I’m following along the book, OpenGL ES 2 for Android : A Quick Start Guide, in Chapter 8, texture rendering.
The codes I followed along were typed according to the book. The texture I used in my program is a custom 128x256 image, while the texture the book used is a 512x1024 image. I figured since both texture image ratios are the same, the textures shouldn’t be causing any issues.
Below is an image of a screenshot I took in Android, concerning the Z fighting.
And here’s the code, mostly the same as in the book.:
{
private static final int POSITION_COMPONENT_COUNT=2;
private static final int TEXTURE_COORDS_COMPONENT_COUNT=2;
private static final int STRIDE=(POSITION_COMPONENT_COUNT+TEXTURE_COORDS_COMPONENT_COUNT)*Constants.BYTES_PER_FLOAT;
private static float[] VERTEX_DATA={
//using a different texture.
0f,0f,0.5f,0.5f,
-0.5f, -0.8f, 0f,0f,
0.5f,-0.8f,1f,0f,
0.5f,0.8f,1f,1f,
-0.5f,0.8f,0f,1f,
-0.5f,-0.8f,0f,0f
};
private final VertexArray vertexArray;
public Table(){
vertexArray=new VertexArray(VERTEX_DATA);
}
public void bind(TextureShaderProgram program){
vertexArray.setVertexAttribPointer(
POSITION_COMPONENT_COUNT,
program.getTextureCoordsAttributeLocation(),
TEXTURE_COORDS_COMPONENT_COUNT,
STRIDE
);
vertexArray.setVertexAttribPointer(
0,
program.getPositionAttributeLocation(),
POSITION_COMPONENT_COUNT,
STRIDE
);
}
public void draw(){
//GLES20.glFrontFace(GLES20.GL_CCW);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN,0,6);
}
}
The problem is in the center of the screenshot, the white link flickers through the blue portion of the texture rapidly. My guess would be that tje triangle fans were drawn incorrectly or something, but I couldn’t think of any other ways of drawing triangle fans that doesn’t work as it is supposed to do.
Any clues?