Jump to content
  • Advertisement
Sign in to follow this  
Samurai-X

OpenGL OpenGL Alpha problem.

This topic is 2072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to render two partially transparent 2D sprites, with the same alpha value, one on top of the other, the transparency is achieved by setting the alpha value in the ColorArray.

My question is this: Is it possible that the intersection area of the two partially transparent objects to have the same initial alpha value? What I have now is something like the sum of both objects alpha value...

Please take a look at the attached image, which I think it describes the problem in a better way.

 

16bipuq.png

 

Your help would be much appreciated.
Thanks.

Share this post


Link to post
Share on other sites
Advertisement

If the two overlapping object have the same alpha, then just write the alpha channel to the frame buffer without any kind of blending at all. The last object you draw already contains exactly the alpha channel you expect as a final result.

Share this post


Link to post
Share on other sites

I am not sure if I did correctly understand what you do mean, but I want to state that those two overlapping objects are rendered to the screen among many other objects, each with it's own alpha. So I guess setting the frame buffer alpha would affect every rendered object(...) Also, disabling blending will affect my 2D textured objects area that is fully transparent, resulting the sprites to be rendered into "black box". Well I hope this makes any sense at all...

 

Could be there any possible solution to such issue? Thank you.

Share this post


Link to post
Share on other sites

You can draw them with depth-testing, so that they never overdraw each other. Draw the one that is supposed to be in front first, then with depth-testing enabled the one that is supposed to be behind it will not be drawn, if it's drawn at an appropriate Z. (For example same Z and a depth-test that is GL_NOTEQUAL).

Share this post


Link to post
Share on other sites

Thanks for the advice, I will do a quick search about the depth-testing, even though the depth thingy has been disabled (that's because the game is purely 2D, which helps avoiding any unecessary hassle) if I recall correctly.

 

Perhaps another solution that doesn't involve depth testing?  :)

Share this post


Link to post
Share on other sites

You can render the sprites without blending like Brother Bob suggests, writing the alpha, and then blend the background in with GL_ONE_MINUS_DST_ALPHA. So instead of blending sprites on top of the background, blend the background on top of the sprites.

Or draw into a separate render-target and then blit the result on top of the background.

 

It's rather difficult to understand exactly the effect you want to achieve. Perhaps you can post a screen-shot of how it looks now with real sprites, and draw an image of how it's supposed to look?

If I understand correctly (each pixel only drawn once) then depth-testing is likely the easiest solution.

Share this post


Link to post
Share on other sites

This is how blending of any object in 3d rendering or the real world works. What are you specifically trying to do? What effect?

Share this post


Link to post
Share on other sites

 What are you specifically trying to do? What effect?

 

Thanks for asking... I've got a big 2D sprite, which is composed with 5 small separate textured 2D sprites, What I need is to create a shadow effect for the whole big sprite by stetting the R,G, and B values of every small sprite composing the big one to 0 (to give it a nice black color) and setting each one's alpha value  to 50% in order to have a nice transparent black shadow effect.... The problem is that the intersection areas of the overlapping sprites look draker than the non-intersection areas.... Here is a small image that would better decribe all of this.

 

2ik8ww3.png

 

My question is, how can I get rid of that issue that's affecting my shadow effect? Is there any other way to achieve a nice shadow effect for 2D sprites without involving alphas (And unecessary 3d effects such lightings and cameras)?

 

Thanks.

Edited by Samurai-X

Share this post


Link to post
Share on other sites

Thank you all for your kind help... I have done some quick research regarding the depth testing and the other solutions that were kindly proposed, and have realised implementing such solutions will make things even more complex. The graphic engine I have written is mainly for rendering 2D sprites, with some 2D capabilities such 2D rotation.... Thus I have opted to look else where and do some research about rendering into texture.

 

I think rendering into texture is the best and simplest way for me to render those shadows, which doesn't need too many alteration to the render engine. The idea is to render all the objects into a texture in runtime with 100% alpha value, then rendering this new texture to the screen, whith the desired 50% value.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!