Sunday, May 17, 2009

Simple Mac OS X OpenGL Program


// Apple gcc program0.c -framework opengl -framework glut

// A simple OpenGL and glut program
#include <GLUT/glut.h> /* Header File For The GLut Library*/

void display() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();

glFlush();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitWindowSize(512,512);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("The glut hello world program");
glutDisplayFunc(display);
glClearColor(0.0, 0.0, 0.0, 1.0);
glutMainLoop(); // Infinite event loop
return 0;
}