I was trying to create two textures use real-time snap shots of my scene. It display well and act well when there’s only one texture object. When there’s more than one texture object, it doesn’t display the one specified second, and what’s more, it crashes if I try to move the display window… it seems like a memory thing, though I assigned memory space for each texture object, they didn’t use that. They use something else instead, which cause the first texture correct, and make the second no place to write…
Here’s the part of my code, hope someone can give me any suggestion on where the problem might be. Thank you!
**** INIT **************************
unsigned int *texture1, *texture2
pic1 = (unsigned int ) malloc(MAPSIZE * MAPSIZE * 3sizeof(int));
pic2 = (unsigned int ) malloc(MAPSIZE * MAPSIZE * 3sizeof(int));
********* create first texture object ***************
glGenTextures(1, &texture[0]);
// define textures
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, MAPSIZE, MAPSIZE, 0, GL_RGB, GL_UNSIGNED_INT, pic1);
CREATE SECOND TEXTURE OBJECT
glGenTextures(1, &texture[1]);
printf("to here1
");
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, MAPSIZE, MAPSIZE, 0, GL_RGB, GL_UNSIGNED_INT, pic2);
Create snapshots (in another function)
glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawScene();
glPopMatrix();
glBindTexture(GL_TEXTURE_2D, texture[0]);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, MAPSIZE, MAPSIZE, 0);
glPushMatrix();
//do something ***
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawScene();
glPopMatrix();
glBindTexture(GL_TEXTURE_2D, texture[1]);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, MAPSIZE, MAPSIZE, 0);