Basaa
Basaa

Reputation: 1685

Poor performance on my first LWJGL application

I'm experimenting with LWJGL at the moment. I created a very simple .obj loader, render it to my screen, and I created a fps-like camera. It can't get much simpeler, but I only get 40 FPS, and it's using a hell of a lot of video memory, and my GPU fan is blowing like hell. What did I do wrong?

Here is my code:

FPSController.java (main class): http://pastebin.com/kjWrJs0p

OBJLoader.java: http://pastebin.com/cGmLU0Fz

Model.java: http://pastebin.com/gMX8SXXc

Face.java: http://pastebin.com/5P813v9V

First question: is my FPS counter actually a proper counter?
Second question: why is this tiny program asking SO much of my GPU?
Third question: what is the best model type to use with textures, lighting, shaders etc?

Upvotes: 0

Views: 803

Answers (1)

Martijn Courteaux
Martijn Courteaux

Reputation: 68847

First question:

I really don't understand what your FPS code is doing, so it might be wrong. The basic idea is this:

  • Start timer, in nanos (1)
  • Update and render your game
  • Stop the timer, in nanos (2)
  • Subtract: (2) - (1), this is the nano time it took for your machine to update and render (3)
  • Divide: 1e9 / (3). This is your framerate

In Java:

long start = System.nanoTime();
updateAndRenderTheGame();
long stop = System.nanoTime();
long time = stop - start;
float framerate = 1e9f / time; // 1e9f is equivalent to 1000000000.0f

Second question:

The reason why your fan is blowing like hell, is probably because your FPS code did not work and you think you only got 40 FPS, but you actually get a lot higher framerate. Let's say 200 FPS. To prevent this from happening you should limit the framerate, by sleeping between two frames, using Thread.sleep(milliseconds);

You should be using Vertex Buffer Objects (VBO's), they are much faster. The method you are using right now is deprecated and is very expensive for the GPU, but is easier to use. VBO's are really worth using, they require some more work, but the performance gets a lot better. Some simple Googling will do to find some good references and examples.

Third question:

I'm not a professional at 3D Graphics, but I played around with OBJ files. I created them using Blender. Just make sure that when you export with blender, you check all the data you want to export, in the panel at the left side of the window. (like: Position, Normals, Faces, UV, etc...)

Upvotes: 1

Related Questions