Skip to main content
gamedev.net
🔒 Locked

transparent

Started by BloodLust666 Sep 15, 2006 at 3:13 PM 16 replies 1.7k views
Original Post
BloodLust666
BloodLust666
i'm having some trouble again with my transparency... my sprites are being rendered with depth test and depth mask on and blending turned on with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); as the blending function. BUT, in places where my texture has alpha of 0, it doesn't show the sprite behind it, it shows black, as if the color is black with alpha of 255. what's wrong?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Zao
Zao
Are you drawing your sprites in the correct order?

Also, I believe that the correct term is transcluency, not transparency. A transparent object is invisible =)
To make it is hell. To fail is divine.
BloodLust666
BloodLust666
the objects don't need to be drawn in order, that's what the depth test is. and when i say transparent, i mean part of my sprite is transparent (alpha 0) and a lot is opaque (alpha 255), the part that's 0 is not showing the sprite behind it, it's showing up black
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
ScottC
ScottC
When you load it, are you loading it as GL_RGBA?

Also, try rendering it with the depth mask disabled.
TrueTom
TrueTom
With alphablending the drawing order DOES matter...

Have you set the correct vertex color before the texture draw eg. glColor(255,255,255) ?
mrMagnetic
mrMagnetic
sounds like you need alpha testing, not blending:

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

note that with blending enabled, you might have blurry edges where the draw order *does* matter, even with alpha values of only 0 and 255. i think openGL does this to make it look smoother.
---Current pet project: ProjectM
BloodLust666
BloodLust666
well that fixed it, is there a way to disable the "smooth" thing? because it's like I see a fine line of black pixels at the edge of my texture that has the alpha test
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
if i can't do that, how ELSE am i supposed to get sprites to look correctly?? i need blending, i obviously need alpha testing, and i need depth testing and mask.
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Lord_Evil
Lord_Evil
Try moving your texture coordinates slightly towards the initerior of your texture (i.e. 0.001 instead of 0.0 and 0.999 instead of 1.0). Due to sampling inaccuracies there might be a "seam" at the border when using exact coordinates.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
BloodLust666
BloodLust666
i'll try moving it a texel in towards the center
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Kalidor
Kalidor
Quote:
Original post by EvilKnuckles666
well that fixed it, is there a way to disable the "smooth" thing? because it's like I see a fine line of black pixels at the edge of my texture that has the alpha test
That "smooth thing" is called (bi)linear texture filtering. You disable it by using GL_NEAREST for the minification and magnification filtering modes instead of GL_LINEAR. The reason you get a black color at the edge of your texture is because the transparent pixels in the image are black, so when the texture is filtered you get some mix of (0,0,0,0) and your opaque color.

One way to "fix" this while still being able to use linear filtering is to simply use a different color for the transparent pixels that more closely match the pixels at the border of opaque->transparent. This will still have some artifacts where the colors don't match perfectly but it is much less noticeable and may be adequate for your purposes. The correct way is to extrude the colors at that border into the transparent pixels.
BloodLust666
BloodLust666
sweet, everything looks great now thanks :) is that a lot slower though because i can't really tell but it just kinda looks and feels little.. jittery
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Kalidor
Kalidor
Quote:
Original post by EvilKnuckles666
sweet, everything looks great now thanks :) is that a lot slower though because i can't really tell but it just kinda looks and feels little.. jittery
Which method are you using? Using nearest filtering should be slightly faster than linear filtering, although it will most likely be unnoticeable. The other two methods will have no run-time cost at all, they should be done at load-time or even before... it's possible to do it at content-creation-time (ie: have the artists make the images with the proper background or colors extruded already, then you won't need to do anything different at load-time).
mrMagnetic
mrMagnetic
You can also try different values for glAlphaFunc, using a higher value reduces the blurry border.
---Current pet project: ProjectM
Daivuk
Daivuk
the Alpha channel has nothing to do with the RGB channels, if you are (for example) attempting drawing vegetation, bush. The textures should look like all green, with bush detail in the middle.
The alpha channel will do the visibility job.
You DONT have to put a unique RGB color for the transparent color (like purple, green or black).
With opengl, Use RGBA texture (Anyway in the VRAM they will be RGBA)
Lord_Evil
Lord_Evil
You don't have to use a key color if your texture format allows for an alpha channel. But if you are using 24 bit textures for example, which don't provide an alpha channel, key coloring is your tool of choice. Just replace the key color with a 0-alpha color at load time.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Sir Sapo
Sir Sapo
glpng is a nice library that will load and bind .PNG's to textures pretty easily, I would recommend them over using a color key.
My Current Project Angels 22 (4E5)
Kalidor
Kalidor
I just wanted to clarify that in my posts I did not mean to imply using a color key when I talked about the color of transparent pixels. What I meant was simply the RGB components of RGBA pixels where alpha=0. My second suggestion, if done at load-time, could be thought of as the reverse of color-keying. The pixels are already transparent and you're just setting the RGB values to a certain color to minimize the linear interpolation artifacts.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.