Hello Guest

antialiasing using FSAA or multisampling

  • 9 Replies
  • 10264 Views
antialiasing using FSAA or multisampling
« on: September 28, 2006, 12:51:55 »
Hi,

I would like to do a simple 4X antialiasing with the easy example of the applet. but I can get it to work antialiased.
Can you provide me the good sample of code to make it work antialiased ?

Code: [Select]

package org.lwjgl.test.applet;
 
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Canvas;
 
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.applet.LWJGLInstaller;
 
public class AppletTestComplete extends Applet {
 
  public void init() {
   
    /* Install applet binaries */
    try {
      LWJGLInstaller.tempInstall();
    } catch (Exception le) {
      le.printStackTrace();
    }
   
    setLayout(new BorderLayout());
    try {
      Canvas canvas = new AppletCanvas();
      canvas.setSize(getWidth(), getHeight());
      add(canvas);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 
  /*
   * @see org.lwjgl.opengl.AWTGLCanvas
   */
  public class AppletCanvas extends AWTGLCanvas {
   
    float angle = 0;
   
    /*
     * @see org.lwjgl.opengl.AWTGLCanvas#AWTGLCanvas()
     */
    public AppletCanvas() throws LWJGLException {
      // Launch a thread to repaint the canvas 60 fps
      Thread t = new Thread() {
        public void run() {
          while (true) {
            if (isVisible()) {
              repaint();
            }
            Display.sync(60);
          }
        }
      };
      t.setDaemon(true);
      t.start();      
    }
   
    /*
     * @see org.lwjgl.opengl.AWTGLCanvas#paintGL()
     */
    public void paintGL() {
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
      GL11.glMatrixMode(GL11.GL_PROJECTION_MATRIX);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, 640, 0, 480, 1, -1);
      GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX);
 
      GL11.glPushMatrix();
      GL11.glTranslatef(320, 240, 0.0f);
      GL11.glRotatef(angle, 0, 0, 1.0f);
      GL11.glBegin(GL11.GL_QUADS);
      GL11.glVertex2i(-50, -50);
      GL11.glVertex2i(50, -50);
      GL11.glVertex2i(50, 50);
      GL11.glVertex2i(-50, 50);
      GL11.glEnd();
      GL11.glPopMatrix();
 
      angle += 1;
 
      try {
        swapBuffers();
      } catch (Exception e) {
      }
    }  
  }
}
 


thank you for your help

*

Offline Matzon

  • *****
  • 2242
antialiasing using FSAA or multisampling
« Reply #1 on: September 28, 2006, 14:15:38 »
You should instantiate the applet with the constructor that allows a PixelFormat arg. Then set samples to 4 in the PixelFormat constructor

antialiasing using FSAA or multisampling
« Reply #2 on: September 28, 2006, 14:52:11 »
thank you but could you give me the sample of code to achieve that because I do not see how to do it.
take for example the code over and tell me what to change

antialiasing using FSAA or multisampling
« Reply #3 on: September 28, 2006, 16:20:24 »
You can use the AWTGLCanvas Constructor that accepts a pixelformat.
Quote
AWTGLCanvas

public AWTGLCanvas(PixelFormat pixel_format)
            throws LWJGLException

    Create an AWTGLCanvas with the requested PixelFormat on the default GraphicsDevice.

    Parameters:
        pixelFormat - The desired pixel format. May not be null
        device - the device to create the canvas on.
    Throws:
        LWJGLException


Code: [Select]
Canvas canvas = new AppletCanvas(new PixelFormat(8,0,0,4));

Its like the default PixelFormat Constructor, except that samples is set to 4.

You have to add the Constructor to your applatcanvas class and call its parent.

antialiasing using FSAA or multisampling
« Reply #4 on: September 28, 2006, 16:55:27 »
Sorry evil-devil but this sample code does not work.
I have no antialiased but standard jagged square.
if you have a working sample code please post it here or send it to me.
thanks

*

Offline Matzon

  • *****
  • 2242
antialiasing using FSAA or multisampling
« Reply #5 on: September 28, 2006, 19:49:58 »
check your drivers - works as expected with nvidia
specifically, check your forced AA and AF settings in the control panel

antialiasing using FSAA or multisampling
« Reply #6 on: September 28, 2006, 20:26:17 »
AA works fine when forced.
if you know how to do matzon please post a full code sample doing AA this will help me a lot.
thanks

*

Offline Matzon

  • *****
  • 2242
antialiasing using FSAA or multisampling
« Reply #7 on: September 28, 2006, 22:33:25 »
using your code, I just added a call to the constructor accepting a pixelformat:
Code: [Select]
package org.lwjgl.test.applet;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;

/*
 * @see org.lwjgl.opengl.AWTGLCanvas
 */
public class AppletCanvas extends AWTGLCanvas {

float angle = 0;

/*
* @see org.lwjgl.opengl.AWTGLCanvas#AWTGLCanvas()
*/
public AppletCanvas() throws LWJGLException {
super(new PixelFormat(8, 0, 0, 4));
// Launch a thread to repaint the canvas 60 fps
Thread t = new Thread() {

public void run() {
while (true) {
if (isVisible()) {
repaint();
}
Display.sync(60);
}
}
};
t.setDaemon(true);
t.start();
}

/*
* @see org.lwjgl.opengl.AWTGLCanvas#paintGL()
*/
public void paintGL() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glMatrixMode(GL11.GL_PROJECTION_MATRIX);
GL11.glLoadIdentity();
GL11.glOrtho(0, 640, 0, 480, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX);

GL11.glPushMatrix();
GL11.glTranslatef(320, 240, 0.0f);
GL11.glRotatef(angle, 0, 0, 1.0f);
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2i(-50, -50);
GL11.glVertex2i(50, -50);
GL11.glVertex2i(50, 50);
GL11.glVertex2i(-50, 50);
GL11.glEnd();
GL11.glPopMatrix();

angle += 1;

try {
swapBuffers();
} catch (Exception e) {
}
}
}

antialiasing using FSAA or multisampling
« Reply #8 on: September 28, 2006, 23:37:26 »
Just compiled you sample but it does not work....

console report:

java.lang.ClassCastException

   at sun.applet.AppletPanel.createApplet(Unknown Source)

   at sun.plugin.AppletViewer.createApplet(Unknown Source)

   at sun.applet.AppletPanel.runLoader(Unknown Source)

   at sun.applet.AppletPanel.run(Unknown Source)

   at java.lang.Thread.run(Unknown Source)



please help me this is very important

antialiasing using FSAA or multisampling
« Reply #9 on: September 29, 2006, 16:19:22 »
thank you evill devil it works