Replace stencil buffer with z-buffer to draw outline of selected items
This commit is contained in:
parent
8c49d33731
commit
0569ca17bf
@ -113,7 +113,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
log.debug("Setting up GL capabilities...");
|
log.debug("Setting up GL capabilities...");
|
||||||
|
|
||||||
log.verbose("GL - Getting Default Profile");
|
log.verbose("GL - Getting Default Profile");
|
||||||
GLProfile glp = GLProfile.getDefault();
|
GLProfile glp = GLProfile.get(GLProfile.GL2);
|
||||||
|
|
||||||
log.verbose("GL - creating GLCapabilities");
|
log.verbose("GL - creating GLCapabilities");
|
||||||
GLCapabilities caps = new GLCapabilities(glp);
|
GLCapabilities caps = new GLCapabilities(glp);
|
||||||
@ -124,9 +124,6 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
log.verbose("GL - setNumSamples");
|
log.verbose("GL - setNumSamples");
|
||||||
caps.setNumSamples(6);
|
caps.setNumSamples(6);
|
||||||
|
|
||||||
log.verbose("GL - setStencilBits");
|
|
||||||
caps.setStencilBits(1);
|
|
||||||
|
|
||||||
log.verbose("GL - Creating Canvas");
|
log.verbose("GL - Creating Canvas");
|
||||||
canvas = new GLCanvas(caps);
|
canvas = new GLCanvas(caps);
|
||||||
|
|
||||||
@ -139,7 +136,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
log.verbose("GL - Setting up mouse listeners");
|
log.verbose("GL - Setting up mouse listeners");
|
||||||
setupMouseListeners();
|
setupMouseListeners();
|
||||||
|
|
||||||
log.verbose("GL - Rasterizine Carets"); //reticulating splines?
|
log.verbose("GL - Rasterizing Carets");
|
||||||
rasterizeCarets();
|
rasterizeCarets();
|
||||||
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
@ -567,7 +564,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
glu.gluProject(c.x, c.y, c.z, mvmatrix, 0, projmatrix, 0, viewport, 0,
|
glu.gluProject(c.x, c.y, c.z, mvmatrix, 0, projmatrix, 0, viewport, 0,
|
||||||
out, 0);
|
out, 0);
|
||||||
|
|
||||||
log.verbose("GL - peoject() complete");
|
log.verbose("GL - project() complete");
|
||||||
return new Coordinate(out[0], out[1], out[2]);
|
return new Coordinate(out[0], out[1], out[2]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,35 @@ public class RocketRenderer {
|
|||||||
|
|
||||||
gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing
|
gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing
|
||||||
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
|
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
|
||||||
|
{ //Draw selection outline at nearest Z
|
||||||
|
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION,
|
||||||
|
selectedEmissive, 0);
|
||||||
|
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_DIFFUSE, colorBlack, 0);
|
||||||
|
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_AMBIENT, colorBlack, 0);
|
||||||
|
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0);
|
||||||
|
gl.glLineWidth(5.0f);
|
||||||
|
|
||||||
|
for (RocketComponent c : selection) {
|
||||||
|
//Draw as lines, set Z to nearest
|
||||||
|
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
|
||||||
|
gl.glDepthRange(0, 0);
|
||||||
|
cr.renderGeometry(gl, c);
|
||||||
|
|
||||||
|
//Draw polygons, always passing depth test,
|
||||||
|
//setting Z to farthest
|
||||||
|
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
|
||||||
|
gl.glDepthRange(1, 1);
|
||||||
|
gl.glDepthFunc(GL.GL_ALWAYS);
|
||||||
|
cr.renderGeometry(gl, c);
|
||||||
|
gl.glDepthFunc(GL.GL_LESS);
|
||||||
|
gl.glDepthRange(0, 1);
|
||||||
|
}
|
||||||
|
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
|
||||||
|
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION,
|
||||||
|
colorBlack, 0);
|
||||||
|
} //done with selection outline
|
||||||
|
|
||||||
// Draw all inner components
|
// Draw all inner components
|
||||||
for (RocketComponent c : configuration) {
|
for (RocketComponent c : configuration) {
|
||||||
@ -158,50 +187,6 @@ public class RocketRenderer {
|
|||||||
}
|
}
|
||||||
gl.glDisable(GL.GL_BLEND);
|
gl.glDisable(GL.GL_BLEND);
|
||||||
gl.glDisable(GL.GL_CULL_FACE);
|
gl.glDisable(GL.GL_CULL_FACE);
|
||||||
|
|
||||||
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION,
|
|
||||||
selectedEmissive, 0);
|
|
||||||
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_DIFFUSE, colorBlack, 0);
|
|
||||||
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_AMBIENT, colorBlack, 0);
|
|
||||||
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0);
|
|
||||||
|
|
||||||
gl.glDepthMask(false);
|
|
||||||
gl.glDisable(GL.GL_DEPTH_TEST);
|
|
||||||
gl.glEnable(GL.GL_STENCIL_TEST);
|
|
||||||
|
|
||||||
for (RocketComponent c : configuration) {
|
|
||||||
if (selection.contains(c)) {
|
|
||||||
// So it is faster to do this once before the loop,
|
|
||||||
// but then the outlines are not as good if you multi-select.
|
|
||||||
// Not sure which to do.
|
|
||||||
|
|
||||||
gl.glStencilMask(1);
|
|
||||||
gl.glDisable(GL.GL_SCISSOR_TEST);
|
|
||||||
gl.glClearStencil(0);
|
|
||||||
gl.glClear(GL.GL_STENCIL_BUFFER_BIT);
|
|
||||||
gl.glStencilMask(0);
|
|
||||||
|
|
||||||
gl.glStencilFunc(GL.GL_ALWAYS, 1, 1);
|
|
||||||
gl.glStencilMask(1);
|
|
||||||
gl.glColorMask(false, false, false, false);
|
|
||||||
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
|
|
||||||
gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_REPLACE);
|
|
||||||
cr.renderGeometry(gl, c);
|
|
||||||
gl.glStencilMask(0);
|
|
||||||
|
|
||||||
gl.glColorMask(true, true, true, true);
|
|
||||||
gl.glStencilFunc(GL.GL_NOTEQUAL, 1, 1);
|
|
||||||
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
|
|
||||||
gl.glLineWidth(5.0f);
|
|
||||||
cr.renderGeometry(gl, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
|
|
||||||
gl.glDepthMask(true);
|
|
||||||
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION,
|
|
||||||
colorBlack, 0);
|
|
||||||
gl.glDisable(GL.GL_STENCIL_TEST);
|
|
||||||
gl.glEnable(GL.GL_DEPTH_TEST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderMotors(GL2 gl, Configuration configuration) {
|
private void renderMotors(GL2 gl, Configuration configuration) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user