/* * vertexLists.cpp * * Created on: Feb 13, 2013 * Author: debure */ /* flat and non-flat assemblies of triangles */ #include #include GLfloat vertices[][3] = { { -1.5, -0.5, 0 }, { -0.5, -0.5, 0 }, { -0.5, 0.5, 0 }, { -1.5, 0.5, 0 }, { -1, 0, 0 } }; GLfloat colors[][3] = { { 1.0, 0.0, 0.0 }, // colors[0] = red { 0.0, 0.0, 1.0 } }; // colors[1] = blue void drawPolygons() { glBegin(GL_POLYGON); glColor3f(1.0, 0.0, 1.0); glVertex3f(1.5, -0.5, 0); glVertex3f(0.5, -0.5, 0); glVertex3f(1.0, 0.5, 0); glEnd(); glBegin(GL_POLYGON); glColor3fv(colors[0]); glVertex3fv(vertices[0]); glVertex3fv(vertices[1]); glVertex3fv(vertices[2]); glEnd(); /* glEnableClientState(GL_VERTEX_ARRAY); // must have this set to use glDrawElements glVertexPointer(3, GL_FLOAT, 0, vertices); // tells where the array of vertices is located GLubyte indices[3]={0,1,2}; glDrawElements(GL_POLYGON, 3, GL_UNSIGNED_BYTE, indices); // second parameter is length of array */ } void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); /* viewing transformation */ glLoadIdentity(); gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); // first three values are camera pos // next three are camera direction // last three are up vector drawPolygons(); glFlush(); } void init() { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glMatrixMode(GL_PROJECTION); // specify which matrices are affected glLoadIdentity(); // start with a new transformation matrix // Use an orthographic view glOrtho(-2.0, 2.0, -2.0, 2.0, 2.0, 20.0); glMatrixMode(GL_MODELVIEW); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutCreateWindow("Vertex Lists"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }