Can somebody help me with this? It is probabely not a JOGL-issue.
I have the following program
Doublebuf.java
import java.awt.event.*;
import javax.swing.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;
public class Doublebuf{
public static void main(String args[]){
JFrame frame = new JFrame("Hello");
GLJPanel panel = new GLJPanel();
panel.addGLEventListener(new DoublebufRenderer());
final Animator animator = new Animator(panel);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
animator.stop();
System.exit(0);
}
});
frame.add(panel);
frame.setVisible(true);
frame.setBounds(100, 100, 250+frame.getInsets().left+frame.getInsets().right, 250+frame.getInsets().top+frame.getInsets().bottom);
animator.start();
}
}
DoublebufRenderer.java
import java.awt.event.*;
import javax.media.opengl.*;
public class DoublebufRenderer implements GLEventListener{
private GL gl;
static private boolean spinning=false;
static private float spin=0.0f;
public void init(GLAutoDrawable drawable){
this.gl=drawable.getGL();
drawable.setGL(new DebugGL(drawable.getGL()));
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
drawable.addMouseListener(new MouseHandler());
drawable.addKeyListener(new KeyHandler());
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height){
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(50.0, -50.0, 50.0, -50.0, -1.0, 1.0);
}
public void display(GLAutoDrawable drawable){
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glPushMatrix();
gl.glRotatef(spin, 0, 0, 1);
gl.glRectf(-25.0f, -25.0f, 25.0f, 25.0f);
gl.glPopMatrix();
gl.glFlush();
if(spinning==true){
spinDisplay();
}
}
public void displayChanged(GLAutoDrawable drawable, boolean moseChanged, boolean deviceChanged){
}
private void spinDisplay(){
spin=spin+2.0f;
if(spin>360.0f) spin=spin-360.0f;
}
class MouseHandler extends MouseAdapter{
public void mouseClicked(MouseEvent e){
if(e.isMetaDown()){
spinning=false;
}
else{
spinning=true;
}
}
}
class KeyHandler extends KeyAdapter{
public void keyPressed(KeyEvent e){
System.out.println("Test");
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
System.exit(0);
}
}
}
When I compile, everything seems to be normal, but when I run the program, the key events don’t work (I don’t get a “test” printed out) while the mouse reacts as expected.