Commit 1ddb871c authored by Ellen Dekkers's avatar Ellen Dekkers

ACG/Scenegraph: Use stencil buffer in coordsys node.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5450 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 35686a74
......@@ -213,6 +213,9 @@ draw(GLState& _state , unsigned int /*_drawMode*/)
// Init state - changes when mode_ != POSITION
Vec3d pos3D(0.0,0.0,0.0);
GLint stencil = 0;
glGetIntegerv(GL_STENCIL_BITS, &stencil);
if ( mode_ == SCREENPOS ) {
int left, bottom, width, height;
......@@ -244,12 +247,36 @@ draw(GLState& _state , unsigned int /*_drawMode*/)
_state.set_modelview (modelview);
_state.translate (pos3D[0], pos3D[1], pos3D[2]-0.3, MULT_FROM_LEFT);
if (stencil > 0)
{
glEnable (GL_STENCIL_TEST);
// clear stencil buffer in desired area
glStencilOp (GL_ZERO, GL_KEEP, GL_KEEP);
glStencilFunc (GL_NEVER, 0, ~0);
drawClearArea(_state, false, GLMatrixd ());
// fill stencil with values
glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE);
glStencilFunc (GL_NEVER, 1, ~0);
drawCoordsys(_state);
// draw only to regions that have been marked
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc (GL_EQUAL, 1, ~0);
}
// clear depth buffer behind coordsys node
drawClearArea(_state, false, GLMatrixd ());
drawClearArea(_state, false, GLMatrixd (), 1.0);
// Koordinatensystem zeichnen
drawCoordsys(_state);
// make sure nothing can paint above coordsys node
drawClearArea(_state, false, GLMatrixd (), 0.0);
if (stencil > 0)
glDisable (GL_STENCIL_TEST);
// Projection reload
_state.pop_projection_matrix();
......@@ -264,10 +291,34 @@ draw(GLState& _state , unsigned int /*_drawMode*/)
_state.set_modelview (modelview);
if (stencil > 0)
{
glEnable (GL_STENCIL_TEST);
// clear stencil buffer in desired area
glStencilOp (GL_ZERO, GL_KEEP, GL_KEEP);
glStencilFunc (GL_NEVER, 0, ~0);
drawClearArea(_state, false, GLMatrixd ());
// fill stencil with values
glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE);
glStencilFunc (GL_NEVER, 1, ~0);
drawCoordsys(_state);
// draw only to regions that have been marked
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc (GL_EQUAL, 1, ~0);
}
// clear depth buffer behind coordsys node
drawClearArea(_state, false, GLMatrixd ());
drawClearArea(_state, false, GLMatrixd (), 1.0);
drawCoordsys(_state);
// make sure nothing can paint above coordsys node
drawClearArea(_state, false, GLMatrixd (), 0.0);
if (stencil > 0)
glDisable (GL_STENCIL_TEST);
}
glPopAttrib();
......@@ -408,7 +459,7 @@ CoordsysNode::pick(GLState& _state, PickTarget _target)
//----------------------------------------------------------------------------
void CoordsysNode::drawClearArea(GLState& _state, bool _pick, GLMatrixd _pickMatrix)
void CoordsysNode::drawClearArea(GLState& _state, bool _pick, GLMatrixd _pickMatrix, GLfloat z)
{
std::vector<Vec2f> points;
Vec2f center;
......@@ -452,7 +503,7 @@ void CoordsysNode::drawClearArea(GLState& _state, bool _pick, GLMatrixd _pickMa
_state.push_modelview_matrix();
_state.reset_modelview();
glDepthFunc (GL_ALWAYS);
_state.translate (center[0], center[1], -1.0);
_state.translate (center[0], center[1], -z);
if (_pick)
_state.pick_set_name (0);
......
......@@ -117,7 +117,7 @@ public:
void drawCoordsys(GLState& _state);
void drawCoordsysPick(GLState& _state);
void drawClearArea(GLState& _state, bool _pick, GLMatrixd _pickMatrix);
void drawClearArea(GLState& _state, bool _pick, GLMatrixd _pickMatrix, GLfloat z = 1.0);
void boundingCircle(std::vector<Vec2f> &_in, Vec2f &_center, float &_radius);
CoordsysMode mode_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment