【发布时间】:2009-02-18 14:20:16
【问题描述】:
我正在 Visual Studio 2005 中使用 C++ 编写一些 OpenGL。
// SetUpOpenGL sets the pixel format and a rendering
// context then returns the RC
HGLRC COpenGLBaseWnd::SetUpOpenGL(HWND hwnd)
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof (PIXELFORMATDESCRIPTOR), // strcut size
1, // Version number
PFD_DRAW_TO_WINDOW | // Flags, draw to a window,
PFD_DOUBLEBUFFER | // enable double buffering
PFD_SUPPORT_OPENGL, // use OpenGL
PFD_TYPE_RGBA, // RGBA pixel values
24, // 24-bit color
0, 0, 0, // RGB bits & shift sizes.
0, 0, 0, // Don't care about them
0, 0, // No alpha buffer info
0, 0, 0, 0, 0, // No accumulation buffer
32, // 32-bit depth buffer
0, // No stencil buffer
0, // No auxiliary buffers
PFD_MAIN_PLANE, // Layer type
0, // Reserved (must be 0)
0, // No layer mask
0, // No visible mask
0 // No damage mask
};
pCDC = pWnd->GetDC();
hDC = pCDC->GetSafeHdc();
PixelFormatID = ChoosePixelFormat(hDC, &pfd);
if (!PixelFormatID)
{
// catch errors here.
// If nMyPixelFormat is zero, then there's
// something wrong... most likely the window's
// style bits are incorrect (in CreateWindow() )
// or OpenGl isn't installed on this machine
//printf("ChoosePixelFormat Failed %d\r\n",GetLastError());
abort();
exit(-1);
}
if (pfd.dwFlags & PFD_NEED_PALETTE)
{
//printf("Choosen Pixel Format requires a palette.\r\n");
abort();
exit(-1);
}
SetPixelFormat(hDC, PixelFormatID, &pfd);
而且 SetPixelFormat 调用在运行时会发生爆炸。烦人的是,它只会在我的机器上崩溃,而不是在我同事的机器上。
我在 stackoverflow 上找到了看起来相关的 this answer,但要么我不知道如何在 C++ 中使用此信息解决问题,要么不是同一个问题。
我需要有关如何在 C++ 或其他潜在解决方案中实现该解决方案的建议。
【问题讨论】:
-
我认为您不小心提交了一半的问题?
-
哦,原来还不到一半。
-
是链接错误还是崩溃?它们完全是不同的野兽。
-
哪个 OpenGL 调用?在这个sn-p中我看不到任何东西。 SetPixelFormat() 是 Win32 API 调用,而不是 OpenGL。
-
抱歉,我已经改写了问题以使其更清楚。链接器错误是指我在其他地方找到并在问题中链接到的答案。链接器,但显然链接的顺序很重要。
标签: c++ visual-studio opengl