I’m creating a small tank-game (renderer is >1300 lines of code) and at present working on the weapons in the game. The work on weapons has become very annoying as I’m noticing unexpected stuff on the screen (flickering on the screen or complete black screen) whenever I set gl_PointSize.
How does this happen and how to remove this (OpenGL ES 2.0 vendor: Imagination Technologies, Device: Motorola Milestone, OS: Android 2.3.3). Could z-fighting be an issue?
Adjusting setLookAtM does not effect anything, the only way to remove strange effects is by removing gl_PointSize.
[UPDATE]
May be gl_PointSize is not the problem; there is a tank, a room, and a light in the game, and the moment a call to glDrawArrays is made for the weapons, the screen flickers or turns completely black for sometime (until I touch and rotate the tank) given that the weapon is well inside the frustum.
Matrix.setLookAtM(GLES20Renderer._ViewMatrix, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0);
Matrix.frustumM(GLES20Renderer._ProjectionMatrix, 0, -ratio, ratio, -1, 1, 0.75f, 10);
float[] pointVFA = {
3.0f,3.0f,3.0f,
-3.0f,3.0f,3.0f,
-3.0f,-3.0f,3.0f
};
ByteBuffer pointVBB = ByteBuffer.allocateDirect(pointVFA.length * 4);
pointVBB.order(ByteOrder.nativeOrder());
GLES20Renderer._pointVFBMissile = pointVBB.asFloatBuffer();
GLES20Renderer._pointVFBMissile.put(pointVFA);
GLES20Renderer._pointVFBMissile.position(0);
private static final String _vertexShaderCodeMissiles =
"attribute vec4 aPosition; \n"
+ "void main() { \n"
+ " gl_PointSize = 15.0; \n"
+ " gl_Position = aPosition; \n"
+ "} \n";
private static final String _fragmentShaderCodeMissiles =
"#ifdef GL_FRAGMENT_PRECISION_HIGH \n"
+ "precision highp float; \n"
+ "#else \n"
+ "precision mediump float; \n"
+ "#endif \n"
+ "void main() { \n"
+ " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); \n"
+ "} \n";
Having tried all the ways to remove the black empty/flickering screen, (after 2 weeks of agitation) the issue is finally solved and is a new lesson for me.
It seems that in OpenGL ES 2.0 we cannot mix buffer objects (vbo or ibo) with nio buffers. Either the code should mostly use buffer objects or just nio.
This is the erroneous code:
and this is the correct code: