Draw hidden lines as indicated in the wireframe

I am trying to draw all hidden lines (or portions of lines) as dashed (i.e. outlined) in a wireframe drawing. After a bit of research, it makes sense that this should be feasible by taking multiple render passes.

Here's what I have so far.

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

      

I have added what happens when I run this on a particular case that I am working on.

+3


source to share


1 answer


You should draw the finish line last with depth buffer enabled, but vice versa and read only



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

      

+4


source







All Articles