views:

46

answers:

1

In JOGL, there is the addGLEventListener, I add a listener to it. When the display() "callback on gl" is called, the screen is printed in black, just after four frames the display() prints something.

How to make display() print something on the first callback display()?

+1  A: 

If you application implements an interface GLEventListener, there is always a next sequence:
—init();
—reshape();
—display().

In my opinion, you have a wrong drawing sequence in the function display().

Try do it in this way:

public void display(GLAutoDrawable drawable) {
    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();

    drawable.swapBuffers(); // — it's for double buffering
}
Bar