I'm rendering a libgdx mesh using shader with alpha color less than 1.0.
When rendering the first frame, the alpha value set in shader is being ignored and rendered as 1.0. All following rendering frames are fine.
The same happened to me in previous project drawing lines and shapes using glDrawArrays and I haven't found the solution yet.
Code in libgdx render() loop:
Gdx.gl20.glClearColor(0, 0, 0, 1);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl20.glEnable(GL20.GL_BLEND);
MeshManager_colorFill.meshShader.begin();
MeshManager_colorFill.meshShader.setUniformMatrix("u_worldView", Snappr.camMatrix);
meshArray_colorFill.render(MeshManager_colorFill.meshShader, GL20.GL_TRIANGLE_FAN, 0, meshArray_colorFill.get(i).getNumVertices());
MeshManager_colorFill.meshShader.end();
Gdx.gl20.glDisable(GL20.GL_BLEND);
My shader (compiled in create(){}):
public static final String meshVertexShader_colorFill =
"attribute vec2 a_position; \n" +
"uniform mat4 u_worldView;\n" +
"void main() \n" +
"{ \n" +
" gl_Position = u_worldView * vec4(a_position.xy, 0, 1); \n" +
"} \n" ;
public static final String meshFragmentShader_colorFill =
"precision mediump float;\n" +
"void main() \n" +
"{ \n" +
" gl_FragColor = vec4(1,1,1,0.2);\n" +
"}";
How do I render the very first frame as it should be?
Thanks