Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » openGL guru needed, masking problem :S.

This thread is locked; no one can reply to it. rss feed Print
openGL guru needed, masking problem :S.
Albin Engström
Member #8,110
December 2006
avatar

EDIT: the problem was that i had forgotten to enable alpha testing..

Notice that some invisible quad seems to block out the pixels of those behind it?, this invisible quad is the masked area of the bomb which you should also be able to see, for some reason this happens to objects if they are drawn after and behind a masked quad, as you can see the ground is unaffected because it's drawn before the bomb and the player. I use a custom view port and orthographic view, except from that everything is as it usually is when it works :P..

This seems like the kind of problem people know the answer too, so any ideas?

Kisses :-*// A.P.E

gnolam
Member #2,030
March 2002
avatar

Don't ever post screenshots in BMP format.

As for the solution: turn off depth writing.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Albin Engström
Member #8,110
December 2006
avatar

EDIT: woops.. forgot to enable alpha testing....

It was so small it thought it wouldn't matter :P, won't happen again!

Turning off depth testing would pose another problem.. the depth?! :S
(tried it of course, unfortunately no unexpected results :()

But it has to be something about the depth :/

I've used ortho and depth testing before and these problems didn't show up :/.

Arthur Kalliokoski
Member #5,540
February 2005
avatar

As far as I can get it to work, transparency needs depth testing turned off, and you have to draw all the transparent objects after all the others, and you have to sort the transparent objects by distance.

My father used to play with my brother and me in the yard. Mother would come out and say, "You're tearing up the grass"; "We're not raising grass," Dad would reply. "We're raising boys".
Harmon Killebrew

Albin Engström
Member #8,110
December 2006
avatar

You don't have to if you use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); :).

Rash
Member #2,374
May 2002
avatar

BAF
Member #2,981
December 2002
avatar

It's really easy to save as a png. Chances are, you have to paste your screenshot to save it anyway, even mspaint will save to a png quick and easy.

Tobias Dammers
Member #2,604
August 2002
avatar

Haven't bothered looking at the screenshot, but here's the thing.
When you have a masked polygon, you want depth testing anyway, and probably alpha blending as well. If the non-masked areas of the polygon are supposed to be solid, you also want depth writes - but ONLY FOR THE SOLID PIXELS. Which means you need alpha TESTING, not only alpha BLENDING: alpha blending always "writes" the pixel; if its alpha value is zero, it will still write to the depth buffer.
So here's what you want:
Solid polygons: Disable alpha testing and blending. Enable depth test and depth write.
Masked polygons: Enable alpha testing, disable blending. Enable depth test and depth write.
Blended polygons: Disable alpha testing, enable blending. Enable depth test, disable depth write.

You may want to enable alpha blending on masked polygons; this will give you smoother edges where a masked pixel and a non-masked one are next to each other, but because the alpha test can only ever result in "accept" or "reject", the depth testing that happens afterwards will lead to slightly incorrect results (halfway masked pixels obscuring solid pixels from other polygons). So I'd suggest you turn off blending for these, and let the graphic driver's scene anti-aliasing handle this for you.

Go to: