PDA

View Full Version : Transparent Textures



02-03-2005, 10:58 PM
I'm having some troubles with transparent textures.

What I want to do is to get a transparent texture in front of a background.

My code looks like this:

....draw the background...

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

glTexImage2D(GL_TEXTURE_2D,0,4,64, 64,0,GL_RGBA,GL_UNSIGNED_BYTE,image->imageData);

// draw transparent texture
glBegin(GL_QUADS);
...Vertex and textrue Coordinates
glEnd();

My texture image is a circle.

Everything is working fine except that I can see the Quad where the texture image is transparent. In other words I see the circle but it is surrounded by the quad.

Is it possible to only show the transparent image(circle) on top of the background?

Any help would be greatly appreciated.

dvm
02-03-2005, 11:07 PM
From the code snippet, on first look, it looks you're on a good path. Have you checked your image though? It's not as easy. I know, I've spent quite some time trying to figure this out. You need a program like Photoshop or Gimp, to create the image. You need to add an alpha channel to it. There are plenty of tutorials that describe how you do that. Remember it has to be in a format that supports transparency, I don't think you can do it with .bmp.

02-03-2005, 11:51 PM
Thanks for replying.

I don't think there is anything wrong with the image. I've added an alpha channel to it. Every point on the circle has a value of 255 while every point not on the circle has a value 0.

My problem is that I get a circle inside a quad(the quad used to specify texture coordinates). I only want to show the circle and not the quad.

The texture image seems transparent. If I change the color of the quad, the color around the circle changes.

Is there a way to get the quad invisible but still show the texture used on that quad.

CWiC
02-04-2005, 06:40 AM
Actually you don't need to draw the circle in texture - create circle only in alpha channel and you'll see for sure whether alpha blending work for you or not.

02-04-2005, 08:06 AM
Try: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

Might work.