Problems with JOGL speed

I’m not sure if this is a JOGL issue or something I’m doing wrong –

I basically have a JFrame that has a few JPanels on it. One of the JPanels contains a hardware accelerated GLCanvas. I have a loop running that looks something like this:

while(true){
canvas.display();
Thread.yield();
}

The canvas display() method does nothing – it clears the screen black. When I do nothing, I get around 2000 FPS. However, as soon as I even move the mouse cursor into the JFrame, performance drops drastically. I get continual 2-3 second spikes where there is no response at all, and FPS drops to less than 500 when it is responding. What is happening here?

If I do a Thread.sleep(10) instead, there is no spike when the mouse enters the JFrame and the FPS remains at a steady 90ish (this wont work however – 90 FPS when all I’m doing is clearing the screen).

In both cases, the program freezes up for a a solid 2-6 seconds whenever I try and move the window around, resize it, or exit the program.

Am I doing something wrong, or does JOGL always act like this?

You’re starving the awt thread.

As for the 90 fps… do you really need more than 90 fps?

Ok – I just found out that Yield() does absolutely nothing and that I have to sleep for some time.

However, does an app using JOGL always freeze for 2-5 seconds when you try and move the window?

EDIT: Well, technically I don’t need more than 90 fps, but I’d like the game to run as fast as it can (without hindering other processes, though).

You might want to look at JInput (I haven’t done so myself) or LWJGL for more direct input control.
Both getting as many fps as possible and not starving the awt thread can be a bit tricky and os dependent, ime.

Basically I don’t understand the attitude to make a game “run as fast as possible” since everything above the monitor refresh rate is rendered for nobody to see anyway, but maybe it’s just me :wink:

[quote]Basically I don’t understand the attitude to make a game “run as fast as possible” since everything above the monitor refresh rate is rendered for nobody to see anyway, but maybe it’s just me :wink:
[/quote]
No, it’s not you! We are at least 2 :smiley:

[quote]Basically I don’t understand the attitude to make a game “run as fast as possible” since everything above the monitor refresh rate is rendered for nobody to see anyway, but maybe it’s just me :wink:
[/quote]
The faster you can make it run, the more hardware it will run good on.

The 100 fps theoretical cap of adding a thread.sleep(10) has nothing to do with what hardware you run it on.

Yes i haven’t seen it this way… I prefer to set a limit for the frame rate and then improve code to make CPU usage go down. But it’s the same and harder

Just the habit to have customers that need to lower the CPU usage.

[quote]The 100 fps theoretical cap of adding a thread.sleep(10) has nothing to do with what hardware you run it on.
[/quote]
But it might explain the 25 FPS someone else gets :wink:

Well…

If he’s getting 25 fps, then he’s spending 40 ms per frame, of which 10 ms is sleeping and 30 ms is rendering and game logic (probably).
If you remove the 10 ms sleep, he’d be getting 33 fps.

I just meant a hard coded 10ms sleep is a bad idea in general. If he wants to cap FPS beyond vsync, it’s better to adapt the delay rate at run-time. On a fast machine, it might mean it sleeps for 15 on a slow it might sleep for 5, all to try and get a constant FPS of 60 or so on all machines.

indeed.

Hmm I’m running into another problem…

Every 20-30 seconds, my program hangs for a few seconds (becomes completely unresponsive – no rendering or anything takes place during this time). I have a massive sleep in right now (50 ms), yet the program continues to hang a few times per minute. I’m using swing components along with a GLCanvas. I’m not doing any intensive calculations or rendering – infact, I’m rendering less than 500 polys per frame.

Anyone know what might be causing my program to hang like this?

Maybe you are creating a lot of instances every frame, so the garbage-collector runs every 20-30 second? Just a thought…

It’s not the garbage collector. I’ve set on -verbosegc -XX:+PrintGCDetails and the GC runs in about 0.0008009 secs whenever it needs to, and the pauses do not coincide with the GC running either.

The pauses seem to be the same sort of pause that happens when I try and move the window. It seems to be caused by JOGL… moving the window does not pause without a JOGL canvas, but does pause with one.

Any experience similar problems?