Skip to content

Instantly share code, notes, and snippets.

@turtleli
Created July 16, 2015 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turtleli/fac66d1bb76497f0c3c9 to your computer and use it in GitHub Desktop.
Save turtleli/fac66d1bb76497f0c3c9 to your computer and use it in GitHub Desktop.
Check Supported WGL extensions.
// Semi not so important stuff
// You won't see a window popup. It runs and exits.
// The extension string is written to working directory/supported.txt.
// If it fails after the window is created, it'll write the error there too.
// If it fails before window creation, there'll be no indication.
//
// Needs to be linked against opengl32.lib
// Needs wglext.h from https://www.opengl.org/registry/ placed in gl folder
#define _CRT_SECURE_NO_WARNINGS
#define WIN32_LEAN_AND_MEAN
#include <tchar.h>
#include <windows.h>
#include <GL/GL.h>
#include <stdio.h>
#include "GL/wglext.h"
HDC SetupDC(HWND hwnd, FILE *fp)
{
PIXELFORMATDESCRIPTOR pfd;
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.cStencilBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;
if (HDC hdc = GetDC(hwnd)) {
if (int pixel_format = ChoosePixelFormat(hdc, &pfd))
if (SetPixelFormat(hdc, pixel_format, &pfd))
return hdc;
else
fputs("SetPixelFormat failed\n", fp);
else
fputs("ChoosePixelFormat failed\n", fp);
ReleaseDC(hwnd, hdc);
} else {
fputs("GetDC failed\n", fp);
}
return NULL;
}
void WriteSupportedWGLExtensions(HWND hwnd)
{
FILE *fp = fopen("supported.txt", "w");
if (fp == NULL)
return;
if (HDC hdc = SetupDC(hwnd, fp)) {
if (HGLRC hglrc = wglCreateContext(hdc)) {
wglMakeCurrent(hdc, hglrc);
if (PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"))
fprintf(fp, "%s\n", wglGetExtensionsStringARB(hdc));
else
fputs("wglGetExtensionsStringARB not found", fp);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hglrc);
} else {
fputs("wglCreateContext Failed\n", fp);
}
ReleaseDC(hwnd, hdc);
}
fclose(fp);
}
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc;
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_OWNDC;
wc.lpfnWndProc = DefWindowProc;
wc.hInstance = hInstance;
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT("OpenGLTest");
if (RegisterClass(&wc))
if (HWND hwnd = CreateWindow(wc.lpszClassName, TEXT("OpenGL Test"), 0, 30, 30, 30, 30, NULL, NULL, hInstance, NULL)) {
WriteSupportedWGLExtensions(hwnd);
DestroyWindow(hwnd);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment