// 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
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.
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
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.
correct. The alphatest is faster then. (if you consider 'fast' a criterium when you
use glDrawPixels ;P)
FB
Checking out the Blending section at
http://home.att.net/~bighesh/ogl.html
Mahesh Venkitachalam