LWJGL Forum

Programming => OpenGL => Topic started by: Meanz on August 09, 2011, 07:43:38

Title: Blend issue
Post by: Meanz on August 09, 2011, 07:43:38
(http://img109.imageshack.us/img109/3945/whatz.png)

It is really hard to explain this, but as you can see, there are two different outcomes in the two squares. And I don't understand why :/
I want both to be outcomes to be the same as the green one.

Any hints?


Edit:

There is two quads, both are 1x1
And the  1,0 -> 0,1 quad is drawed first.
Thus shaping an X

I have just enabled GL_BLEND with GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
And I loaded a picture that had some transparent pixels. It was saved using photoshop.
And it's a png
Title: Re: Blend issue
Post by: spasi on August 09, 2011, 08:34:29
You have to disable depth writes while rendering these quads. Try glDepthMask(false);
Title: Re: Blend issue
Post by: Meanz on August 09, 2011, 11:10:39
I tried using glDepthMask(false); (Thanks for that)

I can now see that the quad, which is behind the red square is now rendered on top of the red square, making it look odd.
but also if I render them in the opposite order, I will just get the same problem when viewing my quads from another angle.
(http://img829.imageshack.us/img829/2213/gldepthmask.png)

Could you think of any ways to solve this then :)?
Title: Re: Blend issue
Post by: Mickelukas on August 09, 2011, 11:43:47
If you use blend you'll always need to render back to fourth. If you don't want to spend the time on making the engine do that and you only want to render pixels on or off (no transparency) you can use alpha test instead:
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.9f);
//Draw
GL11.glDisable(GL11.GL_ALPHA_TEST);

Kind regards,
Mike
Title: Re: Blend issue
Post by: Meanz on August 09, 2011, 17:43:10
Thank you mike, the visual outcome is perfect by using alpha testing.

Now I just got to read up on what the pro's and con's are ;p