Hello,
I wanted to create a simple window with the LWJGL and a key input request which closes the window.
I also wanted to create the classes in seperated packages, so it's more organized.
The window displays but if I press that certain key nothing happens.
It would be great if you could help me.
Thanks!
Here is the Main class:
package bb.main;
import bb.input.Input;
import bb.main.render.SimpleRenderer;
public class Main {
public static void main(String[] args){
SimpleRenderer createWindow = new SimpleRenderer();
Input input = new Input();
createWindow.Render();
input.checkKey();
}
}
Here is the SimpleRenderer class:
package bb.main.render;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class SimpleRenderer {
public void Render(){
try{
Display.setDisplayMode(new DisplayMode(1280, 720));
Display.setTitle("MISSING TITLE!");
Display.create();
} catch (LWJGLException LWex){
LWex.printStackTrace();
System.exit(0);
}
while(!Display.isCloseRequested()){
Display.update();
}
Display.destroy();
}
}
And here is the Input class:
package bb.input;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
public class Input {
public void checkKey(){
while(Keyboard.next()){
if(Keyboard.getEventKeyState()){
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){
Display.destroy();
System.exit(0);
}
}
}
Display.destroy();
}
}
Two words: Game Loop.
Before you do anything else, read the LWJGL basics on the wiki: http://lwjgl.org/wiki/index.php?title=LWJGL_Basics_1_(The_Display) (http://lwjgl.org/wiki/index.php?title=LWJGL_Basics_1_(The_Display)) there is the first one. Everything you ever do in LWJGL should follow that basic pattern.
I understand that you have probably just come from learning Swing and things are a bit new but all the answers you need to make your idea work are on that one page I have linked. Study it and only if you still cannot make it work come back here.