我在使用OpenGL的WGL_ARB pbuffer时遇到了麻烦

时间:2014-02-17 05:12:14

标签: opengl wgl

我试图使用WLG_ARB pbufer进行屏幕外渲染, 但我遇到了wglCreatePbufferARB()的问题 它总是返回NULL。 这是代码的一部分。

bool COpenGLWnd::OffscreenRender
    (/* IN parameters */ int transitionID, int counts, int directionID,
    /* OUT parameters */ BYTE* pPixelArray)
{
    HDC tmpDC = ::GetDC(NULL);
    SetDCPixelFormat(tmpDC);

    HGLRC tmpRC = wglCreateContext(tmpDC);
    VERIFY(wglMakeCurrent(tmpDC, tmpRC));

    HDC hDC = ::GetDC(NULL);
    const int attribList[] =
    {
        WGL_DRAW_TO_PBUFFER_ARB, GL_TRUE,
        WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
        WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
        WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
        WGL_COLOR_BITS_ARB, 32,
        WGL_DEPTH_BITS_ARB, 24,
        WGL_STENCIL_BITS_ARB, 8,
        0,        //End
    };

    int pixelFormat;
    UINT numFormats = 1;

    if(!wglGetCurrentContext())
    {
        return false;
    }

    wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
    if(!wglGetExtensionsStringARB) return false;
    const GLubyte* extensions = (const GLubyte*) wglGetExtensionsStringARB(wglGetCurrentDC());
    if(!extensions)
    {
        return false;
    }

    wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");
    wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC) wglGetProcAddress("wglCreatePbufferARB");
    wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC) wglGetProcAddress("wglGetPbufferDCARB");

    VERIFY(wglMakeCurrent(tmpDC, NULL));
    wglDeleteContext(tmpRC);
    ::ReleaseDC(NULL, tmpDC);

    if(!wglChoosePixelFormatARB) return false;
    if(!wglCreatePbufferARB) return false;
    if(!wglGetPbufferDCARB) return false;

    wglChoosePixelFormatARB(hDC, attribList, NULL, 1, &pixelFormat, &numFormats);


    const int attribTmp[] = {WGL_PBUFFER_LARGEST_ARB, 0, 0};
    m_hbuffer = wglCreatePbufferARB(hDC, pixelFormat, m_BmpWidth, m_BmpHeight, attribTmp);
    HDC hpbufferDC = wglGetPbufferDCARB(hbuffer);
    if(!hpbufferDC) return false;

    HGLRC hpbufferRC = wglCreateContext(hpbufferDC);
    VERIFY(wglMakeCurrent(hpbufferDC, hpbufferRC));
    ...
}

正如我所说,wglCreatePbufferARB返回NULL,因此我无法使用wglGetBufferDCARB。其他WGL_ARB扩展函数非常有效,例如wglGetExtensionsStringARB和wglChoosePixelformetARB。并且扩展得到了非常正常的字符串,它以“WGL_ARB_extensions_string ...”开头。在wglCreatePbufferARB中使用的每个参数都不是NULL,包括hDC。那么为什么wglCreatePbufferARB仍然返回NULL而不能按我的意图工作呢?

++ P.S。 我调用了GetLastError,它返回了ERROR_INVALID_DATA。这是因为attribList,但它的问题是什么?感谢您建议调用GetLastError。

++ P.S。 我解决了这个问题现在这非常有效。谢谢!

0 个答案:

没有答案