android - How do I draw a wireframe mesh with hidden lines removed in OpenGL ES? -
the cube want draw:
the above cube pretty easy created in opengl function glpolygonmode(gl_front_and_back, gl_line)
, known opengl es not include function want use. in word, don't want draw cube this:
i thank people provide help.
========================least update picture============================
the edge little thinner front edge. there have solution solve problem?
current code:
gles20.glenable(gles20.gl_depth_test); gles20.gldisable(gles20.gl_polygon_offset_fill); // draw edge gles20.gldrawelements(gles20.gl_lines, lineindices.length, gles20.gl_unsigned_short, lineindexbuffer); gles20.glenable(gles20.gl_polygon_offset_fill); gles20.glpolygonoffset(1.0f, 1.0f); // apply background color , draw faces gles20.gluniform4fv(mcolorhandle, 1, facecolor, 0); gles20.gldrawelements(gles20.gl_triangles, triangleindices.length, gles20.gl_unsigned_short, triangleindexbuffer);
here standard trick (assumes depth buffer enabled):
- draw mesh edges (lines)
- fill mesh polygons background color (to cover hidden lines)
since mesh edges , mesh faces have same z-values meet need solve z-fighting problem. simplest way use polygon offset edges "hover" "above" polygon faces:
gl.disable(gl.polygon_offset_fill) /* draw polygon edges */ gl.enable(gl.polygon_offset_fill); gl.polygonoffset(1.0, 1.0); /* fill polygons in background color */
here wireframe wineglass illustrates z-fighting problem:
here solved z-fighting problem using polygon offset:
Comments
Post a Comment