What is a suitable way to implement double buffering in JOGL (Java OpenGL)?
I am trying to do this with the following code:
...
GLCapabilities capabilities = new GLCapabilities();
capabilities.setDoubleBuffered(true);
GLCanvas canvas = new GLCanvas(capabilities);
...
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();
}
...
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.