VIZA 652 Lecture Notes for Sept. 13, 1997

/*
Sample OpenGL Program to Draw a Square

VIZA 652 Donald H. House 10/2/96

To compile:
cc -I /usr/local/include -o glsquare glsquare.c -lglut -lGLU -lGL -lXmu -lX11

*/

#include /* definitions for standard I/O routines */
#include /* definitions for GL graphics routines */
#include /* definitions for GL input device handling */
#include

#define WIDTH 600 /* window dimensions */
#define HEIGHT 600

/*
Draw clear the screen and draw a square
*/
void drawSquare(){

/* clear the window to the background color */
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1, 0, 0);
glBegin(GL_POLYGON);
glVertex2i(100, 100);
glVertex2i(100, 500);
glVertex2i(500, 500);
glVertex2i(500, 100);
glEnd();
}

/*
Main program to draw the squre and wait for quit
*/
void main(int argc, char* argv[]){

/* start up the glut utilities */
glutInit(&argc, argv);

/* create the graphics window, giving width, height, and title text */
glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow("A Simple Square");

/* the routine to call to draw graphics when glutMainLoop() is called */
glutDisplayFunc(drawSquare);

/* lower left of window is (0, 0), upper right is (WIDTH, HEIGHT) */
gluOrtho2D(0, WIDTH, 0, HEIGHT);

/* specify window clear (background) color to be white */
glClearColor(1, 1, 1, 0);

glutMainLoop();
}