3
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ (Question) Isn't this just v-sync? \$\endgroup\$ Commented Dec 21, 2010 at 13:20

3 Answers 3

2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ SDL's swapbuffers won't do anything magical if you set your driver settings never to do vsync. \$\endgroup\$ Commented Jan 14, 2011 at 11:23
2
\$\begingroup\$

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: https://stackoverflow.com/questions/589064/how-to-enable-vertical-sync-in-opengl

\$\endgroup\$
1
\$\begingroup\$

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: https://stackoverflow.com/questions/589064/how-to-enable-vertical-sync-in-opengl

\$\endgroup\$
4
  • \$\begingroup\$ It should not be impossible if the app does little enough? \$\endgroup\$ Commented Dec 21, 2010 at 16:36
  • \$\begingroup\$ 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. \$\endgroup\$
    – Notabene
    Commented Dec 21, 2010 at 16:54
  • \$\begingroup\$ One frame left, one frame right ... i meaned: one frame for left eye, one for right eye \$\endgroup\$
    – Notabene
    Commented Dec 21, 2010 at 19:53
  • \$\begingroup\$ Interesting twist. \$\endgroup\$ Commented Dec 22, 2010 at 0:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .