Archived

This topic is now archived and is closed to further replies.

Coconut Crab

Is there a way to have different textures on a cube?

Recommended Posts

Hi, I''ve read Nehe''s tutorial on texture mapping, and it uses 1 texture for all 6 faces of the cube. My question is, can you give each face a different texture? I''m asking this question because in the tutorial it says you CANNOT have glBindTexture() inside glBegin() and glEnd(), and since all 6 faces have to be created inside the same glBegin() and glEnd(), how can you speicify a different texture for a face then? If I use a different matrix for each face, would that work smoothly? Or is there an easier way to do it? Thanks for any kind replies. Coco

Share this post


Link to post
Share on other sites
well, easy enough, you just draw one sqaure at a time with a different texture on each square. you''ll end up with six seperate glBegin and glEnd statements.

My Homepage

Share this post


Link to post
Share on other sites
Basically you declare an unsigned int array for the textures, call BindTextures to select one, set all of its mipmapping and other stuff and load the data, then set Bind to the next one and repeat, Bind to the next one and repeat etc etc

Then while you''re drawing, call BindTexture to "select" the "current" texture.

Let me know if you have more questions after checking my program. If you don''t have Visual C++, just check the Initialize() routine in main.cpp and you''ll see how to do it.

Good luck

Share this post


Link to post
Share on other sites
Hey thanks, Julio. I just visited your website: you are cool!

By the way, what does this sign, ^ , mean in A^? The other formula is pretty cool! 1 less variable to declare ^^.

Coco

Share this post


Link to post
Share on other sites
the ^is the binary exclusive-or-operator and a ^= b is the same as a = a^b

here''s an example
a = 10, converted to a binary number that''s 01010
b = 22 = 10110

01010 ^
10110 =
11100 (=28)

the result for each bit is a 1 if ONE, AND ONLY ONE of the corresponding bits of a and b is 1, otherwise it''s 0

hope this helps u

simon

Share this post


Link to post
Share on other sites