Original Post
I have a problem when initializing pbuffers. In my Draw() method, even though I don't enable, disable or render to pbuffer, all my polygons are rendered black if I initialize the pbuffer. I don't know why this happens. If I remove the initialization from the code, I get the colors. Here's my pbufferInit() method: Does anyone have an idea of why this happens? Thank you, Sriram
BOOL pbufferInit (int width, int height)
{
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
wglMakeContextCurrentARB = (PFNWGLMAKECONTEXTCURRENTARBPROC)wglGetProcAddress("wglMakeContextCurrentARB");
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
wglQueryPbufferARB = (PFNWGLQUERYPBUFFERARBPROC)wglGetProcAddress("wglQueryPbufferARB");
wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB");
wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB");
wglSetPbufferAttribARB = (PFNWGLSETPBUFFERATTRIBARBPROC)wglGetProcAddress("wglSetPbufferAttribARB");
if (pbufferInitialized)
{
pbufferDestroy();
}
pbufferWidth = width;
pbufferHeight = height;
GLubyte *extensionString = (GLubyte *)wglGetExtensionsStringARB(wglGetCurrentDC());
hGLDC = wglGetCurrentDC();
hGLRC = wglGetCurrentContext();
if (hGLDC == NULL)
{
MessageBox(NULL, "Error : Unable to get Current Device Context", "Context Error", MB_OK);
return(false);
}
if (hGLRC == NULL)
{
MessageBox(NULL, "Error: unable to get GL Render Context", "Context Error", MB_OK);
return(false);
}
int attr[] =
{
WGL_SUPPORT_OPENGL_ARB, TRUE, // pbuffer will be used with gl
WGL_DRAW_TO_PBUFFER_ARB, TRUE, // enable render to pbuffer
WGL_BIND_TO_TEXTURE_RGBA_ARB, TRUE, // pbuffer will be used as a texture
WGL_RED_BITS_ARB, 8, // at least 8 bits for RED channel
WGL_GREEN_BITS_ARB, 8, // at least 8 bits for GREEN channel
WGL_BLUE_BITS_ARB, 8, // at least 8 bits for BLUE channel
WGL_ALPHA_BITS_ARB, 8, // at least 8 bits for ALPHA channel
WGL_DEPTH_BITS_ARB, 24, // at least 24 bits for depth buffer
WGL_DOUBLE_BUFFER_ARB, FALSE, // we don't require double buffering
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
0 // zero terminates the list
};
// choose a pixel format that meets our minimum requirements
unsigned int count = 0;
int pixelFormat=0;
wglChoosePixelFormatARB(hGLDC,(const int*)attr, NULL, 1,&pixelFormat,&count);
if(count == 0)
{
MessageBox(NULL, "P-buffer Error: Unable to find an acceptable pixel format", "Context Error", MB_OK);
return(false);
}
// set some pbuffer attributes so that we can use this pbuffer as a
// 2D RGBA texture target
int pAttrib[] =
{
WGL_TEXTURE_FORMAT_ARB, // our pbuffer will have texture format RGBA
WGL_TEXTURE_RGBA_ARB,
WGL_TEXTURE_TARGET_ARB, // of texture type GL_TEXTURE_2D
WGL_TEXTURE_2D_ARB,
0 // zero terminates the list
};
// allocate the pbuffer
hPBuffer = wglCreatePbufferARB(hGLDC, pixelFormat, width, height, (const int*)pAttrib);
hPBufferDC = wglGetPbufferDCARB(hPBuffer);
hPBufferRC = wglCreateContext(hPBufferDC);
if(!hPBuffer)
{
MessageBox(NULL, "P-buffer Error: Unable to create P-buffer", "Context Error", MB_OK);
return(false);
}
glGenTextures( 1, &pbufferTextureID );
glBindTexture( GL_TEXTURE_2D, pbufferTextureID );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,0);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR );
pbufferInitialized = true;
return TRUE;
}