PDA

View Full Version : Pasting two transparent textures together?



07-08-2002, 09:16 AM
Hi,

I try to make a small game. I want to have a
object to be presented in a virtual world. The object is represented by 2 rectangles that are pasted together (they have same x and y positions, and differ in z only slightly). The one should be textured with front texture, the otherone with backtexture (to have 2 different views when looking from front or back).

I am using Textures with Alpha Channel, to show only relevant pixels and make the others transparent (the two textures fit to each other, so a "right" picture should be generated)

But when I use the pasted code, the two rectangles are always at the same position.. i may change the z-translation (or z-position of the vertex) by any rate, nothing happens... the two textures always are at exactly the same position (and so the effect I want to have is not visible)...

what is wrong with my code?

Tnx!, Greets Heiko

glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);

// save actual matrix
glPushMatrix();

glTranslatef(_locationx+_sizex/2,_locationy+_sizey,_locationz+_sizez/2);
glScalef(_sizex,_sizey,_sizez);


// bind texture
_texture_object->BindTexture(_tx_front);
//front
glBegin(GL_POLYGON);
glNormal3d(0.0f,0.0f,1.0f);

glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0,-1.0,1.0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(1.0,-1.0,1.0);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.0,1.0,1.0);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0,1.0,1.0);
glEnd();


glTranslatef(0.0,0.0,-1.0);
// bind texture
_texture_object->BindTexture(_tx_back);
//back
glBegin(GL_POLYGON);
glNormal3d(0.0f,0.0f,1.0f);

glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0,-1.0,1.0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(1.0,-1.0,1.0);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.0,1.0,1.0);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0,1.0,1.0);
glEnd();

glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);

// get matrix from stack
glPopMatrix();

07-08-2002, 09:19 AM
There is one error :-)... The normal of the "back-side" should be -1.0 at z-parameter... but actually that does NOT solve my problem... :-)

Hope you find the bug... (i'm sure you will ;-))

DFrey
07-08-2002, 11:40 AM
Sounds like you need to enable backface culling.