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

60, 70 or 75 fps? See the solution ! (Source code to copy and paste.)

Started by Kambiz Nov 22, 2006 at 4:13 AM 5 replies 5.2k views
Original Post
Kambiz
Kambiz
I have seen many threads here people asking why they get a maximum frame rate of 60, 70 or 75fps . Most of them get soon the correct answer: they have to disable the vertical synchronization but this not easy for beginners using opengl so I decided to post the necessary code here:

//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;
}



Links: wglext.h WGL_EXT_swap_control [Edited by - Kambiz on November 22, 2006 6:37:12 AM]
mldaalder
mldaalder
You forgot to mention that this is Windows specific.
bakery2k1
bakery2k1
The test
if(!wglGetProcAddress)
in GetVSync should be
if(!wglGetSwapIntervalEXT)
Ro_Akira
Ro_Akira
One should also mention that the driver has the final say, so if V-Sync is specified "Always on" or "Always off" in the driver settings, then the driver will probably ignore any requests by applications.
Kambiz
Kambiz
Quote:
Original post by bakery2k1
The test
if(!wglGetProcAddress)
in GetVSync should be
if(!wglGetSwapIntervalEXT)


Thank you, I fixed it.
izua
izua
but what happens if i limit my FPS software to 150, (vsync was 75)?

the monitor won't go into a vsync of 150 (drawing 150 frames per second) because he won't be able to do it due the way his electronics are built. what will happen with half of the frames?
rudeness
rudeness
Did I read somewhere that this is possible using SDL on all platforms? Or do I just wish I did? I tried to re-google, but I couldn't find it.

(^-^)/

Topic Locked

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

Sign in to reply to this topic.