开发者

JOGL Double Buffering

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.


If you use a GLCanvas, autoSwapBuffer mode is set to true by default, you should not have to call swapBuffers() manually. Your flickering has nothing to do with double buffering, rather set sun.awt.noerasebackground to true.


If JOGL is like the C/C++ version:

RMorrisey and the sample code is incorrect in stating the use of glFlush.

The swapBuffers function must go at the end of the drawing.

To confirm this: have the shapes do animation very quickly and watch for tearing. If you get tearing then you are doing a single draw, if you don't then you are using double buffering.


Here's an example of double-buffered animation using JOGL:

http://www.java-tips.org/other-api-tips/jogl/how-to-implement-a-simple-double-buffered-animation-with-mouse-e.html

Try instead of calling swapBuffers(), at the end of display(...) call:

gl.glFlush();

It's been a while since I've done anything with JOGL; hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