I can't find any information on glCreateContextAttribsARB returning errors if a version is unsuported by the driver. So how do i check if it is? I don't want the program to hard crash because glCreateContextAttribsARB failed and i had no chance to check why it did.
Here's my code, i try to keep it minimalistic, the OpenGLVersion uses the glGetIntegerv to get the major and minor didgits and creates a number out of it. It checks if the version is 'least 3.3, though i've no idea if this actually does anything unless i set up glCreateContextAttribsARB with the wrong numbers.
So when does OpenGL "get a version", so that the glGetIntegerv returns a valid information? Is it something built in or does it return something valid only after i set up the context? How do i check if the OpenGL version i want to use is supported?
void CreateOpenGLContext(HWND hWnd){
//Set the pixel format
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
24,
8,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
hDC = GetDC( hWnd );
GLuint PixelFormat = ChoosePixelFormat( hDC, &pfd );
SetPixelFormat( hDC, PixelFormat, &pfd );
//Create an OpenGL context to get access to the WGL extensions
hRC = wglCreateContext( hDC );
wglMakeCurrent( hDC, hRC );
//Load functions
if(glload::LoadFunctions() == glload::LS_LOAD_FAILED){
MessageBox( NULL, TEXT("Failed to load OpenGL extensions."), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION );
PostQuitMessage(0);
}
//Load WGL extensions
if(glload::LoadWinFunctions(hDC) == glload::LS_LOAD_FAILED){
MessageBox( NULL, TEXT("Failed to load WGL extensions."), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION );
PostQuitMessage(0);
}
//Use WGL extensions to create an OpenGL 3.3 context
const int contextAttributes[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0
};
HGLRC hRC3 = wglCreateContextAttribsARB( hDC, hRC, contextAttributes);
wglMakeCurrent( hDC, hRC3 );
wglDeleteContext( hRC );
hRC = hRC3;
//Check if the system supports OpenGL version 3.3
if(OpenGLVersion() < 33){
MessageBox( NULL, TEXT("Your system doesn't support OpenGL version 3.3"), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION );
PostQuitMessage(0);
}
}
int glVersion[2] = {0, 0}; glGetIntegerv(GL_MAJOR_VERSION, &glVersion[0]); glGetIntegerv(GL_MINOR_VERSION, &glVersion[1]);
will tell you what you actually got (i.e. what is supported) – melak47 May 2 '12 at 17:30