1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
// 1. Configure clip plane and turn-it ON
// -------------------------------------------------------------------------------
double[] eqn = new double[4] { 0.0, 0.0, -1.0, this.clipPlaneDepth };
Gl.glClipPlane(Gl.GL_CLIP_PLANE0, eqn);
Gl.glPushAttrib(Gl.GL_ENABLE_BIT);
Gl.glEnable(Gl.GL_CLIP_PLANE0);
Gl.glPushMatrix();
Gl.glRotatef(-90.0f, .0f, 1.0f, .0f);
Gl.glCullFace(Gl.GL_BACK);
Gl.glEnable(GL_CULL_FACE);
//>>>>>>> Draw object's outside (we are culling back faces)<<<<<<<<<<<<<
// 2. Cull front face and turn Stencil-Test ON
// Stencil func: set to always pass and set reference value to 1
// Stencil op: set the low stencil if z-compare is successful
// -------------------------------------------------------------------------------
Gl.glCullFace(Gl.GL_FRONT);
Gl.glStencilFunc(Gl.GL_ALWAYS, 1, 1);
Gl.glStencilOp(Gl.GL_KEEP, Gl.GL_KEEP, Gl.GL_REPLACE);
Gl.glEnable(Gl.GL_STENCIL_TEST);
Gl.glPolygonOffset(-.1f, .1f);
Gl.glEnable(Gl.GL_POLYGON_OFFSET_FILL);
//>>>>>>>>>>>>> Draw object's inside (we are culling front faces) <<<<<<<<<
Gl.glPopMatrix();
// 3. Turn off culling and clipping plane
// -------------------------------------------------------------------------------
Gl.glDisable(Gl.GL_CLIP_PLANE0);
Gl.glStencilFunc(Gl.GL_EQUAL, 1, 1);
Gl.glStencilOp(Gl.GL_KEEP, Gl.GL_KEEP, Gl.GL_KEEP); Gl.glPopAttrib(); |
Partager