View Full Version : Multiple textures
03-02-2001, 08:44 AM
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 http://www.opengl.org/discussion_boards/ubb/frown.gif. Thanks.
03-02-2001, 12:58 PM
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.
03-04-2001, 09:05 AM
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 http://www.opengl.org/discussion_boards/ubb/frown.gif One of the textures shows up but then there is garbage on the others. Thank you for the reply and help.
03-04-2001, 09:44 AM
Bind...draw...bind...draw... and so on.
03-04-2001, 03:15 PM
Define "nasty effect" and "garbage." http://www.opengl.org/discussion_boards/ubb/smile.gif
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.
03-04-2001, 04:38 PM
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.
03-04-2001, 04:40 PM
Forgot to mention that yes they are 256x256 and 64x64 http://www.opengl.org/discussion_boards/ubb/smile.gif They're Unreal textures that I got from UnrealEd to practice with http://www.opengl.org/discussion_boards/ubb/smile.gif
03-04-2001, 08:16 PM
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:
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
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.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.