PDA

View Full Version : Problem with glReadPixels under WindowsXP



jong_allegraud
10-31-2003, 05:12 AM
Hi,
I have a some bugs while saving image files from an OpenGL context: all works fine except when I open focus on another window and put in over the openGL display zone(or when i focus on the open GL zone when another window is over it), the image saved does not contain only the openGL generated image but also a part of the other window.
Here is a sample of my drawing function:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

// Here the code to generate my OpenGL objects

if (m_GLStoreMode!=NONE) // To be clear
{
if (m_pRaw) delete []m_pRaw;
m_pRaw = NULL;
switch(m_GLStoreMode)
{
case ARGB:
GetARGBImage(&m_iRawWidth,&m_iRawHeight,(void**)(&m_pRaw));
break;
default:
break;
}
}
// swap the buffer
SwapBuffers(m_hDC);

int GetARGBImage(int *pWidth,int *pHeight,void **pData)
{
unsigned int *pInvRaw = new unsigned int[m_iWidth*m_iHeight];
*pWidth = m_iWidth;
*pHeight = m_iHeight;
cout<<"SetMemory"<<endl;
(*pData) = new unsigned int[m_iWidth*m_iHeight]; // ARGB

if (!(*pData)) return 1;

// VERIFY(wglMakeCurrent(m_hDC, m_hGLContext));
glReadPixels(0,0,(GLsizei)m_iWidth,(GLsizei)m_iHei ght,GL_BGRA,GL_UNSIGNED_INT_8_8_8_8_REV,pInvRaw);

int i,j;
for( i=0;i<m_iHeight;i++)
for(j=0;j<m_iWidth;j++)
((unsigned int*)(*pData))[(m_iHeight-i-1)*m_iWidth+j]= pInvRaw[i*m_iWidth+j];

return 0;
}

Can anyone help please

Jong

Bob
10-31-2003, 05:26 AM
The content of occluded pixels are undefined.

vmh5
10-31-2003, 06:18 AM
Bob is correct. But even though it's undefined several NVidia & ATI drivers will render occluded portions of the Window anyway. The right thing to do is to render to a pbuffer.

jong_allegraud
10-31-2003, 06:40 AM
Thanks, I will look at pbuffers as it seems to be the only good solution.

Jong