java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow JOGL arrow Use of the accumulation buffer to do full-scene antialiasing on a scene
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4092
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Use of the accumulation buffer to do full-scene antialiasing on a scene E-mail
User Rating: / 10
PoorBest 

Use the accumulation buffer to do full-scene antialiasing on a scene with orthographic parallel projection. The example is ported from C examples in the OpenGL Programming Guide (known as the "red book").


Image

-> Copyright and Permission Notice

package glredbook10;

import java.awt.event.*;
import javax.swing.*;

import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.sun.opengl.util.*; 

/**
 * Use the accumulation buffer to do full-scene antialiasing on a scene with
 * orthographic parallel projection.
 
 @author Kiet Le
 */
public class accanti
  extends JFrame
    implements GLEventListener, KeyListener

{
  private GLUT glut;
  private GLCapabilities caps;
  private GLCanvas canvas;
  private static final int ACSIZE = 8;


  public accanti()
  {
    super("accanti");
  
    caps = new GLCapabilities();
    caps.setAccumBlueBits(16);
    caps.setAccumGreenBits(16);
    caps.setAccumRedBits(16);
    System.out.println(caps.toString());

    canvas = new GLCanvas(caps);
    canvas.addGLEventListener(this);
    canvas.addKeyListener(this);

    getContentPane().add(canvas);
  }

  public void run()
  {
    setSize(250250);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    canvas.requestFocusInWindow();
  }

  public static void main(String[] args)
  {
    new accanti().run();
  }

  /*
   * Initialize lighting and other values.
   */
  public void init(GLAutoDrawable drawable)
  {
    GL gl = drawable.getGL();
    glut = new GLUT();
    //
    float mat_ambient[] new float[]
    1.0f1.0f1.0f1.0f };
    float mat_specular[] new float[]
    1.0f1.0f1.0f1.0f };
    float light_position[] new float[]
    0.0f0.0f10.0f1.0f };
    float lm_ambient[] new float[]
    0.2f0.2f0.2f1.0f };

    gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, mat_ambient, 0);
    gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, mat_specular, 0);
    gl.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 50.0f);
    gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_position, 0);
    gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, lm_ambient, 0);

    gl.glEnable(GL.GL_LIGHTING);
    gl.glEnable(GL.GL_LIGHT0);
    gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glShadeModel(GL.GL_FLAT);

    gl.glClearColor(0.0f0.0f0.0f0.0f);
    gl.glClearAccum(0.0f0.0f0.0f0.0f);
  }

  public void display(GLAutoDrawable drawable)
  {
    GL gl = drawable.getGL();

    int viewport[] new int[4];
    int jitter;

    gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);

    gl.glClear(GL.GL_ACCUM_BUFFER_BIT);
    for (jitter = 0; jitter < ACSIZE; jitter++)
    {
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      gl.glPushMatrix();
      /*
       * Note that 4.5 is the distance in world space between left and right and
       * bottom and top. This formula converts fractional pixel movement to
       * world coordinates.
       */
      gl.glTranslatef(j8[jitter].x * 4.5f / viewport[2]//
          j8[jitter].y * 4.5f / viewport[3]0.0f);
      displayObjects(gl);
      gl.glPopMatrix();
      gl.glAccum(GL.GL_ACCUM, 1.0f / ACSIZE);
    }
    gl.glAccum(GL.GL_RETURN, 1.0f);
    gl.glFlush();
  }

  public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h)
  {
    GL gl = drawable.getGL();
    //
    gl.glViewport(00, w, h);
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    if (w <= hgl.glOrtho(-2.252.25, -2.25 * h / w, 2.25 * h / w, -10.0,
        10.0);
    else gl.glOrtho(-2.25 * w / h, 2.25 * w / h, -2.252.25, -10.010.0);
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glLoadIdentity();
  }

  public void displayChanged(GLAutoDrawable drawable, boolean modeChanged,
      boolean deviceChanged)
  {
  }

  public void displayObjects(GL gl)
  {
    float torus_diffuse[] new float[]
    0.7f0.7f0.0f1.0f };
    float cube_diffuse[] new float[]
    0.0f0.7f0.7f1.0f };
    float sphere_diffuse[] new float[]
    0.7f0.0f0.7f1.0f };
    float octa_diffuse[] new float[]
    0.7f0.4f0.4f1.0f };

    gl.glPushMatrix();
    gl.glRotatef(30.0f1.0f0.0f0.0f);

    gl.glPushMatrix();
    gl.glTranslatef(-0.80f0.35f0.0f);
    gl.glRotatef(100.0f1.0f0.0f0.0f);
    gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, torus_diffuse, 0);
    glut.glutSolidTorus(0.2750.851616);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, -0.50f0.0f);
    gl.glRotatef(45.0f0.0f0.0f1.0f);
    gl.glRotatef(45.0f1.0f0.0f0.0f);
    gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, cube_diffuse, 0);
    glut.glutSolidCube(1.5f);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(0.75f0.60f0.0f);
    gl.glRotatef(30.0f1.0f0.0f0.0f);
    gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, sphere_diffuse, 0);
    glut.glutSolidSphere(1.01616);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(0.70f, -0.90f0.25f);
    gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, octa_diffuse, 0);
    glut.glutSolidOctahedron();
    gl.glPopMatrix();

    gl.glPopMatrix();
  }

  public void keyTyped(KeyEvent key)
  {
    // TODO Auto-generated method stub
  }

  public void keyPressed(KeyEvent key)
  {
     switch (key.getKeyCode()) {
      case KeyEvent.VK_ESCAPE:
        System.exit(0);
        break;

      default:
        break;
    }
  }

  public void keyReleased(KeyEvent key)
  {
    // TODO Auto-generated method stub
  }

  /* 2 jitter points */
  jitter_point j2[] =
  new jitter_point(0.246490f0.249999f),
    new jitter_point(-0.246490f, -0.249999f) };

  /* 3 jitter points */
  jitter_point j3[] =
  new jitter_point(-0.373411, -0.250550),//
    new jitter_point(0.2562630.368119)//
    new jitter_point(0.117148, -0.117570) };

  /* 4 jitter points */
  jitter_point j4[] =
  new jitter_point(-0.2081470.353730),
    new jitter_point(0.203849, -0.353780),
    new jitter_point(-0.292626, -0.149945),
    new jitter_point(0.2969240.149994) };

  /* 8 jitter points */
  jitter_point j8[] =
  new jitter_point(-0.3348180.435331),
    new jitter_point(0.286438, -0.393495),
    new jitter_point(0.4594620.141540),
    new jitter_point(-0.414498, -0.192829),
    new jitter_point(-0.1837900.082102),
    new jitter_point(-0.079263, -0.317383),
    new jitter_point(0.1022540.299133)new jitter_point(0.164216, -0.054399) };

  /* 15 jitter points */
  jitter_point j15[] =
  new jitter_point(0.2855610.188437),
    new jitter_point(0.360176, -0.065688),
    new jitter_point(-0.1117510.275019),
    new jitter_point(-0.055918, -0.215197),
    new jitter_point(-0.080231, -0.470965),
    new jitter_point(0.1387210.409168)new jitter_point(0.3841200.458500),
    new jitter_point(-0.4549680.134088),
    new jitter_point(0.179271, -0.331196),
    new jitter_point(-0.307049, -0.364927),
    new jitter_point(0.105354, -0.010099),
    new jitter_point(-0.1541800.021794),
    new jitter_point(-0.370135, -0.116425),
    new jitter_point(0.451636, -0.300013),
    new jitter_point(-0.3706100.387504) };

  /* 24 jitter points */
  jitter_point j24[] =
  new jitter_point(0.0302450.136384),
    new jitter_point(0.018865, -0.348867),
    new jitter_point(-0.350114, -0.472309),
    new jitter_point(0.2221810.149524),
    new jitter_point(-0.393670, -0.266873),
    new jitter_point(0.4045680.230436)new jitter_point(0.0983810.465337),
    new jitter_point(0.4626710.442116),
    new jitter_point(0.400373, -0.212720),
    new jitter_point(-0.4099880.263345),
    new jitter_point(-0.115878, -0.001981),
    new jitter_point(0.348425, -0.009237),
    new jitter_point(-0.4640160.066467),
    new jitter_point(-0.138674, -0.468006),
    new jitter_point(0.144932, -0.022780),
    new jitter_point(-0.2501950.150161),
    new jitter_point(-0.181400, -0.264219),
    new jitter_point(0.196097, -0.234139),
    new jitter_point(-0.311082, -0.078815),
    new jitter_point(0.2683790.366778),
    new jitter_point(-0.0406010.327109),
    new jitter_point(-0.2343920.354659),
    new jitter_point(-0.003102, -0.154402),
    new jitter_point(0.297997, -0.417965) };

  /* 66 jitter points */
  jitter_point j66[] =
  new jitter_point(0.266377, -0.218171),
    new jitter_point(-0.170919, -0.429368),
    new jitter_point(0.047356, -0.387135),
    new jitter_point(-0.4300630.363413),
    new jitter_point(-0.221638, -0.313768),
    new jitter_point(0.124758, -0.197109),
    new jitter_point(-0.4000210.482195),
    new jitter_point(0.2478820.152010),
    new jitter_point(-0.286709, -0.470214),
    new jitter_point(-0.4267900.004977),
    new jitter_point(-0.361249, -0.104549),
    new jitter_point(-0.0406430.123453),
    new jitter_point(-0.1892960.438963),
    new jitter_point(-0.453521, -0.299889),
    new jitter_point(0.408216, -0.457699),
    new jitter_point(0.328973, -0.101914),
    new jitter_point(-0.055540, -0.477952),
    new jitter_point(0.1944210.453510)//
    new jitter_point(0.4040510.224974)//
    new jitter_point(0.3101360.419700),
    new jitter_point(-0.0217430.403898),
    new jitter_point(-0.4662100.248839),
    new jitter_point(0.3413690.081490),
    new jitter_point(0.124156, -0.016859),
    new jitter_point(-0.461321, -0.176661),
    new jitter_point(0.0132100.234401),
    new jitter_point(0.174258, -0.311854),
    new jitter_point(0.2940610.263364),
    new jitter_point(-0.1148360.328189),
    new jitter_point(0.041206, -0.106205),
    new jitter_point(0.0792270.345021),
    new jitter_point(-0.109319, -0.242380),
    new jitter_point(0.425005, -0.332397),
    new jitter_point(0.0091460.015098),
    new jitter_point(-0.339084, -0.355707),
    new jitter_point(-0.224596, -0.189548),
    new jitter_point(0.0834750.117028),
    new jitter_point(0.295962, -0.334699),
    new jitter_point(0.4529980.025397),
    new jitter_point(0.206511, -0.104668),
    new jitter_point(0.447544, -0.096004),
    new jitter_point(-0.108006, -0.002471),
    new jitter_point(-0.3808100.130036),
    new jitter_point(-0.2424400.186934),
    new jitter_point(-0.2003630.070863),
    new jitter_point(-0.344844, -0.230814),
    new jitter_point(0.4086600.345826),
    new jitter_point(-0.2330160.305203),
    new jitter_point(0.158475, -0.430762),
    new jitter_point(0.4869720.139163),
    new jitter_point(-0.3016100.009319),
    new jitter_point(0.282245, -0.458671),
    new jitter_point(0.4820460.443890),
    new jitter_point(-0.1215270.210223),
    new jitter_point(-0.477606, -0.424878),
    new jitter_point(-0.083941, -0.121440),
    new jitter_point(-0.3457730.253779),
    new jitter_point(0.2346460.034549),
    new jitter_point(0.394102, -0.210901),
    new jitter_point(-0.3125710.397656),
    new jitter_point(0.2009060.333293),
    new jitter_point(0.018703, -0.261792),
    new jitter_point(-0.209349, -0.065383),
    new jitter_point(0.0762480.478538),
    new jitter_point(-0.073036, -0.355064),
    new jitter_point(0.1450870.221726) };

  class jitter_point
  {
    private static final int MAX_SAMPLES = 66;
    float x, y;

    public jitter_point(double x, double y)
    {
      this.x = (floatx;
      this.y = (floaty;
    }
  }
}

Source: Kiet Le's The Red Book Examples using JOGL


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.