Skip to main content
gamedev.net
🔒 Locked

alpha texture

Started by GREENie 1 reply 450+ views
Original Post
GREENie
GREENie
I have been trying to get alpha texture to work how i want all night. I have a bad headache from it as well. The problem is i load a tga(with alpha channel) it will only work as expected when I disable depth test and enable blending. i then enable depth test and disable blending so other stuff will work properly. Then it seemed that the alpha texture would always appear behind everything else. All the examples for alpha channels working they just enable blending. This can't be the right way can it? Here is what i do when i render my rgba textured objects.

glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_BLEND);	
glDisable(GL_DEPTH_TEST);

glBindTexture(GL_TEXTURE_2D, m_textureObject[1]);

glBegin(GL_QUADS);
    glTexCoord2f(1,1);glVertex3f(1.0, 1.0, 0.0);
    glTexCoord2f(1,0);glVertex3f(1.0, -1.0, 0.0);
    glTexCoord2f(0,0);glVertex3f(-1.0, -1.0, 0.0);
    glTexCoord2f(0,1);glVertex3f(-1.0, 1.0, 0.0);
glEnd();
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);


egit. Put code as a tag instead of source ><
zedz
zedz
always have depth_test enabled
glDepthMask(GL_TRUE ); also
perhaps change to
glColor4f(1,1,1,1);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);


if that doesnt work
perhaps try glDepthMask( GL_FALSE ); (stopid idea but still)

GREENie
GREENie
thank zedz.
That makes the depth work as i would expect. Though i still have trouble when a alpha textured quad moves over a normal textured quad. What happens is the alpha quad will have a black background instead of transparency and not sure what is behind it. I suspect that this is because the alpha texture is down before the other and is grabbing an empty background. It will be annoying if i have to sort what gets drawn first and last by z location.(Though i suppose that is what use to happen.)

Edit
I tested reversing the order. It looks like the order in which you create objects is important. I think doing all alpha objects last should be safe. Just a pain as currently an object is an object. There is no easy way too sort by type of texture used.
If anyone knows of any other way that would be great.

[Edited by - GREENie on May 22, 2009 4:27:05 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.