gpt4 book ai didi

c++ - C++ 中的 OpenGL - 运行时崩溃

转载 作者:行者123 更新时间:2023-11-28 08:33:56 26 4
gpt4 key购买 nike

我正在 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 调用是它在运行时发生的地方。烦人的是,它只会在我的机器上崩溃,而不会在我同事的机器上崩溃。

我找到了 this answer ,在 stackoverflow 上看起来是相关的,但是我不知道如何使用 C++ 中的这些信息来解决问题,或者这不是同一个问题。

我需要有关如何在 C++ 或其他潜在解决方案中实现该解决方案的建议。

最佳答案

确保在创建窗口类时,未指定 CS_PARENTDC 而指定了 CS_OWNDC

SetPixelFormat() 是否检测到 DC 是共享的(弄乱上述任一标志的效果)我不知道,但 OpenGL 将无法正常工作,除非窗口有一个专用的hDC值。

关于c++ - C++ 中的 OpenGL - 运行时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/561224/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com