🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

blending problem

Started by
5 comments, last by CrashStar 18 years, 7 months ago
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?
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]
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. :(
Hi,
What blendfunc are you using?
Do you have depthtest enabled?
Could you maybe post the relevant parts of your render function?

Regards,
ViLiO
Richard 'ViLiO' Thomasv.net | Twitter | YouTube

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. :)
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
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
thx m8 that solved it :)


thx once again ;)

This topic is closed to new replies.

Advertisement