// Copyright (c) David Kabala // Fall 2009 #include #include #include #include class SceneManager { protected: enum DrawExample {SINGLE_TRIANGLE, MANY_TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN}; DrawExample _Example; public: SceneManager(void) : _Example(SINGLE_TRIANGLE) { } void init(void) { } void reshape(int w, int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-w/2.0,w/2.0,-h/2.0,h/2.0,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glutPostRedisplay(); } void drawSingleTriangle(void) const { //Clear the Draw Buffer glClear(GL_COLOR_BUFFER_BIT); //Draw a single triangle glBegin(GL_TRIANGLES); glColor3f(1.0, 1.0, 1.0); /* white */ glVertex2i(0, 0); glVertex2i(150, 0); glVertex2i(150, 150); glEnd(); glFlush(); /* Single buffered, so needs a flush. */ } void drawManyTriangles(void) const { //Clear the Draw Buffer glClear(GL_COLOR_BUFFER_BIT); //Draw many triangle glBegin(GL_TRIANGLES); glColor3f(1.0, 1.0, 1.0); /* white */ glVertex2i(0, 0); glVertex2i(150, 0); glVertex2i(150, 150); glColor3f(0.0, 1.0, 0.0); /* green */ glVertex2i(-100, 100); glVertex2i(0, 100); glVertex2i(-50, 50); glColor3f(1.0, 0.0, 0.0); /* red */ glVertex2i(50, 50); glVertex2i(100, 100); glVertex2i(75, 20); glEnd(); glFlush(); /* Single buffered, so needs a flush. */ } void drawTriangleStrip(void) const { //Clear the Draw Buffer glClear(GL_COLOR_BUFFER_BIT); const GLfloat PI = 3.14159; unsigned int steps = 60; GLfloat scale = 50.0; glBegin(GL_TRIANGLES); glColor3f(1.0, 1.0, 1.0); /* white */ //Draw triangles allong the cosine curve GLfloat x; for(unsigned int i(0) ; i