I am using to use glReadPixels() in Visual Studio. It works fine in the project which uses glut window, but in another project which uses MFC to display, it can’t read the pixels correctly. Anyone can give me some hint? I totally have no idea. I am not familiar with glReadPixels(). Please see the code below.
void display(void)
{
icVector3 up, ray, view;
int total_bits;
// mapping from 0, center.z+3R to 0 and 1
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-Object.radius1.0, Object.radius1.0, -Object.radius1.0, Object.radius1.0, vd_n, vd_f); // 0.0, Object.center.entry[2]+3.0Object.radius);
view = Object.center-Object.radiusradius_factor*mm;
ray = Object.center - view;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
up.set(1.0, 0.0, 0.0);
normalize(up);
normalize(ray);
if (fabs(dot(ray, up))>0.707)
up.set(0.0, 1.0, 0.0);
//total_bits = int(log(Object.nverts)/log(2)+0.5);
total_bits = int(log((double)Object.nverts)/log(2*1.0)+0.5);
gluLookAt(view.entry[0], view.entry[1], view.entry[2], Object.center.entry[0], Object.center.entry[1], Object.center.entry[2], up.entry[0], up.entry[1], up.entry[2]);
glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix);
glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix);
glGetIntegerv(GL_VIEWPORT, viewport);
// glCallList(theObject);
unsigned char a, b, c;
unsigned int i, j;
Face *face;
int *verts;
fprintf(stderr, "in
");
for (i=0; i<20; i++) { // Object.nfaces; i++) {
if (i>=Object.nfaces)
continue;
a = i >> 16;
b = (i & 0xFF00) >> 8;
c = i & 0xFF;
glColor3ub(255-a, 255-b, 255-c);
face = Object.flist[i];
verts = face->verts;
glBegin(GL_POLYGON);
for (j=0; j<face->nverts; j++) {
glVertex3d(Object.vlist[verts[j]]->x, Object.vlist[verts[j]]->y, Object.vlist[verts[j]]->z);
}
glEnd();
}
fprintf(stderr, "out
");
glReadBuffer(GL_BACK);
glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
glReadPixels(0, 0, win_width, win_height, GL_DEPTH_COMPONENT, GL_FLOAT, depths);
static int counterMARK = 0;
char buffer[128];
sprintf(buffer,"mark%0.4i.ppm", counterMARK++);
SSS_SavePPM(win_width, win_height, pixels, buffer);
// glDrawPixels(win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
//glutSwapBuffers();
glFlush();
glFinish();
}
Thank you for any help!!!