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.