#include #include #include class SceneManager { protected: unsigned int _Example; int _Width, _Height; public: SceneManager(void) : _Example(1) { } void init(void) { } void reshape(int w, int h) { _Width = w; _Height = h; glutPostRedisplay(); } void drawTwoViewports(void) const { glViewport(0,0,_Width/2.0,_Height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-_Width/4.0,_Width/4.0,-_Height/2.0,_Height/2.0,-10.0,10.0); glMatrixMode(GL_MODELVIEW); //Clear the Draw Buffer glClear(GL_COLOR_BUFFER_BIT); //Draw big plane in distance drawPlane(1.0,1.0,1.0); //Red box drawBox(1.0,0.0,0.0); glViewport(_Width/2.0,0,_Width/2.0,_Height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-_Width/4.0,_Width/4.0,-_Height/2.0,_Height/2.0,-10.0,10.0); glMatrixMode(GL_MODELVIEW); //Green box drawBox(0.0,1.0,0.0); glFlush(); /* Single buffered, so needs a flush. */ } void drawBox(GLfloat red, GLfloat green, GLfloat blue) const { //Draw a single quad glBegin(GL_QUADS); glColor3f(red,green,blue); glVertex2i(-75, -75); glVertex2i(75, -75); glVertex2i(75, 75); glVertex2i(-75, 75); glEnd(); } void drawPlane(GLfloat red, GLfloat green, GLfloat blue) const { //Draw a single quad glBegin(GL_QUADS); glColor3f(red,green,blue); glVertex3i(-500, -500, 5); glVertex3i(500, -500, 5); glVertex3i(500, 500, 5); glVertex3i(-500, 500, 5); glEnd(); } void display(void) const { switch(_Example) { case 1: default: drawTwoViewports(); break; } } void keyboard(unsigned char key, int x, int y) { switch(key) { case 'q': //exit(0); break; case '1': _Example = 1; break; } glutPostRedisplay(); } }; SceneManager mgr; void reshape(int w, int h) { mgr.reshape(w,h); } void display(void) { mgr.display(); } void keyboard(unsigned char key, int x, int y) { mgr.keyboard(key,x,y); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE); glutCreateWindow("Viewport Examples"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutReshapeWindow(800,640); glutPositionWindow(50,50); glutKeyboardFunc(keyboard); mgr.init(); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }