Got another problem folks. This is what I’m trying to do: I have two cubes rotating above a plane and over head and behind them is a sphere. I want to move the camera forward, turn 180 degrees around the y axis, take a screen shot using glReadPixels, restore camera to original orientation and position, covert pixel data to a texture, and map it on to the sphere. The problem I’m having is that the scene comes out in black and white when I do this. I’m stumped. Here’s some of my code:
GLfloat *pix; int arraylen; glPixelStoref(GL_PACK_ALIGNMENT, 1); arraylen = 400 * 400 * 3; pix = (GLfloat *)calloc(arraylen, sizeof(GLfloat)); gluLookAt(0, 5, -22, 0, 0, 0, 0, 1, 0); glReadPixels(0, 0, 400, 400, GL_RGB, GL_FLOAT, pix); glEnable(GL_TEXTURE_2D); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 400, 400, 0, GL_RGB, GL_FLOAT, pix); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glLoadIdentity(); glTranslatef(0.0f, 5.0f, -25.0f); glNormal3f(0.0f, 0.0f, 1.0f); glutSolidSphere(3.0f, 25, 25); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_2D);
Any ideas as to where I’m going wrong?