Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In OpenGL, is there a way to ensure I get exactly, no more nor less, 60 (or whatever rate my monitor is set for) frames per second?

Of course given that the new frame can be calculated in less than 1/60 second. I was thinking Windows more than Linux or Mac OSX, even though it is interesting to keep an eye on portability.

share|improve this question
    
(Question) Isn't this just v-sync? –  The Communist Duck Dec 21 '10 at 13:20

3 Answers 3

up vote 2 down vote accepted

I think you need to go platform specific for this, SDL's SDL_GL_SwapBuffers (i think it's called) will wait for retrace before swapping. If you specify your platform, there might be more we can help you with.

HTH.

A quick google turned up this: http://osdl.sourceforge.net/main/documentation/rendering/SDL-openGL.html, search the page for 'retrace' and you'll see it.

share|improve this answer
    
SDL's swapbuffers won't do anything magical if you set your driver settings never to do vsync. –  Jari Komppa Jan 14 '11 at 11:23

Synchronizing with the vertical retrace is not only platform dependent, but vendor-dependent and therfore not covered by the OpenGL-Specification.

Additional information can be found here: http://stackoverflow.com/questions/589064/how-to-enable-vertical-sync-in-opengl

share|improve this answer

What you want is called VSYNC. And for your question:

no more nor less, 60

This is imposible, if you are talking about no less. It is depended on how much your app cuts gpu's performance.

No more is not that easy in OpenGL (compared to directx). Opengl doesnt support vsync in its basics, but the extension for VSYNC exists. Problem is that works only on windows.

Best resource for start studying is stack overflow and this QA: http://stackoverflow.com/questions/589064/how-to-enable-vertical-sync-in-opengl

share|improve this answer
    
It should not be impossible if the app does little enough? –  Prof. Falken Dec 21 '10 at 16:36
    
Of course then it is OK. But you can't say it have to be always ok (if you are thinking mathematicly :-)). Also if you are writing some really frame dependent app be aware of this trouble: I was writing stereoscopic application one frame left, one right (its called page flipping) but before it established to be ok, it took some time. So you cant say the first frame is left or right and user had to perform "switch eye" test on every application startup. –  Notabene Dec 21 '10 at 16:54
    
One frame left, one frame right ... i meaned: one frame for left eye, one for right eye –  Notabene Dec 21 '10 at 19:53
    
Interesting twist. –  Prof. Falken Dec 22 '10 at 0:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.