1

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

LucasSokol
  • 125
  • 4

2 Answers2

2

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/

datenwolf
  • 159,371
  • 13
  • 185
  • 298
1

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.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 2
    @LucasSokol What does this have to do with glew? See https://gist.github.com/nickrolfe/1127313ed1dbf80254b614a721b3ee9c – Rabbid76 Jul 07 '23 at 12:12