Sign in to follow this  
reaktor

OpenGL Annoying jerkiness on OpenGL

Recommended Posts

Hi I've wrote a fairly basic OpenGL program in C++. It has standard Windows code and also makes use of DirectInput and the performance counter to control the speed of animation. I'm planning to write a 2D platform game. At the moment I have 1 textured polygon (quad) which bounces around the edges of the screen. I'm not happy though cos the sprite movement is just not acceptable at all. Every 3 to 4 seconds it seems to jump a few pixels. The movement of the polygon should be smooth around the screen but it isn't. Surely my 700Mhz celeron is up to the task of moving a single polygon around a screen?? Could it maybe be my firewall software getting in the way? I've got no idea. Steve

Share this post


Link to post
Share on other sites
Could it be your code? Can't tell. - How are you moving it your polygon? What kind of graphics card do you have? Etc...

Specifically I am interested in your performance counter to "control the speed of animation."


Share this post


Link to post
Share on other sites
Hello, reaktor,

I'm not entirely sure what the problem is. But try turning on Vsync manually in your graphics control panel and see if that solves the problem. What is your FPS when running the program? Is the movement time-based or frame-based?
If it is time-based, it could be that some frames are skipped for the quad to reach it's destination in time.

Just some quick thoughts though. Please explain the problem a bit more in-depth if you want a better solution.

Jeroen

Share this post


Link to post
Share on other sites
It's probably some random background task running in Windows. Try closing background applications and services and you should see your FPS come back :-)

Just a quick note - it can sometimes be useful to use a low level tool to diagnose what software exactly is eating up your CPU time. Task manager can help find CPU hogs, but services are slightly trickier. Often disk access is the main culprit for slow speed and a tool like Filemon can be very useful to help diagnose problem software.

Share this post


Link to post
Share on other sites
Quote:
Original post by reaktor
Hi

I've wrote a fairly basic OpenGL program in C++. It has standard Windows code and also makes use of DirectInput and the performance counter to control the speed of animation. I'm planning to write a 2D platform game.

At the moment I have 1 textured polygon (quad) which bounces around the edges of the screen. I'm not happy though cos the sprite movement is just not acceptable at all. Every 3 to 4 seconds it seems to jump a few pixels. The movement of the polygon should be smooth around the screen but it isn't. Surely my 700Mhz celeron is up to the task of moving a single polygon around a screen??

Could it maybe be my firewall software getting in the way? I've got no idea.

Steve


I had the same problem where the animations and entities in the game would jerk a bit sometimes and this would occur randomly. I fought with it for days and weeks eventually it turned out that the effect would go away when I shutdown the antivirus scanner (AVG) and OpenOffice quickstart from the taskbar in Windows. It could very well be your firewall or some other software running in the background.

Hope that helps.

Share this post


Link to post
Share on other sites
Hi

Thanks for the replies. I've just tried outputting my framerate to the screen and its a bit erratic to say the least. I get between 60 to 180 fps. Its constantly changing. I guess this is due to the graphics card not using vsync.

I'm borrowing this computer from a mate and it isn't particularly great. The graphics card is an on-board thingy and doesn't seem to have any vsync settings in the control panel so I can't lock the framerate. Plus the mouse is knackered so I am forced to use the keyboard for navigating around windows. Not much fun!

As someone mentioned, the jerking does seem to occur during hard drive access so maybe it is one of the programs running in the background. Its gona be pretty annoying though if I have to turn off my virus checker/firewall everytime I want to test my application.

Strange that other programs (such as emulators) seem to run fine with no jerking graphics.

I remember reading in the OpenGL superbible that you can get around Windows background tasks by using threading in your program. Hs anyone tried this? It looked a little complex so I ignored it. Maybe I should take another look.

Cheers,
Steve

Share this post


Link to post
Share on other sites
Ok, I've had a bit of a play and...

...It was the firewall. Seemed to be knocking a few fps off the framerate every few seconds which causes the jerky motion. How bloody annoying! I tried turning it off and I got a nice solid 191 frames per second. The animation is now nice and smooth and I'm quite happy with it.

Interesting that if I moved the polygon off the screen it added an extra 9 frames per second to my framerate! So when nothing was on the screen I got a result of 200 fps. I didn't think 1 stinking polygon would use up that many frames! lol.

Anyway thanks for your help. Looks like I'll just have to disable the firewall and unplug myself from the modem every time I want to test my program. Sheesh. :(

Cheers,
Steve

Share this post


Link to post
Share on other sites
Quote:

Interesting that if I moved the polygon off the screen it added an extra 9 frames per second to my framerate! So when nothing was on the screen I got a result of 200 fps. I didn't think 1 stinking polygon would use up that many frames! lol.


Ah the common misconception that 9 FPS for a single polygon is alot of performance. I had the same misconception when i started out, you see 9 frames less with a framerate of 200FPS scene is probably less costly than 2 frames less in a 30FPS scene.

There is alot of other work done to render each frame such as
Clearing color/depth buffers
Submission of geometry
Entire Game loop/render loop

With 200FPS, your overhead per frame is very low, almost 0 in your case which is why a single polygon takes away 9 frames. In a proper game running at 30FPS, it will take much more additional detail/code in your scene to take away even a single frame of performance. Which is why many people will tell you that framerate is not a good gauge of performance.

Share this post


Link to post
Share on other sites
To add some numbers to GamerSg's post...
200 fps = 0.005 s/f (seconds per frame) = 5 ms/f (milliseconds per frame)
191 fps ~ 0.00524 s/f = 5.24 ms/f
So rendering your scene with that extra quad takes about 24 hundredths of a millisecond longer than rendering without it.
30 fps ~ 0.033 s/f = 33 ms/f
33.24 ms/f = 0.03324 s/f ~ 30.08 fps
With my rounding through those calculations we actually lose enough accuracy to show an increase in FPS. Without rounding we get...
30 fps = 0.0333... s/f = 33.333... ms/f
33.5689... ms/f = 0.0335689... s/f = 29.7894... fps
where ... doesn't necessarily mean those displayed digits repeat, just that there are more digits than I feel like pasting. [grin]

So if we're rendering at 30fps and we lose the same amount of time that we lost previously we would now be rendering at about 29.7894 fps. If we were rendering at 60 fps, the same difference in rendering speed corresponds to a new fps of about 59.16.

Share this post


Link to post
Share on other sites
Hey interesting stuff.

The program does practically nothing apart from checking direct input every frame, updating the performance counter and rendering the text and sprite. Next I'm gonna be adding physics and collision detection so I expect the framerate to drop fairly dramatically. Hopefully I can keep it around the 60fps mark. That is a nice frame rate to aim for.

Steve

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this