c++ - SetPixelFormat 返回 0 错误代码 3221684230 (C0070006)

标签 c++ opengl

我尝试创建一个 openGL 上下文。 如果我在 Radeon GPU 上启动它,它工作正常......但在我测试过的每张 nvidia 卡上,它都会崩溃。

m_hWindowHandleToDevice = GetDC(hWnd);

m_PixelFormat = {
    sizeof(PIXELFORMATDESCRIPTOR),
    1,
    PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,    //Flags
    PFD_TYPE_RGBA,              //The kind of framebuffer. RGBA or palette.
    32,                         //Colordepth of the framebuffer.
    0, 0, 0, 0, 0, 0,
    0,
    0,
    0,
    0, 0, 0, 0,
    24,                         //Number of bits for the depthbuffer
    8,                          //Number of bits for the stencilbuffer
    0,                          //Number of Aux buffers in the framebuffer.
    PFD_MAIN_PLANE,
    0,
    0, 0, 0
};

int PixelFormatHandle = ChoosePixelFormat(m_hWindowHandleToDevice, &m_PixelFormat);
BOOL bPixelFormatOK = SetPixelFormat(m_hWindowHandleToDevice, PixelFormatHandle, &m_PixelFormat);
DWORD nLastError = GetLastError();
m_hOpenGLContext = wglCreateContext(m_hWindowHandleToDevice);
nLastError = GetLastError();

变量是:

PixelFormatHandle = 9

bPixelFormatOK = 0

nLastError (first time) = 3221684230 

nLastError (at the end) = 2000   //ERROR_INVALID_PIXEL_FORMAT

m_hOpenGLContext = 0

m_hWindowHandleToDevice = 670115fb //so it is set...

所有驱动程序均已更新,我正在使用:

NVIDIA NVS 3100M / not working

NVIDIA gtx 780 / not working

AMD Radeon R7 M370 / is working

Intel(R) HD Graphics 530 / is working

提前谢谢

托马斯

最佳答案

MSDN 说 cColorBits 没有 alpha(尽管我经常在那里看到 32)...

SetPixelFormat() 失败(返回 FALSE)。它从那里开始下降。使用 DescribePixelFormat 检查Chosen PixelFormat,以确保您得到了合理的结果。

您只能设置像素格式一次。确保你这样做。 你把这一切称为哪里?我认为最安全的地方是 WM_CREATE 处理程序。

试试这个传说中的老东西:Nehe OpenGL Window (最后有来源)。 如果连这个都不起作用,那就太奇怪了。或者你知道:不要试图变得太聪明并使用 GLFW 或类似的东西。

关于c++ - SetPixelFormat 返回 0 错误代码 3221684230 (C0070006),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36794641/

相关文章:

c++ - 为什么我的串行通过串行监视器在 Arduino IDE 上打印两次?

c - 根据点旋转一个物体

c++ - OSX Xcode 6 上的 OpenGL 4.1 设置困难

c++ - 由于架构 x86_64 的符号未定义,GLFW 的最小示例失败

c - GLSL:用旋转 vector 旋转?

cocoa - 当我使用 OpenGL Core Profile 3.2 时,我的三角形不渲染

c++ - 将 Armadillo 中的矩阵从稀疏矩阵转换为密集矩阵(spmat 到 mat)

c++ - gcc 和 class 关键字

c++ - 使用 C++ 的安全套接字连接

c++ - 线程本身终止时如何删除boost线程对象?