Enable V-Sync for full-screen games. Vital for Win32 releases

I’m creating a game which I plan to release on iOS, Android, and most importantly, Win32 (Steam).

Would it be possible to have a function to enable V-Sync for fullscreen mode? It’s important to me and not having it is a bit of a deal-breaker. I’m hoping for something like this:

glview->setVSyncEnabled( true );

I know I could probably hack in some OpenGL code and do it myself, but I’ve heard discussion of removing OpenGL from cocos2d-x altogether due to an iOS update, so I’m trying my best to only use official cocos2d functions.

If there’s no other way besides implementing the OpenGL changes myself, I would appreciate guidance on how to do so.

Thanks.

Managed it by inserting the following code into the file CCGLViewImpl-desktop.cpp at line 358 (just before initGlew):

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
// Turn on vertical screen sync under Windows.
// (I.e. it uses the WGL_EXT_swap_control extension)
typedef BOOL(WINAPI *PFNWGLSWAPINTERVALEXTPROC)(int interval);
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
if (wglSwapIntervalEXT)
    wglSwapIntervalEXT(1);
#endif

Could this not be officially added to the library, and enabled in a way similar to my previous suggestion?

2 Likes

Please create pull request