Alpha messed up...

Started by
3 comments, last by Kalidor 19 years, 2 months ago
Hello, i have been working on getting png to render in opengl, i have it working pretty much fine, just one problem the images alpha doesnt seem to be render corrctly, i think it just needs to be inverted but im not sure, how would i got about inverting a gltextures alpha channle? or im using SDL_image to load the file, so if i can do it before i convert it to a texture that would work 2, right? and iv check the .png files and they are fine Heres a picture http://img.photobucket.com/albums/v227/shadow66/Alpha_messedup.jpg any ideas? thanks in advanced.
Advertisement
How are you setting up your blend function?
umm
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_BLEND);
umm
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_BLEND);
Okay, you're positive that the alpha for the background is 0.0? That's what it should be for completely transparent. It looks like it is 1.0 or at least high enough so that the scaled source and destination color values (scaled by src alpha and 1 respectively) saturates to white. Anyway, to invert the alpha used in blending just use GL_ONE_MINUS_SRC_ALPHA instead of GL_SRC_ALPHA.

For changing alpha before you create the texture, you just write a simple for loop over all the image data modifying the alpha values, in your case to 1.0-currentAlpha to invert it. I'm not sure how SDL_image works, never used it before, but I'm assuming it would give you access to the array of image data.

One more thing, it's usually a good idea to turn on alpha testing set to pass with an alpha greater than zero as well because for "most" blending uses an alpha of zero will have no affect on the rendered image anyway, so it's better to make that fail the alpha test so the fragment can die much earlier in the pipe.

EDIT: Spelling and readability

This topic is closed to new replies.

Advertisement