1/21/04


We discussed a sample program that drew a line on the screen and two points. We talked about display screen size and the main functions we need in an OpenGL program.

We discussed the Sierpinski's Gasket and went through one of the algorithms in class.
Here is a sample program we used to display a line and two points. We used boththe vector notation and single point notation.

/* Program line.C. Draws a single line from lower leftto upper right corner of the window */
#include <GL/glut.h>

typedef   GLfloat  point2[2];  // Defining a vector

void myinit(void)
{       
    /* attributes */       
    glClearColor(1.0, 1.0, 1.0, 1.0);
   
    /* white background */       
    glColor3f(1.0, 0.0, 0.0);
    /* draw in black */       
    /* set up viewing */       
    /* 50 x 50 window with origin lower left */       
    glMatrixMode(GL_PROJECTION);       
    glLoadIdentity();       
    gluOrtho2D(0.0, 120.0, 0.0, 120.0);       
    glMatrixMode(GL_MODELVIEW);

}

void display( void )
{       
    glClear(GL_COLOR_BUFFER_BIT); 
    /*clear the window */       

/*
    // using single point notation for the vertices, from here
    glBegin(GL_LINES);               
       glVertex2f(60,10);                
       glVertex2f(10,110);
    glEnd();   
   
    glBegin(GL_POINTS);               
       glVertex2f(70,10);                
       glVertex2f(20,110);
    glEnd();       
     // single point notation, up to here
*/
    // using verctor format for the vertices, from here
    point2 v1={60, 30}, v2={10,110};
    point2 v3={70, 30}, v4={20,110};

   
    glBegin(GL_LINES);               
       glVertex2fv(v1);                
       glVertex2fv(v2);
    glEnd();   
   
    glBegin(GL_POINTS);               
       glVertex2fv(v3);                
       glVertex2fv(v4);
    glEnd();       
     // vector notation up to here

    glFlush();
    /* clear buffers */
}

void main(int argc, char** argv)
{       
    /* Standard GLUT initialization */       
    glutInit(&argc,argv);       
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    /* default, not needed */       
    glutInitWindowSize(500,500);
    /* 500 x 500 pixel window */       
    glutInitWindowPosition(0,0);
    /* place window top left on display */       
    glutCreateWindow("MyTest");
    /* window title */       
    glutDisplayFunc(display);
    /* display callback invoked when window opened */       
    myinit(); /* set attributes */       
    glutMainLoop(); /* enter event loop */
}