Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Transparency

31 views
Skip to first unread message

Jonathan Akers

unread,
Jul 22, 1999, 3:00:00 AM7/22/99
to
Hello,
In my game that I'm currently developing I draw images using
glDrawPixels with a pointer to an RGB structure that holds the picture
information. I'm using 24 bit .bmp's and loading them into a 3 byte RGB
struct. How can I tell openGL not to draw the black pixels in my
picture so that it can be translucent? If anybody can help, please
e-mail me, I will read it faster then, if not then just write it here
and I'll keep checking. Thanks in advance.
Sincerely,
Jonathan Akers

Frans Bouma

unread,
Jul 23, 1999, 3:00:00 AM7/23/99
to

Jonathan Akers <jona...@mailhost.chi.ameritech.net> wrote in message
news:3797F1A4...@mailhost.chi.ameritech.net...

// enable blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_COLOR); // the blacker the more transparent

AFther this, render the picture with transparancy. This is a statechange, so
first render all pictures without blending (disable it) and then render all
transparent pictures.

you should consider using textured polygons in an Orthogonal projection, because
these are MUCH faster than glDrawPixels.

FB

Paul Martz

unread,
Jul 23, 1999, 3:00:00 AM7/23/99
to
Frans Bouma wrote in message <7n93hd$beb$1...@news1.xs4all.nl>...

>Jonathan Akers <jona...@mailhost.chi.ameritech.net> wrote in message
>news:3797F1A4...@mailhost.chi.ameritech.net...
>> In my game that I'm currently developing I draw images using
>> glDrawPixels with a pointer to an RGB structure that holds the picture
>> information. I'm using 24 bit .bmp's and loading them into a 3 byte RGB
>> struct. How can I tell openGL not to draw the black pixels in my
>> picture so that it can be translucent?
>
> // enable blending
> glEnable(GL_BLEND);
> glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_COLOR); // the blacker the more
transparent


This will not work. His draw pixels data is RGB; therefore src alpha will be
constant across the pixel array.

To solve this problem, you will need to copy your 24bit data into a 32 bpp
array. As you copy each pixel, if it is black store 0x0 for the 4th byte. If
it is not black, store 0xff for the 4th byte. You will call glDrawPixels
with this new array, specifying GL_RGBA instead of GL_RGB. But before you
call glDrawPixels, enable alpha test as so:
glEnable (GL_ALPHA_TEST);
glAlphaFunc (GL_NOTEQUAL, 0.0);
This tells OpenGL to only draw the pixels which have alpha not equal to 0.
Since your black pixels all have alpha of 0, they will not render. Call
"glDisable (GL_ALPHA_TEST)" to turn alpha testing back off.

> first render all pictures without blending (disable it) and then render
all
> transparent pictures.

Using alpha test is better than blending in this situation because you don't
need to change the order of your rendering to use it, like you do with
bending.

-Paul Martz
Hewlett Packard Workstation Systems Lab
To reply, remove "DONTSPAM" from email address.

Frans Bouma

unread,
Jul 23, 1999, 3:00:00 AM7/23/99
to
Paul Martz <ma...@DONTSPAMgplmail.fc.hp.com> wrote in message news:7n9upb$e3j$1...@fcnews.fc.hp.com...

> Frans Bouma wrote in message <7n93hd$beb$1...@news1.xs4all.nl>...
> >Jonathan Akers <jona...@mailhost.chi.ameritech.net> wrote in message
> >news:3797F1A4...@mailhost.chi.ameritech.net...
> >> In my game that I'm currently developing I draw images using
> >> glDrawPixels with a pointer to an RGB structure that holds the picture
> >> information. I'm using 24 bit .bmp's and loading them into a 3 byte RGB
> >> struct. How can I tell openGL not to draw the black pixels in my
> >> picture so that it can be translucent?
> >
> > // enable blending
> > glEnable(GL_BLEND);
> > glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_COLOR); // the blacker the more
> transparent
>
> This will not work. His draw pixels data is RGB; therefore src alpha will be
> constant across the pixel array.

oopss. yes you are right.

> To solve this problem, you will need to copy your 24bit data into a 32 bpp
> array. As you copy each pixel, if it is black store 0x0 for the 4th byte. If
> it is not black, store 0xff for the 4th byte. You will call glDrawPixels
> with this new array, specifying GL_RGBA instead of GL_RGB. But before you
> call glDrawPixels, enable alpha test as so:
> glEnable (GL_ALPHA_TEST);
> glAlphaFunc (GL_NOTEQUAL, 0.0);
> This tells OpenGL to only draw the pixels which have alpha not equal to 0.
> Since your black pixels all have alpha of 0, they will not render. Call
> "glDisable (GL_ALPHA_TEST)" to turn alpha testing back off.

