Hey chaps,
I'm currently trying to setup some off screen render effects to perform post render effects on my scene using pbuffers. Having taken the whitepapers from NVIDIA and ATI I've come up with the following initialisation routine.
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, TRUE, // we want double buffering
0
};
unsigned int Count = 0;
int PixelFormat;
// find a pixel format that meets the above requirements
wglChoosePixelFormatARB( m_hDC, (const int*)attr, NULL, 1, &PixelFormat, &Count );
if(Count == 0)
{
g_ProgramLog.Log( LOG_WARNING, "Pbuffer Error: Unable to find an acceptable pixel format" );
return S_FALSE;
}
// setup the pbuffer so it can be used as a texture
int pAttrib[] =
{
WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB,
WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,
WGL_MIPMAP_TEXTURE_ARB, 0,
WGL_PBUFFER_LARGEST_ARB, 0,
0
};
// allocate the pbuffer
m_hRenderTexture = wglCreatePbufferARB(m_hDC, PixelFormat, (int)m_uiWidth/2, (int)m_uiHeight/2, (const int*)pAttrib);
m_hRenderTextureDC = wglGetPbufferDCARB(m_hRenderTexture);
m_hRenderTextureRC = wglCreateContext(m_hRenderTextureDC);
if(!m_hRenderTexture)
{
g_ProgramLog.Log( LOG_WARNING, "Pbuffer Error: Unable to create Pbuffer" );
return S_FALSE;
}
// make a texture object for binding the pbuffer to
glGenTextures(1, &m_uiRenderTextureID);
glBindTexture(GL_TEXTURE_2D, m_uiRenderTextureID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
return S_OK;
The main issue with this code is that it fails to create the pbuffer even though the values passed to the function are all correct (at least according to the whitepapers).
If I take the code down to the minimum that the NVIDIA whitepaper says it required I still have the same problem.
int attr[] =
{
WGL_DRAW_TO_PBUFFER_ARB, TRUE, // enable render to pbuffer
WGL_BIND_TO_TEXTURE_RGBA_ARB, TRUE, // pbuffer will be used as a texture
0
};
unsigned int Count = 0;
int PixelFormat;
// find a pixel format that meets the above requirements
wglChoosePixelFormatARB( m_hDC, (const int*)attr, NULL, 1, &PixelFormat, &Count );
if(Count == 0)
{
g_ProgramLog.Log( LOG_WARNING, "Pbuffer Error: Unable to find an acceptable pixel format" );
return S_FALSE;
}
// setup the pbuffer so it can be used as a texture
int pAttrib[] =
{
WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB,
WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,
0
};
// allocate the pbuffer
m_hRenderTexture = wglCreatePbufferARB(m_hDC, PixelFormat, (int)m_uiWidth/2, (int)m_uiHeight/2, (const int*)pAttrib);
m_hRenderTextureDC = wglGetPbufferDCARB(m_hRenderTexture);
m_hRenderTextureRC = wglCreateContext(m_hRenderTextureDC);
if(!m_hRenderTexture)
{
g_ProgramLog.Log( LOG_WARNING, "Pbuffer Error: Unable to create Pbuffer" );
return S_FALSE;
}
// make a texture object for binding the pbuffer to
glGenTextures(1, &m_uiRenderTextureID);
glBindTexture(GL_TEXTURE_2D, m_uiRenderTextureID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
return S_OK;
Both versions fail to create the pbuffer. The card supports all the extensions needed it just seems nothing works.
:(
Any help is appreciated,
Charles