VSync ist die Abkürzung Vertical synchronization. Zu deutsch "Vertikale Synchronisierung" und verhindert Darstellungsfehler im Bildaufbau. Das folgende Code Fragment zeigt wie man unter OpenGL VSync an- bzw. abschalten kann.
Quellen:
1. VSync - Wikipedia: http://de.wikipedia.org/wiki/VSync
2. 60, 70 or 75 fps? See the solution ! (Source code to copy and paste.) - Gamedev.net: http://www.gamedev.net/community/forums/topic.asp?topic_id=425122
//Download wglext.h from http://oss.sgi.com/projects/ogl-sample/sdk.html
#include <gl\wglext.h>
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = NULL;
//from NeHe Lesson 45
bool IsExtensionSupported( char* szTargetExtension )
{
const unsigned char *pszExtensions = NULL;
const unsigned char *pszStart;
unsigned char *pszWhere, *pszTerminator;
// Extension names should not have spaces
pszWhere = (unsigned char *) strchr( szTargetExtension, ' ' );
if( pszWhere || *szTargetExtension == '\0' )
return false;
// Get Extensions String
pszExtensions = glGetString( GL_EXTENSIONS );
// Search The Extensions String For An Exact Copy
pszStart = pszExtensions;
for(;;)
{
pszWhere = (unsigned char *) strstr( (const char *) pszStart, szTargetExtension );
if( !pszWhere )
break;
pszTerminator = pszWhere + strlen( szTargetExtension );
if( pszWhere == pszStart || *( pszWhere - 1 ) == ' ' )
if( *pszTerminator == ' ' || *pszTerminator == '\0' )
return true;
pszStart = pszTerminator;
}
return false;
}
bool InitVSync()
{
if (IsExtensionSupported("WGL_EXT_swap_control"))
{
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)
wglGetProcAddress("wglSwapIntervalEXT");
wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC)
wglGetProcAddress("wglGetSwapIntervalEXT");
return true;
}
return false;// WGL_EXT_swap_control not supported
}
bool SetVSync(bool VSync)
{
if(!wglSwapIntervalEXT) return false;
wglSwapIntervalEXT(VSync);
return true;
}
bool GetVSync(bool* VSync)
{
if(!wglGetSwapIntervalEXT) return false;//VSynce value is not valid...
*VSync = wglGetSwapIntervalEXT();
return true;
}
Kommentare zum Snippet