littlemanrkc
10-08-2009, 12:22 PM
I have an MFC application that needs to save off screen captures every time it is redrawn. I want this to happen even when the windows is hidden or minimized, so I've begun to delve into the world of frame buffer objects. What I have works properly until I display something on the screen. After that glCheckFramebufferStatus(GL_FRAMEBUFFER) always returns 0. Here's a rough cut of my code:
Draw ()
{
// Set our current render target based on window visibility
if (bRenderToScreen)
{
wglMakeCurrent (m_hDC, m_hRC)
}
else
{
glBindFramebuffer (GL_FRAMEBUFFER, m_uiOffscreenFBO);
glDrawBuffer (GL_DEPTH_ATTACHMENT_EXT);
glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
eStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
// eStatus is always 0x0 after making a single call to the Draw() function with bRenderToScreen=true. It is set to GL_FRAMEBUFFER_COMPLETE every time until that happens.
}
// Drawing code goes here...
// Save off a screenshot
glReadPixels (0, 0, width (), height(), GL_RGB, GL_UNSIGNED_BYTE, pucRGBdata);
SaveImage (pucImage);
// Undo our current render target
if (bRenderToScreen)
{
SwapBuffers (m_hDC);
wglMakeCurrent (m_hDC, NULL);
}
else
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDrawBuffer (GL_BACK);
}
}
So basically, my frame buffer fails to work properly after I've made one call to the Draw() function when bRenderToScreen is set to true. Does anyone have any ideas what might be wrong?
Draw ()
{
// Set our current render target based on window visibility
if (bRenderToScreen)
{
wglMakeCurrent (m_hDC, m_hRC)
}
else
{
glBindFramebuffer (GL_FRAMEBUFFER, m_uiOffscreenFBO);
glDrawBuffer (GL_DEPTH_ATTACHMENT_EXT);
glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
eStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
// eStatus is always 0x0 after making a single call to the Draw() function with bRenderToScreen=true. It is set to GL_FRAMEBUFFER_COMPLETE every time until that happens.
}
// Drawing code goes here...
// Save off a screenshot
glReadPixels (0, 0, width (), height(), GL_RGB, GL_UNSIGNED_BYTE, pucRGBdata);
SaveImage (pucImage);
// Undo our current render target
if (bRenderToScreen)
{
SwapBuffers (m_hDC);
wglMakeCurrent (m_hDC, NULL);
}
else
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDrawBuffer (GL_BACK);
}
}
So basically, my frame buffer fails to work properly after I've made one call to the Draw() function when bRenderToScreen is set to true. Does anyone have any ideas what might be wrong?