I’ve got an icon which I want to display on a scene, which has a transparent colour. At the moment, I’m trying to display it as a texture. I’ve got an alpha channel in the image data, which is set to 0 for the transparent colour. However, instead of the scene showing through the transparent colour, the polygon it’s drawn onto shows through instead. So if I texture the image onto a white polygon, the transparent colour goes white and the scene is still hidden. If I set the polygon to transparent, it just disappears totally, and doesn’t use the alpha values of the texture. I’ve tried playing around with blend options, but can’t get the right one. Is there any solution to this, or do I have to use the masking idea from NeHe’s tutorial 20, which seems inefficient?
I have also tried displaying the image it using glDrawPixels instead of using a texture, and I can get it to do the transparency fine, but the origin of the image (it’s a plain old square) is in the bottom left and I need it in the centre and can’t work out how to do this, so if anyone has a solution to that problem instead, I’d be happy to hear that too (especially since this solution would actually be better for me).
glAlphaFunc() and glEnable(GL_ALPHA_TEST) and the correct glTexEnv() mode should take care of that.
From what you’re describing you’re using alpha blending only and the polygon’s material alpha is used instead of the texture’s.
Thanks for your reply. I was trying to use blending rather than alpha test, although I tried both. I actually got it working now, I needed GL_MODULATE rather than GL_DECAL. I had tried this before, but I hadn’t set the colour for my undelying rectangle, so got strange results as it was picking a random colour up, and not always the same one. I just needed to make it an opaque, white square. I got it through trial and error, and was shocked when I it actually worked at last!
If anyone knows any solution to my other question, whether it’s possible to change the origin of an image drawn using glDrawPixels, please let me know!
Heya, Sarah. AFAIK, there’s no way to change the “image origin” when using glDrawPixels–you’d have to do the math yourself by using the screen’s dimensions and the dimensions of your image.
However, the typical way of drawing any such image is using a screen-aligned texture as you’ve done. One good reason is that if you have to redraw the image every frame, glDrawPixels actually sends the whole image to the video card every frame–this is slow!
However, if you’re using textures, then you load the image into OGL once and then reuse it every frame. Under the hood, OGL sends the image to the video card only when necessary and reuses it across multiple frames–possibly once during the lifetime of your application. =)
BTW, you probably already knew this, but the texture’s color you were seeing wasn’t exactly “random”, but rather the color of the last thing you draw before drawing the texture =P.
Cheers, I didn’t know which solution was quicker, so I’ll stick with textures even though it generates other problems for me (as I don’t want the image to scale when the rest of the scene does, this seemed easier to do by glDrawPixels but that might have been luck rather than skill). I think I’ve solved most of them though!
> BTW, you probably already knew this, but the texture’s color you were seeing wasn’t exactly “random”, but rather the color of the last thing you draw before drawing the texture
I did, but thanks for the extra info.
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.