Quick question – title says it all:
In my OpenGL-code (3.3), I’m using the line
glEnable(GL_ALPHA_TEST);
I’ve been using my code for weeks now and never checked for errors (via glGetError()) because it works perfectly. Now that I did (because something else isn’t working), this line gives me an invalid enum error. Google revealed that glEnable(GL_ALPHA_TEST) seems to be depreciated since OpenGL 3 (core profile?) or so and I guess, that is the reason for the error.
But that part of the code still does exactly what I want. Some more code:
glDisable(GL_CULL_FACE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
// buffer-stuff
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 9, NumParticles);
So, did I put something redundant in there? I’m drawing particles (instanced) on screen using 2 triangles each (to give a quad) and in the alpha-chanel of the particle-color, I’m basically setting a circle (so 1.0f if in the circle, otherwise 0.0f). Depth-testing of course for not drawing particles from the back infront of particles further in front and glBlendFunc() (and as I understood glEnabled(GL_ALPHA_TEST)) for removing the bits not in the circle. I’m still learning OpenGL and am trying to understand, why that code actually works (for once) and why I apparently don’t need glEnable(GL_ALPHA_TEST)…
>Solution :
Yes, I’m using discard in the fragment shader. Otherwise, I just used to code above, so I guess, only one depth value (standard?).
discard is the replacement for glEnable(GL_ALPHA_TEST);.
So, did I put something redundant in there?
Yes discard and glEnable(GL_ALPHA_TEST); would be redundant if you use a profile for which glEnable(GL_ALPHA_TEST); still exists and if you use discard for every fragment with an alpha for which the glAlphaFunc would discard that fragment.
Since you are in a profile for which the glEnable(GL_ALPHA_TEST); does not exist anymore, the glEnable(GL_ALPHA_TEST); has no effect in your code and can be removed.