View Full Version : different textures on both faces of a rectangle.
07-22-2011, 06:25 AM
I have to flip a rectangle so that the backside texture will come front.
I want to know how to assign a new texture for the back side of a rectangle.
Please show me the way.
Note: I am using Triangle Strip for drawing the rectangles.
07-22-2011, 09:10 AM
One way would be to draw the rectangle twice. First time bind the front texture and cull backfaces. Then, bind the back texture, reverse your polygon winding and draw with front faces culled.
Alternatively, choose 3 vertices of the rectangle and use a determinant to see if the rectangle is front or back facing. Bind the front texture if it is front facing or the back texture if it isn't. Be sure to glDisable(GL_CULL_FACE) if you're using this method.
The Little Body
07-22-2011, 02:56 PM
You can limit the texture swapping by using the same texture for the recto and the verso parts
(cf. use differents texture coordinates for the same vertex position on the recto and verso opposites faces)
Texture states changes have a relatively hight GPU cost, so minimizing them can have a big impact on the performance
(cf. using a texture atlas is better that using a lot of very littles textures and hundreds of glBindTexture() calls ...)
I don't know (for the instant) if two opposites rectangles can be represented by a single triangle strip :(
=> but it's certainly possible :)
(I see at http://en.wikipedia.org/wiki/Triangle_strip "However, if a strip has odd number of vertices then the reversed strip will represent triangles with opposite orientation. For example, reversal of a strip ABCDE will result in strip EDCBA which represents triangles EDC, DBC, CBA)." that seem confirm it ... so, I think that we have only to concatenate the verso strip in the reverse order that we have used for the recto strip for to have only one "big" strip that handle the two faces)
The Little Body
07-22-2011, 09:55 PM
I think to have found the needed triangle strip order to apply for to generate the backface and the frontface part of each independant triangle/quad strip :)
For two quads 1234 and 3456 that share an edge 34, we can generate a quad strip of 123456
So, for to handle the two faces on a two sided quad 1234, a "[sur]degenerated" strip of 123412 can to be generate instead
(only replace 5 by 1 and 6 by 2 because 1/5 are shared and 2/6 too)
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.