Yes, but doesn't alpha blending affect the entire texture? I just want to blend out the black portions...
Main Topics
Browse All TopicsI think I'm going insane...
I'm loading bitmaps from a .Theme file. They are 32-bit. But, for some reason, OpenGL draws the transparent portions as black instead of clear. I'm using the BGRA extension, if that helps.
public void LoadTexture(Bitmap name, ref int target)
{
//Debug.WriteLine(file.Pix
using(Bitmap bitmap = new Bitmap(name))
{
bitmap.RotateFlip(RotateFl
Rectangle rectangle = new Rectangle(0, 0, bitmap.Width,
bitmap.Height);
BitmapData bitmapData = bitmap.LockBits(rectangle,
ImageLockMode.ReadOnly, PixelFormat.Format32bppArg
Gl.glGenTextures(1, out target);
Gl.glBindTexture(Gl.GL_TEX
Gl.glTexParameteri(Gl.GL_T
Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
Gl.glTexParameteri(Gl.GL_T
Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
Glu.gluBuild2DMipmaps(Gl.G
bitmapData.Width, bitmapData.Height,
Gl.GL_BGRA_EXT, Gl.GL_UNSIGNED_BYTE,
bitmapData.Scan0);
bitmap.UnlockBits(bitmapDa
}
}
Any ideas why it displays as black?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
the blend function controls how things blend.
SRC + INVSRC is the standard alpha-blending mode. It will use the alpha values of the src pixels to blend, assume other normal texturing settings are in place.
That's separate from the pixel pipeline that grabs the colors in the first place. If you wanted an entire polygon transparent, you'd set the same mode, but then use vertex alphas to apply uniformly to a polygon.
d
you could leave blending for what it is and turn on the alphatest for this .. it will draw the entire texture, except for where the alpha value is lower than a given treshold.
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0);
Will draw all texture samples where the alpha value is greater than 0
This technique is comonly called 'superblack keying'
grtz
e.
Hmmm, I've never heard of 'superblack keying' before. That's an interesting name for it!
Yeah, the problem with alpha-test is that you get hard edges, assuming you have a soft-edged alpha. I'm also nearly sure you still need to enable the blending stuff, as without it alpha is likely ignored (and never gets into the pixel pipeline for evaluation).
However, enki is good to point this out, as for performance reasons, once you are drawing a LOT of alpha'd objects, you'll want alpha-test-zero on, as the alpha test exits pixel processing earlier. Saves rendering time.
d
Business Accounts
Answer for Membership
by: davebytesPosted on 2004-05-09 at 23:09:40ID: 11028735
You need to enable alpha-blending. Plus set the blending modes to something useful, like SRC = ALPHA + DEST = INVSRCALPHA. I think you want something like:
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
If you don't have blending enabled, or have a bad blend mode, alpha will end up blending against black (or white, depending on setup).
d