
/* A Very Simple OpenGL Example! */
/******************************************/
/* this code just creates a window and draws a rectangle in it */
#include <windows.h> /* obviously change this to your native library if you're compiling under unix */
#include <gl\gl.h>
#include <gl\glut.h>
void init(void);
void display(void);
int main (int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow("My First OpenGL Application");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void init(void) {
glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0, 10.0, –10.0, 10.0, –10.0, 10.0);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glRectf(-5.0, 5.0, 5.0, –5.0);
glutSwapBuffers();
}
/**********************************************************************/
Lets go through this step by step:
First, I called the glutInit function, which provides general initialization for the GLUT library:
