wglMakeCurrent 在 x64 上失败
wglMakeCurrent fails on x64
我正在尝试在x64平台上创建一个OpenGL窗口。我的初始代码适用于x86/Win32,但在"wglMakeCurrent"处对x64失败。我想问题要么出在像素格式的设置上,要么出在获取 DC (getDC((( 上。我已经为我的像素格式描述符尝试了不同的设置(假设 OpenGL 的 x64 实现不支持我正在使用的那个(,但在那里没有成功。调试器指示 hdc 可能已损坏 - (就像0xfffffffff10102e0一样( - 但是 wglCreateContext 返回一个有效的 hglrc 然后(即0x0000000000010000(。但是,即使我将值从 hdc 即时更改为 0x0000000010102e0(使用调试器,在调用 wglCreateContext 之前(,wglMakeCurrent 仍然失败。
我使用的是带有Visual Studio 12 RC 1的Windows 8。知道我在这里做错了什么吗?或者x64 OpenGL实现可能存在一些限制?
#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;
}
非常具体的错误,在某些情况下,在Windows 8.x虚拟机中运行64位OpenGL应用程序时触发。根据可用的报告(见下文(,它发生在
- 该应用程序已使用 Visual Studio>= 2012 为 x64 编译
- 它在 Windows 8.x 中执行,运行在 VM 内 (Parallels/VMWare(
我在用于编译适用于 Windows 的应用程序的 Parallels VM 中遇到了同样的问题。一个临时的解决方法是使用32位版本或使用以前版本的Visual Studio(我使用2010(编译为64位。
重要的是,在非模拟硬件上运行的Windows 8.x似乎不受影响。
指向提及此问题的其他人的链接:
http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/b3fbe482-eba4-451d-bbed-3bc00b7c8bb5/wglmakecurrent-in-windows-8-64-bit-always-returns-false?forum=windowssdk
http://connect.microsoft.com/VisualStudio/feedback/details/780757/opengl-in-mfc-application-does-not-work-in-windows-8-64-bit
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 从父数组测试用例构造二叉树失败
- LibGit2 SSH身份验证失败
- 如何让LLDB在成功时退出,在失败时等待
- C++ Boost::asio x64 async_send失败,出现错误 10014 (WSAEFAULT)
- 在OpenCV 3.1.0 x64 (VS12)中使用TAPI时的BSOD(内核安全检查失败)
- wglMakeCurrent 在 x64 上失败
- COM dll x64 上的 regsvr32 调试失败,无法获取有关此的详细信息