Archived

This topic is now archived and is closed to further replies.

Can't get transparency, please help

This topic is 5379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to get all black (0,0,0) pixels on a texture to not be drawn. So I tried what''s used in OpenGL Game Programming, chapter 15, to draw the cacti:
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0);
 
When I render the quad, the black parts are still black. What am I doing wrong? My textures black is 0,0,0 like the cacti texture. Is there something I''m forgetting? Other blending like the blended cube demo from NeHe works. Is there another way of doing this? Any help is greatly appreciated. Thank you!

Share this post


Link to post
Share on other sites
Okay, I tried the NeHe code from Lesson 09, Moving Bitmaps in 3D space:


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


The black isn''t drawn, but the non-black (the sprite) is blended instead of being drawn solidly.

Can someone please tell me how (with depth testing enabled) draw a quad in space with the BLACK pixels of the texture not drawn and everything else drawn opaquely?

As always... thanks beforehand!

Share this post


Link to post
Share on other sites
OK, I tried


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

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5);


and got some weird results... strips of the image are completely transparent, everything else blends.

ergh >< thanks though!

Share this post


Link to post
Share on other sites
Could you explain to me what you mean? =( Sorry I''m a beginner at this stuff. If what I''m doing here is incorrect... what is the correct way? My apologies for being so noobish, but...

Thanks!

Share this post


Link to post
Share on other sites
Well, basically, each pixel in a bitmap has 3 values: R, G, B.
Values that range from 0 to 255 each.
What you want to do is this:
in your texture loading code, have a line that calculates the alpha:

alpha=(r+g+b)/3;

Anyway, if you have VERY little experience with OpenGL, I can post here the function I wrote, for this very purpose.
Let em know if you need it.

Height Map Editor | Eternal Lands | Fast User Directory

Share this post


Link to post
Share on other sites
If you don''t calculate an alpha channel as above, then try:

glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);

which uses the colour values directly (less memory, but less flexible - probably only really useful if your mask colour is either black or white).

Share this post


Link to post
Share on other sites
OrangyTang: Tried that... the entire texture (non-black pixels) turns black. =/ Thanks though.

Raduprv: I''m using auxDIBImageLoad to load bitmaps. So I don''t manipulate the color channels directly. Should I write my own function to load bitmaps?

Thank you both for your help! Hopefully I can get this figured out. =)

Share this post


Link to post
Share on other sites
Okay! I got it working by using my own (well, I didn''t write it from scratch) bitmap loading function.

Thanks everybody =D

Share this post


Link to post
Share on other sites
You should really use .tga or .png or someother file format that supports alpha channel in the texture. I personally use .tga files for textures and can save the alpha channel with it.

Share this post


Link to post
Share on other sites