void drawScene() {
static Rectf theRect(50, 50, 200, 100);
gl::color(0, 0, 1);
gl::drawSolidTriangle(theRect.getLowerLeft(), theRect.getLowerRight(), theRect.getUpperRight());
gl::color(0, 1, 0);
gl::drawSolidTriangle(theRect.getLowerLeft(), theRect.getUpperLeft(), theRect.getUpperRight());
}
static Rectf windowPort(30, 20, 130, 170);
static Area viewPort(100, 30, 300, 330);
void drawWindow1() {
gl::clear();
// draw the scene
drawScene();
// draw window port area
gl::color(1, 0, 0);
gl::drawStrokedRect(windowPort, 3);
}
void drawWindow2() {
gl::clear();
// clipping by using ortho projection
gl::ScopedProjectionMatrix projectionMatrixScope;
CameraOrtho orthoCam;
orthoCam.setOrtho(windowPort.x1, windowPort.x2, windowPort.y2, windowPort.y1, 1, -1);
gl::setProjectionMatrix(orthoCam.getProjectionMatrix());
// draw the scene
drawScene();
}
void drawWindow3() {
gl::clear();
// draw view port area
gl::color(1, 0, 0);
gl::drawStrokedRect(Rectf(viewPort), 3);
// mapping scene to view port area
gl::ScopedViewport scopeViewPort(viewPort.getUL(), viewPort.getSize());
// clipping by using ortho projection
gl::ScopedProjectionMatrix projectionMatrixScope;
CameraOrtho orthoCam;
orthoCam.setOrtho(windowPort.x1, windowPort.x2, windowPort.y2, windowPort.y1, 1, -1);
gl::setProjectionMatrix(orthoCam.getProjectionMatrix());
drawScene();
}