Jump to content
  • Advertisement
Sign in to follow this  
Specchum

OpenGL Alpha Blending issues

This topic is 4672 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 having a difficult time getting alpha blending to work in my openGL program! I have a 32 bit TGA file with an alpha channel. I've set the alpha mask to black as specified in NEHE tutorials. And then while rendering I'm setting the alpha test values to: glEnable(GL_GREATER, 0); glEnable(GL_ALPHA_TEST); //render mesh etc However, curiously, I'm getting a bright pink/magenta colour where my alpha should be and the whole thing just doesn't look right! If I use GL_LESS and a value of 128, the pink colour vanishes but so does part of my image (unsurprisingly). Any idea why I should be getting a magenta alpha?! What could I be doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
I think you've got some things a little mixed up here.
Alpha testing is a way of drawing parts of a texture that are over (or under) a certain limit, specified by you the developer.
You set it with: glAlphaFunc(<Testing function>, <reference value>);
And enable it with: glEnable(GL_ALPHA_TEST);

Blending is a totally different issue. You may want to look at glBlendFunc().
As for the code examples, where on earth did you get glEnable(GL_GREATER, 0) from?

Share this post


Link to post
Share on other sites
Quote:
Original post by StiNKy
I think you've got some things a little mixed up here.
Alpha testing is a way of drawing parts of a texture that are over (or under) a certain limit, specified by you the developer.
You set it with: glAlphaFunc(<Testing function>, <reference value>);
And enable it with: glEnable(GL_ALPHA_TEST);


Oeeer! I've been trying both now and seem to have got my terms thoroughly mixed up. :)

IAC, nither seems to work! If I use the Blend function via glBlendFunc I just get the aforementioned pink/magenta alpha. Interestingly, if I modify the material alpha the whole texture blends (including the magenta alpha). Now I've disabled the material but I still can't seem to get rid of the magenta stuff! Also should I be disabling light for proper blending?

I then tried Alpha Testing. The problem is that the magenta stuff disappears if I test for GL_LESS for 128 but then some bits of the non-alpha texture disappear too.

Quote:

As for the code examples, where on earth did you get glEnable(GL_GREATER, 0) from?


heh heh.. I mean glAlphaFunc(GL_GREATER,0). I shoulds really copy-paste code more often! ;)

Share this post


Link to post
Share on other sites
Okay, let me modify my question a bit.

I have a texture of a tree which I need to slap on a 2d sprite since I'm making a billboarded tree. Now, by all accounts, it's a simple case of taking a 32 bit TGA image with alpha and setting the blend states in openGL to:

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


However, I'm not getting the desired results. I'm getting a pink/magenta colour where the alpha is!

Please note that my 2d sprite does not have a material (is this reqd?) and I have lights enabled. With no light, I don't get a coloured image at all (just grayscale with alpha full black).

What could I be doing wrong?

Share this post


Link to post
Share on other sites
Did you check the glTexImage* () function ?, you should set the internal format and format to GL_RGBA value and type to GL_UNSIGNED_BYTE.

Packing may also be another possible issue. You may try glPixelStorei (GL_PACK_ALIGNMENT, 4) ; (other values are possible, but this should be the most efficient).

Share this post


Link to post
Share on other sites
Yeah, I'm setting the values to glTexImage function correctly. the glPixelStorei doesn't seem to have any effect on the result in my case!

Share this post


Link to post
Share on other sites
May you post your texture creation code ?.

And what happens if you take another TGA files ? The ones with alpha values == 1 or with different bit depth (16 bit, 24 bit) ?.

Are you sure your image loading routine is correct ?.

Share this post


Link to post
Share on other sites
That pink/magenta colour is used by artists quite a bit to indicate transparent areas when using paletted textures.According to this site TGA files can use a palette. I'd check your source image, it probably doesn't have a proper alpha channel. You could check the pixel value when loading your image and manually set the alpha to 0.

Share this post


Link to post
Share on other sites
Okay, now it's getting really weird! I just checked the exported tga file and it appears that most of my diffuse colour is shifted towards magenta! Or to put it in another way, wherever I'd defined my alpha mask, the colours seem to be magenta-ised (??!) .

I can only deduce that I'm creating the image improperly in Photoshop or there is an issue in PS that I'm unaware of. Any ideas anyone?

Share this post


Link to post
Share on other sites
Okay, now it's getting really weird! I just checked the exported tga file and it appears that most of my diffuse colour is shifted towards magenta! Or to put it in another way, wherever I'd defined my alpha mask, the colours seem to be magenta-ised (??!) .

I can only deduce that I'm creating the image improperly in Photoshop or there is an issue in PS that I'm unaware of. Any ideas anyone?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!