// OpenGL Tutorial // Hello_World.c // http://www.eecs.tulane.edu/www/Terry/OpenGL/Introduction.html /************************************************************************* This program essentially opens a window, clears it, sets the drawing color, draws the object, and flushes the drawing buffer. It then goes into an infinite loop accepting events and calling the appropriate functions. *************************************************************************/ // gcc -o Hello_World Hello_World.c -lm -L/usr/lib -lGLU -lGL -lglut -L/usr/X11R6/lib -lX11 -lXext -lXi -lXmu //OR USE lgcc scripts #include #include #include #include void init() { // Clear the window glClear(GL_COLOR_BUFFER_BIT); } void reshape(int width, int height) { // Set the new viewport size glViewport(0, 0, (GLint)width, (GLint)height); // Clear the window glClear(GL_COLOR_BUFFER_BIT); } void draw(void) { // Set the drawing color glColor3f(1.0, 1.0, 1.0); // Specify which primitive type is to be drawn glBegin(GL_POLYGON); // Specify verticies in quad glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); // Flush the buffer to force drawing of all objects thus far glFlush(); } int main(int argc, char **argv) { // Open a window, name it "Hello World" glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(400, 400); glutInitWindowPosition(200,200); glutCreateWindow("Hello World"); // Set the clear color to black glClearColor(0.0, 0.0, 0.0, 0.0); // Call an initialization function init(); // Assign reshape() to be the function called whenever // a reshape event occurs glutReshapeFunc(reshape); // Assign draw() to be the function called whenever a display // event occurs, generally after a resize or expose event glutDisplayFunc(draw); // Pass program control to tk's event handling code // In other words, loop forever glutMainLoop(); return 0; }