this wil cause 'jagged edges'. If you copy the 24bit data in a 32bit
array and store just an alpha value with the pixel, AND use the blend
method I mentioned above it WILL work, plus pixels with ALMOST black edges
(like antialiased pixels in the picture) will give a bit less transparancy
so they will blend nicely. It's not what the alphabyte's value is. it's
about that there is one. I blend/render all my lensflares this way and they
blend nicely with the background as they're supposed to do. The flares are
textures with a black background that will be transparent. I just move in
a 0xFF as alpha and use the function above.

> > first render all pictures without blending (disable it) and then render
> all
> > transparent pictures.
>
> Using alpha test is better than blending in this situation because you don't
> need to change the order of your rendering to use it, like you do with
> bending.

that's true but you won't have anti-aliassing that is already IN the
picture, if you use the alphatest option. (like you have with transparent
gifs on webpages, same prob, well you know :))If the picture doesn't have
jagged edges caused by for example a light object that is blended with the
black background in the sourcepicture (in photoshop for example) then the
alphatest method is ok.

FB


Paul Martz

unread,
Jul 23, 1999, 3:00:00 AM7/23/99
to

Frans Bouma wrote in message <7na3fj$b4h$1...@news1.xs4all.nl>...

>Paul Martz <ma...@DONTSPAMgplmail.fc.hp.com> wrote in message
news:7n9upb$e3j$1...@fcnews.fc.hp.com...
>> Frans Bouma wrote in message <7n93hd$beb$1...@news1.xs4all.nl>...
>> >Jonathan Akers <jona...@mailhost.chi.ameritech.net> wrote in message
>> >news:3797F1A4...@mailhost.chi.ameritech.net...
>> >> struct. How can I tell openGL not to draw the black pixels in my
>> >> picture so that it can be translucent?
>
>> To solve this problem, you will need to copy your 24bit data into a 32
bpp
>> array. As you copy each pixel, if it is black store 0x0 for the 4th byte.
If
>> it is not black, store 0xff for the 4th byte. You will call glDrawPixels
>> with this new array, specifying GL_RGBA instead of GL_RGB. But before you
>> call glDrawPixels, enable alpha test as so:
>> glEnable (GL_ALPHA_TEST);
>> glAlphaFunc (GL_NOTEQUAL, 0.0);
>
> this wil cause 'jagged edges'. If you copy the 24bit data in a 32bit
> array and store just an alpha value with the pixel, AND use the blend
> method I mentioned above it WILL work, plus pixels with ALMOST black
edges
> (like antialiased pixels in the picture) will give a bit less
transparancy
> so they will blend nicely.

I agree completely with what you have said.

However, see the original post: he really did say he wants to make only the
black pixels not render. He didn't say he wants the near-black pixels to
partially render. If skipping the black pixels is what's desired, alpha test
is the better solution.

Frans Bouma

unread,
Jul 23, 1999, 3:00:00 AM7/23/99
to

Paul Martz <ma...@DONTSPAMgplmail.fc.hp.com> wrote in message news:7na52s$gbd$1...@fcnews.fc.hp.com...

> However, see the original post: he really did say he wants to make only the
> black pixels not render. He didn't say he wants the near-black pixels to
> partially render. If skipping the black pixels is what's desired, alpha test
> is the better solution.

correct. The alphatest is faster then. (if you consider 'fast' a criterium when you
use glDrawPixels ;P)

FB

Jonathan Akers

unread,
Jul 23, 1999, 3:00:00 AM7/23/99
to
Hey guys thanks a ton this is really going to help. Yes only full black
I don't want rendering, Don't want to get too complicated :)
Thanks a lot.
Jonathan

Jonathan Akers

unread,
Jul 28, 1999, 3:00:00 AM7/28/99
to
Hello,
I've got transparency to work in my game so that full back 0,0,0
isn't drawn at all, and it is shown through. How could I make it so
that near black is partially transparent? Also how would I make it so
that lets say I am making a HUD in a game, for like telling you your
score and lives and health, lets say the HUD is red, how would I make
parts of it transparent? Thank you very much in advance for the help.
Sincerely,
Jonathan Akers

Mahesh Venkitachalam

unread,
Jul 28, 1999, 3:00:00 AM7/28/99
to
Jonathan Akers wrote:

Checking out the Blending section at
http://home.att.net/~bighesh/ogl.html

Mahesh Venkitachalam

0 new messages