Sign in to follow this  
xaviergxf

Texturing two sides

Recommended Posts

Hello everyone, I would like to know if there´s a way to put two differents textures in polygon. I´m trying to do a cards game, and i´d like to put one texture in the front face of the GL_QUADS and another texture in the back face of the polygon.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can do it with one texture. Just put the two pictures next to each other in the texture file ( [front][back] ) and when you set the UV coords scale from 0.0 thru 0.5 on one side, and 0.5 thru 1.0 on the other (for the width coord only, I think its the U value but I dont recall exactly right now).

Share this post


Link to post
Share on other sites
Two-sided geometry is funky, because while lighting supports two-sided calculation (on most modern cards), texturing does not. However, you CAN write shaders that offset the UV based on the front-facing-ness of the polygon; use gl_FrontFacing in the fragment program / pixel shader for this. I wouldn't recommend it, though -- it's much easier to just emit the geometry twice, with two separate windings, and map each polygon copy with a different texture.

Share this post


Link to post
Share on other sites
I´ve tryed to put the other image on the side of the front face image, however it hasn´t worked. The texture repeat exactly the same image on the two sides of the polygon. Can you exemplify a simple code to me?


thanks everyone

Share this post


Link to post
Share on other sites
The easiest way I can think of to do 2-sided texturing would be to use two quads, in exactly the same position, one with the rear texture and one with the face texture. Make they have opposite winding (ie Clockwise and Anti-Clockwise) then turn on backface culling. That way you won't you have any Z-fighting and whichever card is facing away from the camera won't get shown until you turn it over.

If i've missed something I apologise.

Share this post


Link to post
Share on other sites
I´ve already thought about that idea, but i thought that maybe the opengl had some other way more elegant for solving this problem. Well, if there no other choice i will do this way with to polygons one above the other.


Thanks for the tip.

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