glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(512, 512);
glutInitContextVersion(3,0);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutCreateWindow(argv[0]);
while (1) {
GetEvent(E)
if (E != NO_EVENT) {
DispatchEvent(E)
} else {
IdleEvent();
}
}
attribute vec4 vPosition;
void main() {
gl_Position = vPosition;
gl_PointSize = 5.0;
}
void init(void) {
glClearColor(1,1,1,1);
glEnable(GL_PROGRAM_POINT_SIZE);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
...
}
GLfloat vertices[NumVertices][2] = {
{ -0.90, 0.0},
{ -0.60, 0.90},
{ 0.60, 0.90},
{ 0.90, 0.00},
{ 0.60, -0.90},
{ -0.60, -0.90}
};
void display(void){
static int state = 0;
GLenum mode;
cout << "In the display function " << endl;
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(VAOs[Triangles]);
switch(state) {
case 0: mode = GL_POINTS;
cout << "Drawing Points " << endl;
break;
case 1: mode = GL_LINES;
cout << "Drawing Lines " << endl;
break;
case 2: mode = GL_LINE_STRIP;
cout << "Drawing Line Strip " << endl;
break;
case 3: mode = GL_LINE_LOOP;
cout << "Drawing Line Loop " << endl;
break;
case 4: mode = GL_TRIANGLES;
cout << "Drawing Triangles " << endl;
break;
case 5: mode = GL_TRIANGLE_STRIP;
cout << "Drawing Triangle Strip " << endl;
break;
default:
case 6: mode = GL_TRIANGLE_FAN;
cout << "Drawing Triangle Fan " << endl;
state = -1;
break;
}
state++;
glDrawArrays(mode, 0, NumVertices);
glFlush();
return;
}
// function prototype
void Keypress(unsigned char key, int x, int y) ;
int main() {
...
glutDisplayFunc(display);
glutKeyboardFunc(Keypress);
glutMainLoop();
};
void Keypress(unsigned char key, int x, int y) {
cout << "The " << key << " key was pressed at (" << x << "," << y
<< ")" << endl;
bool redisplay = false;
switch (key) {
case 'Q':
case 'q': exit(0);
case 'r':
case 'R': redisplay = true;
break;
default:
cerr << "Unhandled keypress for key '" << key << "'" << endl;
}
if (redisplay) {
glutPostRedisplay();
}
return;
}