FPS problems in LWJGL

Hello,

Whole eclipse project.
[spoiler]http://www.mediafire.com/?vp0ybzwfutqd4o5[/spoiler]

So to the point.

I have a LWJGL game. It renders simple tiles. I’m using VBO along with textures. My game loop calculates when to render and update the game. FPS should be 60. It says 60. After random periods of time my game screen seems to start to laggg like hell. Seems like 10 fps or something. But my game loop still says 60 fps and updates. So I guess this is openGL or LWJGL problem.

A little bit more about my VBO:
I have certain sized vertices(which make certain size squares). I’m guessing this might be caused due to use of translatef.

Just in short again.
Game runs normally. At random times FPS drop very low, but my program executes like usually. FPS fixes after some times. Then starts to lag again. You get the point.

GPU or CPU drops into power saving mode and lowers its clock rates? Scratch that if your FPS is fine. >_>

I don’t think you understood me. This is just some lame ass game. Shouldn’t cause any problems for hardware even in power saving modes. It runs at 1000fps if I don’t cap it. But doesn’t seem that way when the FPS drop.

No, I don’t think you understood. I have never had a problem with FPS drops, I would take a look at your code and make sure something isn’t messing with your main loops. We really can’t help without some sort of source code. I, as of this moment, have no clue what it could possibly be.

[quote]First things first: Can’t really post source because it’s pretty big and you wouldn’t bother trying to understand it.
[/quote]
And how do you know this? I would be glad to look through the code because I could actually help instead of spending the next hour asking you how your game works. Don’t assume anything.

FPS drop = an actual drop in FPS.
Stuttering = high FPS but it’s still not smooth.

I’ve seen so many ways my (attempts at) games stuttered and bogged down over the years… the most critical was using integers to represent speed and positions where I now use floats. The second most critical was to let the loop timing (“when to draw the next frame”) go out of sync due to not correcting for overshoots and such.

Ok I now know where the problem is. I’m doing something wrong with VBO. I switched to intermediate mode for rendering (glVertex2i, you know the simpliest one) and I seem to be getting twice the FPS. This means I’m doing something very wrong with VBO. If anybody has the time and knowledge you could guide me to the right direction :slight_smile:

Are you rebuilding vbos each frame?

Hard to help without seeing code.

Whole project is available for download. It’s an eclipse project.

Hm… seems I was wrong. The low fps problem is still there even with intermediate render mode.

I played it for a few minutes and no problem so far… FPS is stable and it looks smooth.
Problem is specific to your hardware, it seems.

Hm… That’s heart breaking because I have been looking into this problem for a while now…

I think I found the solution. As I was speculating, the problem was with not clearing something from opengl. I found a forum thread somewhere suggesting glFlush(). I implemented it and now I have no FPS drops.
Told ya I wasn’t clearing something :stuck_out_tongue:

That sounds a driver problem. glFlush() reduces parallelism between the GPU and CPU since the CPU waits for the GPU. Also, are you using a variable delta?

If you’re asking whether my game renders and updates only at some point of the second than yes. Most of the time game loop runs without doing anything.
As for my problem, it seems to come back sometimes for no reason. I just don’t understand why would it persist. I tried it on other computer and it had same fps drop problem.

In Main, change all your time variables to longs instead of doubles.

Also, your game loop has a lot of boilerplate code.


			if(nowTime - oldTime > idleTime) {
				shouldUpdate = true;
				oldTime = nowTime;
			}
			
			if (shouldUpdate) {
				tick();
				ticks+=1;
				shouldRender = true;
			}

			
			if(shouldRender){
				render();
				frames+=1;
			}

is exactly the same as just


if(nowTime - oldTime > idleTime) {
    oldTime = nowTime;
    tick();
    render();
    frames++; //ticks is always equal to frames, so remove one of them.
}

You’re also using a busy loop which is a bit bad. You should probably ditch the whole time-related code and throw in a Display.sync(60) instead.

Yea I know the thing about “boiler plate” as you called it. I just sometimes switch between 60 and unlimited fps.

I changed doubles to longs. ATM I don’t encounter ant fps drop. I thought problem might be there but I didn’t actually take a swet to try it.