JOGL double buffering

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

I am trying to do this with 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 resize a window, I usually get flickering. As I can see, I have an error in the implementation of double buffering.

- I have doubts where I should place the swapBuffers function - before or after (as many sources say) a drawing? As you noticed, before drawing a rectangle I use the swapBuffers ( drawable.swapBuffers()) function . Otherwise, I get noise after resizing. So what is the appropriate way to do this?

Including or dropping a line capabilities.setDoubleBuffered(true)has no effect.

+3
3

JOGL C/++:

RMorrisey, glFlush.

swapBuffers .

: . , , , .

+3

GLCanvas, autoSwapBuffer true, swapBuffers() . , sun.awt.noerasebackground true.

+6

Source: https://habr.com/ru/post/1719673/


All Articles