Since I got trouble using the lwjgl Keyboard class, I'm trying to implement my own Keylistener. I've been succesful at creating the opengl context inside a glcanvas/jframe, but I really can't make the keylistener work. Here's the code:
mport javax.swing.JFrame;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ContextAttribs;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import events.Keyboard;
public static void createDisplay() {
GLProfile glprofile = GLProfile.getDefault();
GLCapabilities glcap = new GLCapabilities(glprofile);
GLCanvas canvas = new GLCanvas (glcap);
JFrame frame = new JFrame("best frame ever");
canvas.addKeyListener(new Keyboard());
canvas.setVisible(true);
canvas.setSize(WIDTH,HEIGHT);
frame.getContentPane().add(canvas);
frame.pack();
frame.setVisible(true);
ContextAttribs attribs = new ContextAttribs(3,2);
try {
Display.setDisplayMode(new DisplayMode(WIDTH,HEIGHT));
Display.create(new PixelFormat(), attribs);
Display.setParent(canvas);
} catch (LWJGLException e) {
e.printStackTrace();
System.err.println("something went wrong creating the display");
}
GL11.glViewport(0, 0, WIDTH, HEIGHT);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
Keyboard class:
package events;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Keyboard implements KeyListener{
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
public void keyPressed(KeyEvent e) {
System.out.println("pressed something");
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
}