简体   繁体   中英

Android OpenGL ES 1 - Polygon Edge

I am drawing a an arrow in using opengl es 1.0. I drew the arrow using a rectangle as the shaft and a pyramid as the tip. When the arrow is rotating from certain angles the shaft can be seen through the edge of the arrow tip.

Image of what is occuring: http://i.imgur.com/9K41OE8.png

My draw method

    public void draw(GL10 gl) {
    gl.glFrontFace(GL10.GL_CW);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);

    gl.glDrawElements(GL10.GL_TRIANGLES, indexBuffer.capacity(), GL10.GL_UNSIGNED_BYTE, indexBuffer);

    gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);  

}

I think it may have something to do with culling, but why would it only occur at the edge of the tip?

Depth testing must be enabled for this to look right. Use this:

gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthMask(GL10.GL_TRUE);

And then don't forget to clear the bits before drawing a frame:

gl.glClear(GL10.GL_DEPTH_BUFFER_BIT | GL10.GL_COLOR_BUFFER_BIT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM