Advertisement

Blending question

Started by February 25, 2003 04:22 AM
14 comments, last by BigBoy 22 years ago
I have a image (foreground) I want to place over another image (background) so that any foreground black pixels are transparent and anything else is placed as is over the top of the background. However, it seems like no matter what blend function I use, the black is transparent but the colours are so bright they are almost white. I should note that at the moment the background image is RGB, not RGBA, while the foreground image is RGBA. The alpha value of the foreground image''s black pixels is 0, while the foregropund image''s other colours have an alpha value of 255. What blending function should I use? Or should I be looking at alpha testing? Cheers, Jeroen
Cheers,Jeroen
This is a very convenient situation to use alpha masking. Simply glEnable(GL_ALPHA_TEST) and set glAlphaFunc(GL_GREATER, 0). You can play around with different alpha values by changing the second argument. In your case this code should suffice. Remember to glDisable(GL_ALPHA_TEST) after you''re done though!

Hope this helps,
Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Advertisement
quote:
Original post by Crispy
This is a very convenient situation to use alpha masking. Simply glEnable(GL_ALPHA_TEST) and set glAlphaFunc(GL_GREATER, 0). You can play around with different alpha values by changing the second argument. In your case this code should suffice. Remember to glDisable(GL_ALPHA_TEST) after you''re done though!

Hope this helps,
Crispy


I tried this, but still get the image appearing in a black box (same as the image background colour). I''ve also tried NEhe''s fonts from tutorial 32, and the same thing happens.

Now, I''ve had a bit of a ponder about it this morning on the way to work and I think I should note that I use a glColour3f to set the colour of the image. I''m guessing OGL automatically assigns an alpha of 1 to the image because of this. I''ll try out using glColour4f with an alpha of 0 tonight when I get home and see if it makes a difference.

The day will now drag by sooooo slowly. Oh for student days...

Cheers,
Jeroen
Cheers,Jeroen
Did you disable blending? Also, only alphatest the foreground image. Additionally, always make sure your alpha channel is built correctly.

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
quote:
Original post by Crispy
Did you disable blending? Also, only alphatest the foreground image. Additionally, always make sure your alpha channel is built correctly.

Crispy


Yep, all blending is turned off and only the foreground image is alpha tested. I''m using GIMP (windows version) and use the colour picker to get the details of the colour. The tool lists the alpha value as 0 for black and #FF for all others. I assume this is what you mean with the alpha channel being correctly built.

However, as I said previously, I need to check out the glColour4f option.

Thanks for all your suggestions so far though.

Jeroen
Cheers,Jeroen
ok, then try:

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

this will only dispalay pixels with an alpha value above 128

if this doesn''t work it''s a problem with your texture loader.

| - Project-X - my mega project.. yup, still cracking along - | - adDeath - an ad blocker I made - | - email me - |
Advertisement
quote:
Original post by RipTorn
ok, then try:

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

this will only dispalay pixels with an alpha value above 128

if this doesn''t work it''s a problem with your texture loader.




I''ll try this, but I''m at the point of not worrying about the background image anymore - it''s more of a nice to have than a neccessity for the game.

Chances are I''m doing something wrong, not initialising settings correctly or something along those lines. The source code will be released soon, after which anyone mad enough to peruse it may be able to point out where I''ve gone astray.

Cheers,
Jeroen
quote:
Original post by RipTorn
ok, then try:

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

this will only dispalay pixels with an alpha value above 128

if this doesn''t work it''s a problem with your texture loader.




I''ll try this, but I''m at the point of not worrying about the background image anymore - it''s more of a nice to have than a neccessity for the game.

Chances are I''m doing something wrong, not initialising settings correctly or something along those lines. The source code will be released soon, after which anyone mad enough to peruse it may be able to point out where I''ve gone astray.

Cheers,
Jeroen
Cheers,Jeroen
This doesn''t need anykindofspecial initialization. Post some relevant code. Maybe the problem is very straightfroward.

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
quote:
Original post by Crispy
This doesn''t need anykindofspecial initialization. Post some relevant code. Maybe the problem is very straightfroward.

Crispy


Thanks. I''ll try out RipTorn''s suggestion first, and if that fails I''ll post the snippets of code.

Cheers,
Jeroen



Cheers,Jeroen

This topic is closed to new replies.

Advertisement