Click to See Complete Forum and Search --> : Evaluating if an extension is available


alexin
February 22nd, 2008, 06:26 AM
I have the following code to turn vsync on or off:
void Application::setVSync(bool vsync) throw(OcasoException){

typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int);
PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0;

const char* extensions = (char*) glGetString(GL_EXTENSIONS);

if(strstr(extensions, "WGL_EXT_swap_control") == 0 ){
throw OcasoException("Extension not supported.");
}else{
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC) wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT){
wglSwapIntervalEXT(vsync ? 1 : 0);
}
}
}
The code fails in the first 'if' statement. The debugger says 'extensions' is a bad pointer.

What's the problem? Is there a better way to turn vsync on or off?

Mike Harnad
February 22nd, 2008, 08:45 AM
Is 'extensions' null? Try checking the error code (GetLastError ()) after the call to glGetString. Is it GL_INVALID_OPERATION ?

alexin
February 22nd, 2008, 12:37 PM
I don't think extension is null, it doesn't seem at least.

GetLastError() returns 'Cannot create a file when that file already exists'...

Lindley
February 22nd, 2008, 01:06 PM
You're much better off just using GLEW.

glewInit() pulls in the APIENTRYs of all available extensions, and glewIsSupported does the test you want.

alexin
February 22nd, 2008, 07:31 PM
Humm... the program crashes when I use glewInit() and I can't say why.

Anyone has a thought about this, with or without GLEW?

STLDude
February 22nd, 2008, 08:06 PM
Actually, I believe you need to use glGetError() function to get last OpenGL error. It has been a while since I used OpenGL.

alexin
February 23rd, 2008, 09:35 AM
Yes, but the error may not be related to OpenGL and I thought GetLastError() would wrap any OpenGL error.

Wow! I think I found the problem. I'll see into that later and let you know something.

EDIT: Problem resolved, I was calling glewInit() before initializing OpenGL.

Thanks for the help!