bool Component::setupClipping(Graphics* const Graphics) const { if(getClipping()) { //Get Clipping initial settings Pnt2f ClipTopLeft,ClipBottomRight; getClipBounds(ClipTopLeft,ClipBottomRight); Vec4d LeftPlaneEquation (1.0,0.0,0.0, -ClipTopLeft.x() + Graphics->getClipPlaneOffset()), RightPlaneEquation (-1.0,0.0,0.0, ClipBottomRight.x() + Graphics->getClipPlaneOffset()), TopPlaneEquation (0.0,1.0,0.0, -ClipTopLeft.y() + Graphics->getClipPlaneOffset()), BottomPlaneEquation(0.0,-1.0,0.0, ClipBottomRight.y() + Graphics->getClipPlaneOffset()); //glClipPlane //Clip with the Intersection of this components RenderingSurface bounds //and its parents RenderingSurface bounds if(ClipBottomRight.x()-ClipTopLeft.x() <= 0 || ClipBottomRight.y()-ClipTopLeft.y()<= 0) { return false; } if(!glIsEnabled(GL_CLIP_PLANE0)) { glEnable(GL_CLIP_PLANE0); } if(!glIsEnabled(GL_CLIP_PLANE1)) { glEnable(GL_CLIP_PLANE1); } if(!glIsEnabled(GL_CLIP_PLANE2)) { glEnable(GL_CLIP_PLANE2); } if(!glIsEnabled(GL_CLIP_PLANE3)) { glEnable(GL_CLIP_PLANE3); } //Clip Plane Equations //Clip Planes get transformed by the ModelViewMatrix when set //So we can rely on the fact that our current coordinate space //is relative to the this components position glClipPlane(GL_CLIP_PLANE0,LeftPlaneEquation.getValues()); glClipPlane(GL_CLIP_PLANE1,RightPlaneEquation.getValues()); glClipPlane(GL_CLIP_PLANE2,TopPlaneEquation.getValues()); glClipPlane(GL_CLIP_PLANE3,BottomPlaneEquation.getValues()); } else { if(glIsEnabled(GL_CLIP_PLANE0)) { glDisable(GL_CLIP_PLANE0); } if(glIsEnabled(GL_CLIP_PLANE1)) { glDisable(GL_CLIP_PLANE1); } if(glIsEnabled(GL_CLIP_PLANE2)) { glDisable(GL_CLIP_PLANE2); } if(glIsEnabled(GL_CLIP_PLANE3)) { glDisable(GL_CLIP_PLANE3); } } return true; }