Jump to content
  • Advertisement
Sign in to follow this  
CrashStar

blending problem

This topic is 4688 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. Im making my first game in opengl and I have a problem... I have sprite of a ship, which is acctually TGA with alpha channel. Alpha channel works fine, everything is ok, but not only part of tga which should be invisible IS invisible, i mean transparent, but part which should be visible is partially invisible. Not much, but enough to see starfield trough starship rofl... Pls help m8s, what can be the problem?

Share this post


Link to post
Share on other sites
Advertisement
Maybe the quad (or whatever) you're texturing is itself translucent. If so, glColor4f(1, 1, 1, 1) before rendering your sprites may fix the problem.

[edit]As an afterthought - are you sure that you are actually seeing stars through the ship, or is it possible that the stars are being drawn in front of the ship? That would be a different kind of problem.[/edit]

Share this post


Link to post
Share on other sites
http://filebuffer.net/?id=ef1fc7581a9c4_problem.zip
Here is the problem.


Its not depth, when i disable blending, stars are drawn behind the ship.

Ur solution didnt help me. :(

Share this post


Link to post
Share on other sites
Hi,
What blendfunc are you using?
Do you have depthtest enabled?
Could you maybe post the relevant parts of your render function?

Regards,
ViLiO

Share this post


Link to post
Share on other sites

glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glBlendFunc(GL_SRC_ALPHA,GL_ONE);

glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations




Im still new to opengl, so its probably some stupid mistake, so forgive me. :)

Share this post


Link to post
Share on other sites
Ok, I can see from your code that you possibly are using lesson 8 as the basis for blending. However, with alpha blended objects you really need to sort and render back to front. To get around this need for sorting in this early lesson, additive blending is used. This will work fine for the stars but when you have the ship above them it will be blended with the stars and the fragments will be added together thus making a brighter spot where the star and the ship overlap.

So, when drawing the ship you should change the blendfunc to gl_src_alpha, gl_one_minus_src_alpha.

The ship should also be drawn after the stars.

If you have any more questions, just ask [smile]

Regards,
ViLiO

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!