Skip to main content
GameDev.net gamedev.net
🔒 Locked

[SDL] Disabling vsync

Started by Klarre Dec 30, 2006 at 4:11 PM 2 replies 1.6k views
Original Post
Klarre
Klarre
Hi! Is there a way to disable vertical sync through SDL? Thanks for your help! /Klarre
http://www.klarre.se
Kambiz
Kambiz
I do not know much about SDL but using this code you can disable vertical sync using some OpenGL extensions:
//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 45bool 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;}
Klarre
Klarre
The engine I am writing is cross-platform. So I can't use any platform specific functions like the wgl functions. I have to do everything through SDL.
Thanks for your reply though! :)
http://www.klarre.se
Kambiz
Kambiz
GLFW is an open source, cross platform framework for OpenGL, in the User's Guide I found a function called glfwSwapInterval (on Page 12), maybe you can isolate the source code of this function and put it in you appliation(The license used for GLFW is the zlib/libpng license.).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.