Login  Register

JOGL display update problem

Posted by polirol on Dec 29, 2012; 11:02am
URL: https://forum.jogamp.org/JOGL-display-update-problem-tp4027643.html

Hi everybody,

I have this problem that is actually driving me crazy: looks like the display function does not update if the changes in the scene are triggered by a key pressed/relased/typed event.

I have something like that:

[imports]

public class TestClass extends GLCanvas implements GLEventListener, KeyListener
{

private float t;
[...]

 public TestClass()
 {
    some init variables;
    addKeyListener(this);
 }

[...]

public void display(GLAutoDrawable d )
{
      GL2 gl = d.getGL().getGL2();
      gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      gl.glMatrixMode(GL_MODELVIEW);
      gl.glLoadIdentity();  

      gl.glPushMatrix();
      gl.glTranslatef(0.0f, 0.0f, -3.0f);
      glut.glutSolidTeapot(0.5f *  Math.sin(t));
      gl.glPopMatrix();


     gl.glFlush();
}

 public void keyPressed(KeyEvent ke)
  {
            t+=0.05f;
            System.out.println("Key pressed : " + ke.getKeyChar());
        }

[...]

}

Well, it doesn't work even if the keyevent is correctly captured (the println output is displayed in the console), but the teapot does not changes its dimension according on how much I press some keys. Forcing a display() method call in keyPressed does not improve the situation.

Moreover, if I put the "t+=0.05f;" statement in the display(GLAutodrawable d) method, the teapot changes its size every frame update; so the question is why the key events are captured but ignored when redrawing the scene every frame update.