Sign in to follow this  
N1ghtDr34m3r

glAlphaFunc in gl20 ? or How do I enable alpha in gl20 ?

Recommended Posts

N1ghtDr34m3r    378
Hey guys.

I'm currently coding a little game with the libGdx library and I wanted to have a slight fade in/fade out effect if the screen changes (e.g. from MainMenu into the game).
After some time, I've got the idea, that I draw a black filled rectangle over the whole screen with an increasing alpha value. At the point where the alpha value is 0.0f (so, the whole screen is black) I change the screen to my game, where at this point my alpha value is getting bigger (so it will be transparent more and more).

So I implemented something like this:

[CODE]
// init
Gdx.gl.glEnable( GL10.GL_ALPHA_TEST );
// [...]
// render
Gdx.gl10.glAlphaFunc( GL10.GL_GREATER, 0 );
// render my quad
[/CODE]

While having my project setting up with LwjglApplicationConfig.useGL20 = false; it will work very well.
But enabling gl20, it won't start, saying that there is a problem with GL10.GL_ALPHA_TEST
So I searched if gl20 have something like that... but now it's 30 minutes later and I don't have any solution.

Could you help?
What I have to enable in gl20 ( and setting up) to use alpha like in gl10 ?

Greets,
N1ghtDr34m3r

Share this post


Link to post
Share on other sites
karwosts    840
The built in alphaFunc is gone in GL20 because you're expected to replicate it in shader with the 'discard' keyword.

Basically at some point in your fragment shader you'll have:

[CODE]

float alphaMin = 0.1;
if(color.a < alphaMin) { discard; }
[/CODE]

This achieves the same effect as alpha testing.

Share this post


Link to post
Share on other sites

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