我试图在线框图中以虚线(即斑点)绘制所有隐藏线(或线条的部分)。经过一些研究后,通过渲染几次传递就可以实现这一点。
这是我到目前为止所拥有的。
// -- preamble stuff --
gl.glClearColor(1.f, 1.f, 1.f, 1.f);
gl.glShadeModel(GL.GL_SMOOTH);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glLineWidth(2);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// -- render hidden lines with stipple set, color mask enabled, depth buffer disabled --
gl.glDisable(GL_DEPTH_TEST);
gl.glColorMask(true, true, true, true);
gl.glLineStipple(1, (short) 0x00FF);
gl.glEnable(GL_LINE_STIPPLE);
gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
renderGLDisplayLists(); // -- does the rendering
// -- render in fill mode with color mask disabled, depth buffer enabled --
gl.glEnable(GL_DEPTH_TEST);
gl.glColorMask(false, false, false, false);
gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
renderGLDisplayLists();
// -- final pass to render visible lines --
gl.glColorMask(true, true, true, true);
gl.glEnable(GL_LINE);
gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
renderGLDisplayLists();
我已经了解了当我在我正在处理的特定情况下运行时会发生什么。
答案 0 :(得分:4)
您应该在最后启用深度缓冲区的情况下绘制点画线,但颠倒和只读
//just drew the fills
gl.glDepthMask(false);
lg.glDepthFunc(gl.GL_GREATER);//reverses the depth buffer
//render
gl.glColorMask(true, true, true, true);
gl.glLineStipple(1, (short) 0x00FF);
gl.glEnable(GL_LINE_STIPPLE);
gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
renderGLDisplayLists(); // -- does the rendering
gl.glDepthMask(true);
lg.glDepthFunc(gl.GL_LESS);//restores the depth buffer