# 2 sided textured polygon

## Recommended Posts

Hey guys, I have a question regarding texturing both side of a polygon (OpenGL). Firsty I am guessing I need to use glMultiTexCoord2fARB GL_TEXTURE0_ARB & GL_TEXTURE1_ARB, to be able to assign 2 textures. Just a little unsure how to assign the co-ordinates here I guess And can I turn off BackFace culling per polygon, ie.. between glBegin/End. Just to explain, assume I have a polygon (square of 2 triangles) to be used for a playing card. I need the reverse texture of the card, AND the regular playing card for the face .. king, queen, ace etc... Of course lets say the card is face down, and I turn it over ( and culling is on) I wont see the other side of the card. All cards will be loaded at runtime, to prevent continuous disk access during game. And at random times, all cards may flip magically at once, which would be a delay in loading all textures at once. Hence loaded at runtime, which is acceptable for any game, to have a loading delay. So any ideas on how to 'double side' textures, and advice on the culling would be great. ** EDIT ** I am thinking of maybe building a cube now, all be it actually a rectangle and a very small thickness (0.1f) say, to give the card some actual depth and texture. Then 1 texture for back face, one for front, and plain white for the other sides (edges). This would solve the culling problem, and might enhance the look of the actual card. I read though, it's a bad idea to keep binding textures during the glBegin/End. So now what would be the best solution for applying 3 different texures to a cube ?? ** ** ** Thanks guys ;-) [Edited by - darren_mfuk on March 5, 2007 12:06:01 PM]

##### Share on other sites
I think an easier solution would be to only bind the texture that you can see. You'll never see both sides of the card at once, so why bother drawing the other side? Determine which side of the card is facing you, either front or back, then bind the correct texture. If it's as simple as turning over cards, then a flag for face-up or face-down will tell you which texture you want. If, however, you have fancy animations with cards rotating in no particularly ordered fashion, a dot product between the camera's direction and the card's normal will tell you which direction the card is facing.

Rendering a *barely* rectangular prism isn't a good idea, thanks to z-fighting. There are ways to work around this, but the easiest is to not even have that second polygon.

As far as taking the thickness of the card into account, just translate the card in the thickness direction by some amount; rendering it isn't necessary, and may actually make the card look worse.

##### Share on other sites
Hi Jouley,

As you guess yes, the cards will be animated.

ie.. as you pick or select a card etc.. it will rotate over.

As far as my other idea, I now have a cube, (or rectangle of thin thickness)
so if the back is textured it will be culled anyway now.

It just seemed easier, and less effort to calculate angle of cards and rotations and so forth.

Plus at points if I flip ALL the cards at once (possibly a couple of decks)
it would be a lot of calculations to go through every single card.

Since the actuall poly count will be so low anyway, even with a couple of decks, I'm not worried about texturing both sides at once.

And I think using a cube, for a 3D card effect would be cool for later in the game (giant jumbo cards, and shadow effects.
So I think I shall actually stick with the 3D card now instead of a flat polygon.

I just wonder how to texutre each face differently, I read somewhere it was bad practice to keep binding texture.

Cheers ;-)

##### Share on other sites
Quote:
 Original post by darren_mfukI just wonder how to texutre each face differently, I read somewhere it was bad practice to keep binding texture.

Texture binding is indeed a huge performance hit, which is why I suggested a method of using only one texture. To use more than one, however, I'll assume you have some sort of DrawCard( ) method going. The most straightforward (and easiest) method of having another texture would be something like this:
void DrawCard( ){  glEnable(GL_TEXTURE_2D);  //  front face  glBindTexture(GL_TEXTURE_2D, frontTexture);  glBegin(GL_TRIANGLES);    //  pass the normal, texture coords, and verts  glEnd( );  //  back face  glBindTexture(GL_TEXTURE_2D, backTexture);  glBegin(GL_TRIANGLES);    //  pass the normal, texture coords, and verts  glEnd( );  glDisable(GL_TEXTURE_2D);  //  to have plain white color on the sides  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);  glBegin(GL_TRIANGLES);    // etc., no texture coords, though, for each of the 4 remaining sides  glEnd( );}

As you can see, there's an enable, disable, two bindings, and at least 3 pairs of begin/ends. All that is going to take a toll, while a cross and dot product (you'll need the cross anyway, for the normal!), one binding, and one begin/end wouldn't cause nearly the strain on the grahpics. A note on the plain white sides -- you'll have to either disable textures completely, or bind a plain white texture, either of which will take more time than doing nothing. [smile]

For such a simple example, performance may be a moot point, but the one texture/one quad approach would make a difference with LOTS of cards or a more complex scene.

If you're interested in trying it out and need some insight into cross or dot products, let me know. Otherwise, the above is a basic outline for getting multiple textures on your card.

-jouley

##### Share on other sites
You don’t need edges for your cards. Just take your four corners and draw two tris facing one way for the front, and two tris facing the other way for the back. It shouldn’t matter that they are coplanar.

##### Share on other sites
Hi Jouley & yckx,

I'll give you an update later, and post a screenshot ;-)

I've got a busy day today 'woohoo job hunting' !!!

Off topic I know, but I moved to the USA from England 7 months ago, and my 'Green Card' has only just been approved, so been unable to work.

But 'YAY' I've just got it, so I'm running off to recruitment agencies today, but thanks again for your replies.

##### Share on other sites
Quote:
 Original post by darren_mfukOff topic I know, but I moved to the USA from England 7 months ago, and my 'Green Card' has only just been approved, so been unable to work.

Heh. I lived in Plymouth as a toddler. My father was a U.S. Marine stationed with the British marines there, mostly doing cold-weather training in Norway. Always wanted to go back and visit sometime.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628391
• Total Posts
2982419

• 10
• 9
• 19
• 24
• 11