Hey, I was trying to split up the game loop into an update loop and render loop. I finished but for some reason the application stops responding and can’t figure out why. Wondering if anyone might have an idea as to why and how to fix it. I put all the code and put it into pastebin http://pastebin.java-gaming.org/f6427305b13
-Thanks
Zerali
What was the idea behind doing this every frame???
try {
Display.releaseContext();
} catch (LWJGLException e) {
e.printStackTrace();
}
Game game = new Game();
game.play();
Why are you using threads?! Why would you create them every frame?! Why would you use a separate thread for updating and rendering?
Why do you have a game loop within your game loop?!?!!?! Why are you repeating all that code!?
Your code baffles me…
I think you’ll have a hard time learning OpenGL and LWJGL if you have no idea how to program in Java.
Well the idea was to have a menu and then create the game object which would then in turn start the two threads once the person has chosen to play the game. Then the code should wait until the two threads complete and join back in with the main thread.
public void play () {
render.start();
update.start();
try {
render.join();
update.join();
}
catch(InterruptedException e) { }
}
So I was releasing the opengl context from the main thread and then making it current to the render loop thread.
public void run(){
try {
Display.makeCurrent();
} catch (LWJGLException e) {
e.printStackTrace();
}
lastFPS = getTime(); // call before loop to initialise fps timer
startTime = lastFPS;
while (!Display.isCloseRequested()) {
int delta = getDelta();
System.out.println("Render Loop");
// Clear The Screen Buffer
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.5f, 0.5f, 0.5f);
glRectf(0, 0, windowWidth, windowHeight);
Display.update();
Display.sync(60); // cap fps to 60fps
//updateFPS();
}
}
Display.makeCurrent and releaseContext hasn’t got anything to do with threads. It’s more useful if you have PBuffers or multiple GL contexts.
You shouldn’t be using threads for this… it sounds like you don’t really understand what they do. Generally rendering and updating should all be done in the same (GL) thread.
I’d suggest taking a look at the LWJGL wiki if you are still lost, or a higher level library like Slick2D or LibGDX to ease you into Java programming.