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

        0, 0, 0, 0, 0, 0,
        0, 0, 0, 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 );

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

    //Use WGL extensions to create an OpenGL 3.3 context

    const int contextAttributes[] =

    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 );
  • \$\begingroup\$ You should use GLEE \$\endgroup\$
    – bobobobo
    May 2, 2012 at 17:22
  • \$\begingroup\$ how does that help me, i know how to load extensions \$\endgroup\$
    – dreta
    May 2, 2012 at 17:28
  • \$\begingroup\$ I could be wrong, but you specify the version you'd like (3.3), create the context, and afterwards (if successful) 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) \$\endgroup\$
    – user13213
    May 2, 2012 at 17:30
  • \$\begingroup\$ yea i'm doing that, i just don't know if this is going to yield the minimum version supported, f.e. 2.1 if the version i specify in the wgl function isn't availible, i want to know when the number is set and if wglCreateContextARB is going to crash if the version isn't supported or something and what kind of version do i get when i first set up the context without the wgl extensions that are required for opengl 3.x and up \$\endgroup\$
    – dreta
    May 2, 2012 at 17:48
  • 1
    \$\begingroup\$ @bobobobo: GLEE is dead. Hasn't been updated in years. \$\endgroup\$ May 2, 2012 at 17:56

2 Answers 2


I'd like to know if the way i'm checking if the OpenGL version of choice (3.3) is availible.

Allow me to state this more clearly:

The only way to know if your OpenGL implementation supports a particular version is to attempt to create a context with that version and see if you get a valid context as a result. wglCreateContextAttribsARB will either return the version you requested (or a backwards-compatible higher version), or it will fail. And failure is the only way to know what is and is not supported.

I can't find any information on glCreateContextAttribsARB returning errors if a version is unsuported by the driver.


On failure wglCreateContextAttribsARB returns NULL. Extended error information can be obtained with GetLastError. Conditions that cause failure include:


If the pixel format associated with does not support OpenGL contexts providing the requested API major and minor version, forward-compatible flag, and/or debug context flag, then ERROR_INVALID_PIXEL_FORMAT is generated.

So just check to see if you got an actual context. If you didn't, then it failed.

But really, there's not much point to having a check/fail/retry cycle. You wrote your code expecting some minimum version of OpenGL. That version is what you should ask for. If you happen to get a version higher than this version, great. But no matter what, you will get a version of OpenGL that is backwards compatible with what you asked for.

  • \$\begingroup\$ Yea, it returns NULL, but that's related to the function attributes and it doesn't say in the errors if the OpenGL version is supported or not, only says if they're defined so you won't try 7.52 or something. I know that i can expect a version, i am doing it, i want to use OpenGL 3.3 and if it isn't supported i exit. It's just that i don't know if wglCreateContext will set the version as the maximum supported one so i can check it or will it just return null. I'd like to know if the way i'm checking if the OpenGL version of choice (3.3) is availible. \$\endgroup\$
    – dreta
    May 2, 2012 at 18:15
  • \$\begingroup\$ since you're reading it probably, i'll say additionaly "Querying the GL_VERSION string with glGetString (or the GL_MAJOR_VERSION and GL_MINOR_VERSION values with glGetIntegerv, in a 3.0 or later context) will return the actual version supported by a context." doesn't help me either, because the only exeptions mentioned are that if you specify openGL 3.2 or higher you get 'least that, so i still don't know if i'll get f.e. 2.1 as a resault of version check if that's the latest version supported by the driver, i need a clarification on this specifically \$\endgroup\$
    – dreta
    May 2, 2012 at 18:17
  • \$\begingroup\$ @dreta: See my edit. \$\endgroup\$ May 2, 2012 at 18:24

I like simple. If GLEW loaded correctly, this extension will be valid function pointer. Otherwise it will be null.

    wglCreateContextAttribsARB(hDC, hRC, &attribs)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .