我正在尝试在线框图中以虚线(即点画)绘制所有隐藏线(或线的部分)。经过一些研究,可以通过在渲染过程中进行多次遍历来实现这一点。

到目前为止,这就是我所拥有的。

// -- 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();

我已附上在我正在处理的特定案例上执行此操作时发生的情况。

最佳答案

您应该在启用深度缓冲但最后反转且只读的情况下最后绘制点画线

//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

09-04 11:37