以虚线方式在线框图中绘制隐藏线。

3
我正在尝试在线框图中将所有隐藏的线条(或线条的部分)绘制为虚线(即点划线)。经过一番研究,我发现这应该可以通过多次渲染来实现。
以下是我目前的进展。
// -- 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();

我附上了在我正在处理的一个特定案例上运行此代码时出现的情况。
1个回答

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接