noob question: Mixing texture objects and calls to glTexImage

I’m trying to display a cube shaped room that is staticly textured, so I use a texture object, and in the forground I have a quad displaying video. I want to load the static texture using a texture object, and load the video frames into another texture that I can update on the foreground quad.

The rendering code is something like this:

glClear(…)
glPushMatrix()
glRotate(…)

glBindTexture(GL_TEXTURE_2D, integer_for_texture_object);

glCallList(integer_to_cube_display_list);

glPopMatrix

// then, to render the animated-texture quad,
// I do
glPushMatrix();
glLoadIdentity();

glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, pointer_to_current_frame_rgb_data);

glCallList(integer_to_foreground_quad);

glPopMatrix();

What ends up happening is that the cube walls also get rendered with the frames of my animation - I never see my original texture stored in the texture object.

If I remove the call to glTexImage2D(), then everything gets textured with the texture object, which is what I expect.

What am I missing?

glTexImage2D affects the currently bound texture object. Create a 2nd texture object that you update for the animated one. Also, you could probably get better performance if you initially do a glTexImage2D of the size you need, then use glTexSubImage2D to do your updates.

As I’ve since found out. I now use texture objects for each frame, and only delete and re-create the texture object when a frame changes.

Not only does this work, but it gave me a 10x improvement in framerate (31 -> 300). Thanks!