// // gcc xwin-gl-probe.c -lgdi32 -lopengl32 -o xwin-gl-probe.exe -Wall // #include #include int main(void) { HWND hwnd; HDC hdc; HGLRC hglrc; // create window class #define WIN_GL_TEST_WINDOW_CLASS L"XWinGLTest" { static ATOM glTestWndClass = 0; if (glTestWndClass == 0) { WNDCLASSEXW wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = DefWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetModuleHandle(NULL); wc.hIcon = 0; wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = WIN_GL_TEST_WINDOW_CLASS; wc.hIconSm = 0; RegisterClassExW(&wc); } } // create an invisible window for a scratch DC hwnd = CreateWindowExW(0, WIN_GL_TEST_WINDOW_CLASS, L"XWin GL Renderer Capabilities Test Window", WS_OVERLAPPEDWINDOW|WS_VISIBLE, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); if (hwnd == NULL) { printf("Couldn't create a window for render capabilities testing\n"); goto error; } hdc = GetDC(hwnd); if (!hdc) { printf("Couldn't create a DC for render capabilities testing\n"); goto error; } // we must set a pixel format before we can create a context { PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DEPTH_DONTCARE | PFD_DOUBLEBUFFER_DONTCARE | PFD_STEREO_DONTCARE, PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; int iPixelFormat = ChoosePixelFormat(hdc, &pfd); if (iPixelFormat == 0) { printf("ChoosePixelFormat failed\n"); goto error; } if (!SetPixelFormat(hdc, iPixelFormat, NULL)) { printf("SetPixelFormat %d failed\n", iPixelFormat); goto error; } printf("Testing pixelFormatIndex %d\n",iPixelFormat); } hglrc = wglCreateContext(hdc); if (!wglMakeCurrent(hdc, hglrc)) { printf("wglMakeCurrent error: %08x dc %p ctx %p\n", (unsigned)GetLastError(), hdc, hglrc); } printf("Done\n"); error: return 0; }