# 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 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 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 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 on other sites
Quote:
 Original post by reaktorHiI'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 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 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 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 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/f33.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/f33.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 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

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627686
• Total Posts
2978637
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 12
• 14
• 12
• 10
• 12