I’ve done alot of searching and trial/error, can’t seem to figure this out, so here it goes…
What I am trying to be able to do is to take whatever was last on the screen (currently showing on the screen) and save it as a texture so I can do whatever I want with it. All my attempts to copy it to a texture have failed so far.
Here is a code snippet that I am using to try and create the texture:
glGenTextures(1, &screenTexture);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, screenTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 256, 256, 0);
That is initiated by a button press. Then what I do is render it to one side of a cube. The other 3 sides has textures that I have loaded from a file, and I use the same code to try and render this texture as I do with the other textures. Here is the code I call to render each side of the cube
void DrawQuad(float x1, float y1, float x2, float y2, float z1, float z2, float fWrapCount, GLuint uiTexture)
{
// Use the given texture
glBindTexture(GL_TEXTURE_2D, uiTexture);
// Pass the vertex data
VERTTYPE afVertices[] = {f2vt(x1),f2vt(y1),f2vt(z1), f2vt(x2),f2vt(y1),f2vt(z2), f2vt(x1),f2vt(y2),f2vt(z1), f2vt(x2),f2vt(y2),f2vt(z2)};
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,VERTTYPEENUM,0,afVertices);
// Pass the texture coordinates data
VERTTYPE afTexCoord[] = {f2vt(0),f2vt(0), f2vt(fWrapCount),f2vt(0), f2vt(0),f2vt(fWrapCount), f2vt(fWrapCount),f2vt(fWrapCount)};
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,VERTTYPEENUM,0,afTexCoord);
// Draws an indexed triangle list
unsigned short aIndices[] = {0,1,2, 2,1,3};
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, aIndices);
}
Like I said, the textures that I load from a file work fine, but the screenshot texture…not so much. It creates some garbage on the screen so I know it is doing something, but definitely not what I want it to.
Any ideas on where I am going wrong?