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

178 Views Asked by At

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

2

There are 2 best solutions below

1
Rabbid76 On BEST ANSWER

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.

0
datenwolf On

The cliff notes version:

  1. Create dummy window and OpenGL context to get access to extension functions.
  2. Fetch entry points for wglCreateContextAttribsARB and friends.
  3. Use those to create the window proper and the OpenGL context for it.
  4. Bonus points: Making it all thread safe.

For everyone's convenience I did all the heavy lifting in my wglarb helper library. Get it here (also comes with example programs): https://git.datenwolf.net/wglarb/