Due: Wednesday, April 8, by 11:59pm
|
OBJECTIVE: This lab is just to get you to type in an OpenGl program and get it to run. Basically, it is intended to make sure everyone has an OpenGL programming environment set up so they can do the lab assignments. Type in the code below, compile it, and run it. Notes:
|
|
////////////////////////////////////////////////////////
// CSE 581 - Spring '09
// Lab 0
// <your name here>
// <your email address here>
////////////////////////////////////////////////////////
#include <glut.h>
void myDisplay();
// =================================================
// MAIN
int main(int argc, char** argv)
{
glutInit(&argc, argv); // initialize OpenGL
glutCreateWindow("Lab 0"); // create a window
glutDisplayFunc(myDisplay); // display callback function is 'myDisplay'
glutMainLoop(); // go into the main idle loop: wait for an event
}
// =================================================
// MY DISPLAY
void myDisplay()
{
glColor3f(1,0,0); // set the color to red
glClear(GL_COLOR_BUFFER_BIT); // clear the buffer
glColor3f(1,0,1); // set the color to cyan
glBegin(GL_LINES); // draw individual lines
glVertex2f(-0.75, -0.75);
glVertex2f(0.75, 0.75);
glVertex2f(-0.75, 0.75);
glVertex2f(0.75, -0.75);
glEnd();
glColor3f(1,1,1); // set the color to white
glBegin(GL_LINE_STRIP); // draw connected lines
glVertex2f(-1.0, -1.0);
glVertex2f(2.0, 1.0);
glVertex2f(0.5, -1.0);
glVertex2f(2.0, 0.5);
glEnd();
glColor4f(1,1,0,1); // set the color to yellow
glBegin(GL_POLYGON); // draw a polygon
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glColor3f(0,1,0); // set the color to green
glBegin(GL_TRIANGLES); // draw a 2D triangle
glVertex2f(-0.25, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glEnd();
glFlush(); // this 'flushes' the command buffer
}