Skip to main content
GameDev.net gamedev.net
🔒 Locked

texture problem

Started by Dannyli Aug 17, 2013 at 8:19 PM 4 replies 2k views
Original Post
Dannyli
Dannyli

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?

GeneralQuery
GeneralQuery
We have no idea what any of these methods do so the first port of call would be to list them.
_WeirdCat_
_WeirdCat_

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

BornToCode
BornToCode

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.

Dannyli
Dannyli

can I use the function: glPushAttrib(); and glPopAttrib();?

Dave Hunt
Dave Hunt

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.