Sign in to follow this  
keikei_c

loading multiple textures

Recommended Posts

i'm currently working with lesson 10 at Nehe..texture mapping. I'd like to do something about it, however, i really dont know exactly how. In the tut, the program only loaded 1 texture for all areas (ceiling, floor, etc..)..is it possible to load different texture for every space? can anyone kindly teach me how to manipulate the code? it has something about sectors and stuff..please?

Share this post


Link to post
Share on other sites
you use the bind function to choose which texture is being used in your drawing code:

glBindTexture(GL_TEXTURE_2D, texture_1);
...draw something...

glBindTexture(GL_TEXTURE_2D, texture_2);
...draw something else...



if you go back to lesson 6, where it teaches you how to load a texture, you can use that code to load multiple textures, then use the code I posted above to change which one you are drawing with.

eg.in your initialisation code:

int texture_1, texture_2;

glGenTextures(1, &texture_1);
glGenTextures(1, &texture_2);

glBindTexture(GL_TEXTURE_2D, texture_1);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);


glBindTexture(GL_TEXTURE_2D, texture_2);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data);


or if you store your texture ID's in an array:

int textures[2];

glGenTextures(2, textures);

glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexImage2D(GL_TEXTURE_2D, ...);


glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexImage2D(GL_TEXTURE_2D, ...);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this