Getting Legacy Support with WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB

Hi there,

I am getting the extended render context with wglCreateContextAttribsARB and passing
WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB to the attribute field. However, whenever I do this
I do not even get the requested OpenGL version. The driver(?) just sets it to the highest available which is 4.6
on my machine. When I change the bit to WGL_CONTEXT_CORE_PROFILE_BIT_ARB I can select the OGL version
down to 3.0 which seems to be the lowest supported on my machine. I check the version I got with: (LPCSTR)glGetString(GL_VERSION)

I’ve got the init code for the OpenGL context here, maybe this helps:



int initGL(HWND* windowHandle, WNDCLASS* windowClass)
{
    PIXELFORMATDESCRIPTOR pixelFormatDescriptor =
    {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,    // Flags
        PFD_TYPE_RGBA,        // The kind of framebuffer. RGBA or palette.
        32,                   // Colordepth of the framebuffer.
        0, 0, 0, 0, 0, 0,
        0,
        0,
        0,
        0, 0, 0, 0,
        24,                   // Number of bits for the depthbuffer
        8,                    // Number of bits for the stencilbuffer
        0,                    // Number of Aux buffers in the framebuffer.
        PFD_MAIN_PLANE,
        0,
        0, 0, 0
    };
    HDC dummyDC = GetDC(*windowHandle);
    // try to find best matching pixel format.
    int pixelFormatNr = ChoosePixelFormat(dummyDC, &pixelFormatDescriptor);
    if (!pixelFormatNr) // was null
    {
        OutputDebugStringA("could not get pxl format nr
");
        // TODO(Michael): logging
        return 1;
    }
    
    if (!SetPixelFormat(dummyDC, pixelFormatNr, &pixelFormatDescriptor))
    {
        return 1;
    }
    
    HGLRC dummyRC = wglCreateContext(dummyDC);
    if (!dummyRC)
    {
        return 1;
    }
    
    // load extensions
    if (wglMakeCurrent(dummyDC, dummyRC))
    {
        OutputDebugStringA("ogl rendering context made current
");
        // TODO(Michael): query supported extensions
        
        // LOAD OGL EXTENSIONS HERE (according to ogl docu, msdn says sth different)
        wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)
            wglGetProcAddress("wglChoosePixelFormatARB");
        if (!wglChoosePixelFormatARB) return 0;
        wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
            wglGetProcAddress("wglCreateContextAttribsARB");
        if (!wglCreateContextAttribsARB) return 0;
        glGenBuffers = (PFNGLGENBUFFERSPROC)
            wglGetProcAddress("glGenBuffers");
        glBindBuffer = (PFNGLBINDBUFFERPROC)
            wglGetProcAddress("glBindBuffer");
        glBufferData = (PFNGLBUFFERDATAPROC)
            wglGetProcAddress("glBufferData");
    }
    
    // destroy dummy RC, DC, Window
    if (!wglMakeCurrent(0, 0))
    {
        return 1;
    }
    wglDeleteContext(dummyRC);
    ReleaseDC(*windowHandle, dummyDC);
    DestroyWindow(*windowHandle);
    
    // create "real" opengl context
    *windowHandle = CreateWindow(
        windowClass->lpszClassName,
        "Hello OpenGL2",
        WS_OVERLAPPEDWINDOW | WS_VISIBLE,
        0,
        0,
        1280,
        720,
        0,
        0,
        windowClass->hInstance,
        0
        );
    
    if (windowHandle == NULL)
    {
        return 1;
    }
    global_deviceContext = GetDC(*windowHandle);
    
    const int pixelAttribs[] = {
        WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
        WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
        WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
        WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
        WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
        WGL_COLOR_BITS_ARB, 24,
        WGL_ALPHA_BITS_ARB, 8,
        WGL_DEPTH_BITS_ARB, 24,
        WGL_STENCIL_BITS_ARB, 8,
        WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
        WGL_SAMPLES_ARB, 4,
        0
    };
    
    int pixelFormat;
    UINT numFormats;
    // get the pixel format id by checking the DC and the attributes
    int ok = wglChoosePixelFormatARB(global_deviceContext,
                                     pixelAttribs,
                                     0,
                                     1, // max pixel formats we want
                                     &pixelFormat,   // return: pixel format numbers
                                     &numFormats); // return: how many were created
    if (!ok)
    {
        return 1;
        OutputDebugStringA("Failed to create ARB pixel format
");
    }
    
    // fill the PFD struct by telling what the pixel format is set
    PIXELFORMATDESCRIPTOR PFD;
    DescribePixelFormat(global_deviceContext, pixelFormat, sizeof(PFD), &PFD);
    // set the DC's pixel format
    if (SetPixelFormat(global_deviceContext, pixelFormat, &PFD) == 0)
    {
        return 1;
    }
    
    int contextAttribs[] = {
        WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
        WGL_CONTEXT_MINOR_VERSION_ARB, 0,
        WGL_CONTEXT_FLAGS_ARB, 0,
        WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
        //WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
        0
    };
    
    // create gl render context
    global_oglRenderContext = wglCreateContextAttribsARB(global_deviceContext, 0, contextAttribs);
    
    if (global_oglRenderContext == 0)
    {
        return 1;
    }
    
    if (!wglMakeCurrent(global_deviceContext, global_oglRenderContext))
    {
        return 1;
    }
    
    return 0;
}



I have checked the documentation and I am not sure what is going wrong here. Drawing a triangle with glBegin() glEnd() does not work. Setting the color
in the Backbuffer and display it by Swapping the DC works just fine, though.

Maybe my nVidia driver just disabled support for that completely, which from what I have read is unlikely…

Any help/hints highly appreciated. Thank you.
Best, Pythno

The implementation is not required to provide the exact version requested, only a context which is compatible with the requested version and profile. A 4.6 context provides all of the functionality which was available in all versions up to and including 3.0 and in the compatibility profile of all versions since 3.2 (3.1 effectively only supports the core profile).

The profile should be ignored if the requested version is less than 3.2, as that was the first version to introduce profiles.

Note that a 3.2+ compatibility profile isn’t considered compatible with a 3.2+ core profile because there are slight differences in behaviour; although the only one which immediately springs to mind is that GL_POINT_SPRITE is disabled by default in the compatibility profile but enabled always in the core profile.

The exact behaviour is documented in the WGL_ARB_create_context extension.