I was trying to do off-screen rendering with WLG_ARB pbufer, but I got trouble with wglCreatePbufferARB() It always returns NULL. Here is a part of the code.
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));
...
}
As I said, wglCreatePbufferARB returns NULL so I can't use wglGetBufferDCARB. Other WGL_ARB extension functions work very well, such as wglGetExtensionsStringARB and wglChoosePixelformetARB. And also extension got very normal string, it starts with "WGL_ARB_extensions_string..." Every parameter used at wglCreatePbufferARB wasn't NULL, including hDC. Then why wglCreatePbufferARB still returns NULL and doesn't work what I intended?
++p.s. I called GetLastError and it returned ERROR_INVALID_DATA. It's because of attribList, but what's the matter of it? Thanks for the recommendation to call GetLastError.
++p.s. I solved this. Now this works very well. Thank you!