Problem with glReadPixels under WindowsXP

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_iWidthm_iHeight];
*pWidth = m_iWidth;
*pHeight = m_iHeight;
cout<<“SetMemory”<<endl;
(pData) = new unsigned int[m_iWidthm_iHeight]; // ARGB

if (!(*pData)) return 1;

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

int i,j;
for( i=0;i&lt;m_iHeight;i++)
	for(j=0;j&lt;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

The content of occluded pixels are undefined.

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.

Thanks, I will look at pbuffers as it seems to be the only good solution.

Jong