I’m using the ninja cave lwjgl 2 tutorials for this and I’m very new to Java and also to understanding game mechanics.
I used this example from ninja cave
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class DisplayExample {
public void start() {
try {
Display.setDisplayMode(new DisplayMode(800,600));
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
// init OpenGL here
while (!Display.isCloseRequested()) {
// render OpenGL here
Display.update();
}
Display.destroy();
}
public static void main(String[] argv) {
DisplayExample displayExample = new DisplayExample();
displayExample.start();
}
}
The example is very easy to understand and I got it running without a problem. The big problem started when running the application. The first thing that happened is that my cpu fan went from zero to very high almost immediately. This was my first clue, that cpu utilization was up. So I figured it must be the game loop. You can understand how this is distressfull since there is nothing in the game loop yet. So I added the following into the game loop.
try
{
Thread.sleep(50);
}
catch (Exception e)
{
e.printStackTrace();
}
This immediately solved the problem. Excellent, but is it correct coding. In other words. Java has a lot of libraries. Such as lwjgl 2 which is what I’m using here. Then there is the standard api and threading practices and etc. Since I know very little about this, I would like to know if someone can tell me if I’m doing something that does not correctly correspond to lwjgl. Is this the right way or is there another better way to stabilize the initial game loop before I start adding drawing and updates to it?