Frame limiting

How would I go about frame limiting, I’m basing my code off the time based movement tutorial on gametutorials.com. Now I have moved to a different computer and my program is rendering way too fast (1000 fps) And I need to limit it so I don’t get tearing of the image. I have no idae how to go about doing this, any help would be appreacated.

http://www.angelcode.com/dev/timefps/timefps.asp

I don’t see what this has to do with OpenGL, btw.

Turn on vsync or change the code that does the rendering, don’t know what it look’s like but you might want to modify it there.

It also does depend on your OS, many windows application just put a stupid loop that calls PeekMessage() and if there is none it goes wild rendering zillions frames per second and hogging 102% cpu time or so.

You could use a high resolution timer and set a maximum framerate to limit the rendering.

But if the only problem is image tearing you should be fine if you just turn on vsync.

Mikael

Okay thanks, but how would I go about turing on vsync, I don’t have any books with me fight now, and the code is in openGL thats what it has to do with it.

If you code on windows, see : http://oss.sgi.com/projects/ogl-sample/registry/EXT/wgl_swap_control.txt

use :
wglSwapIntervalEXT(1); // vsync ON

or :
wglSwapIntervalEXT(1); // vsync OFF

Beware, these settings can be overriden by the driver (on NVidia, and probably on ATI too). Tweak ‘vertical sync’ on the Display Control Panel.

Sorry for the misprint :
wglSwapIntervalEXT(0); // vsync OFF

Thanks but it seems to be giving me erorr 0x0005 or something like that I don;t thaink that has enough zeros, is that an access violation error?

Just get the system time and put an if statement:

if (CheckTheTimeHere())
{
… render the scene
}
this will work fine and will give you more cpu time for other applications.
Can’t remember exactly but the name of the function you need was GetSystemCount() or wasn’t :eek:

Do you have an active rendering context when you call wglSwapIntervalEXT ?

Um, just wondering, i’ve seen alot about wglSwapIntervalEXT, but how am i able to get it to work in my program? using visal basic 6 at the moment, and it doesn’t have the procedure and keeps asking for one, can’t figure out where to get it…

either that, or could someone help me with a way in visual basic 6 to limit the frames?

Having never seen Visual Basic code, I’m not sure how you’d get at the extensions, however I’m sure there’s a way to get the system time in milliseconds, in which case busy-waiting on that would work, as TheHighKingBG suggests.

geh! i seriously just can’t grasp this damn timer concept, not at all >.< so frustrated at the moment beucase of that.

i know this is asking abit, but could someone either put it in real lamens terms about how to do it, or put some code up for it showing an example? :frowning: i just don’t get it!