windowsopenglgraphicsrenderinghwnd

HGLRC OpenGL rendering context - How to indicate the version of the OpenGL


How I'm creating my rendering context using wgl :

//Device
HDC hdc = GetDC(hWnd);

HGLRC hRC = wglCreateContext(hdc);

How/where/when should I change the version of the OpenGL context?

Is there a function like wglCreateContextVer(hdc, major(3) /major/, 0 /minor/, "core");


Solution

  • You can use wglCreateContextAttribsARB. e.g.:

    int attributes[] = {
        WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
        WGL_CONTEXT_MINOR_VERSION_ARB, 3,
        WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
        WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 1,
        0,
    };
    HGLRC hRC = wglCreateContextAttribsARB(hdc, 0, attributes);
    

    See also Sample code showing how to create a window using a modern OpenGL core profile context without any libraries other than the standard Win32 wglXXX calls.