Sign in to follow this  
Dannyli

texture problem

Recommended Posts

Dannyli    135

I use the following code to generate two textures:

ter=Loadtexture("terrain.bmp",ter);
	cross=Loadtexture("cross.bmp",cross);

but all the objects in the scence are bind with texture 

cross=Loadtexture("cross.bmp",cross);

can someone tell me why?

Share this post


Link to post
Share on other sites
WiredCat    1452

its because the last loaded texture is binded

 

if you want to use a different texture for different faces you must bind it to the face like:

 

glBindTexture(GL_TEXTURE_2D,ter); but i dont know if ter is unsigned int or something else so i just guess

the you draw something

then you change texture

glBindTexture(GL_TEXTURE_2D,anothertex);

and you draw something

Share this post


Link to post
Share on other sites
BornToCode    1185

If every object is getting drawned with the second texture. It means that your load texture function is binding the resource been loaded. If you want to draw using the first texture then you need to bind that one.

Share this post


Link to post
Share on other sites
Dave Hunt    4872

Yes, but that is really not their intended use. You should always bind the texture you want to draw with before drawing. You can never be sure what other pieces of code (particularly anything living in a library you didn't write) might be doing behind your back.

 

The best practice is to always explicitly set whatever states/attributes you need when drawing. That way you aren't caught by surprise when some black box function does something without telling you.

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