I'm trying to create an OpenGL window on an x64 platform.
My initalization code works for x86/Win32, but fails for x64 at "wglMakeCurrent". I guess the problem is either in the setting of the pixelformat or in getting the DC (getDC()). I've tried different settings for my PIXELFORMATDESCRIPTOR already (assumed that the x64 implementation of OpenGL doesn't support that one I'm using), but had no success there. The debugger indicates that hdc may be corrupt - (its like 0xfffffffff10102e0) - however wglCreateContext returns an valid looking hglrc then (i.e. 0x0000000000010000). But even if I change the value from hdc on-the-fly to 0x0000000010102e0 (using the debugger, before the call of wglCreateContext) wglMakeCurrent still fails.
I'm on windows 8 with Visual Studio 12 RC 1.
Any ideas what I'm doing wrong here? Or is there maybe some limitation of the x64 OpenGL implementation?
#include <windows.h>
#pragma comment(lib, "OpenGL32.lib")
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
switch (uMsg){
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WindowProc;
wc.hInstance = nullptr;
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClassTest";
RegisterClassEx(&wc);
DWORD dwStyle = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
RECT WindowRect;
WindowRect.left = (long)0;
WindowRect.right = (long)640;
WindowRect.top = (long)0;
WindowRect.bottom = (long)480;
AdjustWindowRect(&WindowRect, dwStyle, FALSE);
HWND hWnd = CreateWindowEx(0,
"WindowClassTest",
"WindowTitle",
dwStyle,
0, 0,
WindowRect.right - WindowRect.left,
WindowRect.bottom - WindowRect.top,
nullptr,
nullptr,
wc.hInstance,
(LPVOID) nullptr);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
ShowWindow(hWnd, SW_SHOW);
SetFocus(hWnd);
HDC hdc = GetDC(hWnd);
int pf;
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pf = ChoosePixelFormat(hdc, &pfd);
if (pf == 0) {
MessageBox(NULL, "ChoosePixelFormat() failed: "
"Cannot find a suitable pixel format.", "Error", MB_OK);
}
if (SetPixelFormat(hdc, pf, &pfd) == FALSE) {
MessageBox(NULL, "SetPixelFormat() failed: "
"Cannot set format specified.", "Error", MB_OK);
}
DescribePixelFormat(hdc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
HGLRC hglrc = wglCreateContext(hdc);
if (!wglMakeCurrent(hdc, hglrc)){
MessageBox(NULL, "wglMakeCurrent() failed: "
"Cannot make context current.", "Error", MB_OK);
}
/* left out other unnecessary code here*/
return 0;
}