JOGL Double Buffering

Posted by Bar on Stack Overflow See other posts from Stack Overflow or by Bar
Published on 2009-10-08T22:45:25Z Indexed on 2010/04/16 10:13 UTC
Read the original article Hit count: 668

Filed under:
|
|

What is eligible way to implement double buffering in JOGL (Java OpenGL)?

I am trying to do that by the following code:

...    

/** Creating canvas. */
GLCapabilities capabilities = new GLCapabilities();
capabilities.setDoubleBuffered(true);
GLCanvas canvas = new GLCanvas(capabilities);

...

/** Function display(…), which draws a white Rectangle on a black background. */
public void display(GLAutoDrawable drawable) {
    drawable.swapBuffers();

    gl = drawable.getGL();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    gl.glColor3f(1.0f, 1.0f, 1.0f);

    gl.glBegin(GL.GL_POLYGON);
    gl.glVertex2f(-0.5f, -0.5f);
    gl.glVertex2f(-0.5f, 0.5f);
    gl.glVertex2f(0.5f, 0.5f);
    gl.glVertex2f(0.5f, -0.5f);
    gl.glEnd();
}

...

/** Other functions are empty. */

Questions:

— When I'm resizing the window, I usually get flickering. As I see it, I have a mistake in my double buffering implementation.

— I have doubt, where I must place function swapBuffers — before or after (as many sources says) the drawing? As you noticed, I use function swapBuffers (drawable.swapBuffers()) before drawing a rectangle. Otherwise, I'm getting a noise after resize. So what is an appropriate way to do that?

Including or omitting the line capabilities.setDoubleBuffered(true) does not make any effect.

© Stack Overflow or respective owner

Related posts about java

Related posts about jogl