I have a question for glReadPixels.
That I render silhouette using ID IMAGE method, it is render using different color for every silhouette, but I check the frame buffer color miss my result.
I do not know what is happened?
My sample code is next ,wish have someone can help me.
Then use width and height to allocate memory for image. Also check for gl errors every time if your code doesn’t work as you expect. Here are example:
Add this macro on top of every your c/cpp file where you have gl calls:
#define GLCALL(a) {(a); glerr(#a, __LINE__);}
//#define GLCALL(a) a
static void glerr(char *str, int line)
{
int err;
err=glGetError();
if (err!=0)
{
char errstr[1000];
sprintf(errstr, "gl error: %s %d: %s", __FILE__, line, gluErrorString(err));
MessageBox(NULL, errstr, "GL ERROR", MB_OK);
}
}
and use it as:
GLCALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Xres, m_Yres, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
I have found that if you have anti-aliasing enabled either through the control panel or programmatically glReadPixels will not give you the image data as you expect when reading from the back buffer. I found it gave me the background colour instead. I can see why this would be the case but unfortunately do not know any useful way around it. My only suggestions are to either turn AA off or read the front buffer which will give you the AA image but for certain applications this is clearly inappropriate.
If anyone has any suggestions for how to read an AA back buffer I’d be very grateful. I have to admit I have spent no time looking into whether there was a way around it case due to having very little time recently.