How do I get OpenGL to display multiple textures in a scene? When I use glTexImage2D, OpenGL places that texture on every polygon. The only way I found to fix this is call glTexImage2D for every frame, but that’s impractical cause its a big performance hit. I’m using OpenGL Win32 on Win2k. I don’t have my OpenGL book with me . Thanks.
You create all your textures using glTexImage2d, using a different ID for each of them. (Use glGenTextures, to get an ID.) You then just use glBindTexture with the ID of the texture you want to use.
Where do I, and how many times do I call glBindTexture? Do I call it for every frame? I currently am calling it before glTexImage in my Polygon class’ constructor. Then I call it right before I draw the polygon. This is producing a nasty effect when drawing the polygon One of the textures shows up but then there is garbage on the others. Thank you for the reply and help.
Bind…draw…bind…draw… and so on.
Define “nasty effect” and “garbage.”
Are the dimensions of all your textures a power of 2? (1,2,4,8,16,32,64,128, etc.)
Generally, I would suggest you sort your polygons so that you only have to bind each texture once each frame.
Sorry, my program is a simple 3d cube rotating on all 3 axis and the corresponding texture displays correctly for which ever side of the cube is facing the camera. But the rest of the sides are scrambled with nothing resembling their appropiate texture. This problem occured after I started calling glGenTextures and glBindTextures so that must mean I’m not using them correctly. I’m missing something basic here lol. Thanks again.
Forgot to mention that yes they are 256x256 and 64x64 They’re Unreal textures that I got from UnrealEd to practice with
Problem solved. Ok, you need to call glBindTexture once before the call to glTexImage. Then, what I wasn’t doing, is that you need to make the following function calls:
When I wasn’t doing this it was creating that garbage look. I never realized that these settings needed to be set for every texture. Thanks for the help everyone.