Hi, I'm trying to create billboarded trees for an assignment and part of this is using textures with an alpha channel. I've created the billboard effect and textured the trees but for soem reason only objects drawn before the tree are visisble through the transparent sections.
Does any one know why that might happen?
Here's a picture of the effect:
As you can see the tree in the background isnt visible though the closer tree, although the track, floor, skydome etc are visible through it.
Here's my draw method for my tree:
glPushMatrix();
if(Texture() != -1){
Textures::ApplyTexture(Texture());
glEnable(GL_TEXTURE_2D);
}
CylindricalBillboard::billboardBegin();
GraphicObject::Material().apply();
glNormal3f(0,0,1);
glEnable(GL_BLEND);
glBegin(GL_TRIANGLE_STRIP);
for(float i = 0.0f; i <= 4; i++){
glTexCoord2d(0.0, i/4); glVertex3f(0.0f, i, 0.0f);
glTexCoord2d(1.0, i/4); glVertex3f(2.0f, i, 0.0f);
}
glEnd();
glDisable(GL_BLEND);
if(Texture() != -1){
glDisable(GL_TEXTURE_2D);
}
CylindricalBillboard::billboardEnd();
glPopMatrix();
My textures class contains methods for generating my textures from images and then the apply method (which is called from my tree class)
void Textures::GenerateTextures()
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// load images
_images[0].Load("trackpiece.bmp");
_images[1].Load("tree.tga");
//lots more textures edited out
glGenTextures(15, &_textures[0]);
}
void Textures::ApplyTexture(int texture){
glBindTexture(GL_TEXTURE_2D, _textures[texture]);
_images[texture].gluBuild2DMipmaps();
_images[texture].Free();
}
Any help would be much appreciated. This is my first time using OpenGL so I'm not very good at it.
Thanks in advance!