Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active January 25, 2020 17:32
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pervognsen/b4b0438a57a42461a8298d6d2779140c to your computer and use it in GitHub Desktop.
Save pervognsen/b4b0438a57a42461a8298d6d2779140c to your computer and use it in GitHub Desktop.
// Despite appearances to the contrary, this does proper error handling. Any error cascades into a failure of the wglGetProcAddress.
int init_opengl() {
HWND window = CreateWindowA("edit", "", WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
PIXELFORMATDESCRIPTOR format_desc = {
.nSize = sizeof(PIXELFORMATDESCRIPTOR),
.nVersion = 1,
.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL
};
HDC dc = GetDC(window);
int format = ChoosePixelFormat(dc, &format_desc);
SetPixelFormat(dc, format, &format_desc);
HGLRC rc = wglCreateContext(dc);
wglMakeCurrent(dc, rc);
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
wglDeleteContext(rc);
ReleaseDC(window, dc);
DestroyWindow(window);
return wglCreateContextAttribsARB != NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment