Sign in to follow this  

blending problem

This topic is 4381 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
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
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

This topic is 4381 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this