In-Class Exercise:  Drawing Points



Using the following program, you are to add your own display function.  This display function will simply draw three lines of your choosing to the screen.
 
 

UNIX VERSION (Windows Below)
/*#####################################*/
/*Description:   program to draw three red lines*/
/*   to a GLUT window  that is 500x500 pixels*/
/*Author:  L. Grewe                                       */
/* UNIX VERSION                                         */
/*Date: 1-1-99                                               */
/*#####################################*/
 

#include <GL/gl.h>
#include <GL/glut.h>
#include <stdlib.h>

#include <stdio.h>
#include <math.h>

/*Function prototypes*/
GLvoid display(GLvoid);
GLvoid myinit(GLvoid);
 
 

     void main(int argc, char **argv) 
     { 

         glutInit(&argc,argv); /*init.  GLUT window sys.*/ 

         /*there will be a single buffered  window displaying RGB */ 
         glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); 

         glutInitWindowSize(500,500);   /*size in pixels  */
         glutInitWindowPosition(0,0);   /* located lower-left of screen */ 

         /*Create the window using the setup from the previous glut calls*/ 
         glutCreateWindow("Lines Example");  /*title=Lines Example*/ 

         /*tell system what function will be in charge of displaying*/ 
         glutDisplayFunc(display); 
 

         /*Call another function to further initialize window contents*/ 
         myinit(); 

         /*this call causes to go in infinite loop waiting for window i/o */ 
         glutMainLoop(); 

     } 
 
 
 
 

     /*#####################################*/ 
     /*myinit:  this function clears the background of the */ 
     /*  graphics system and sets up the drawing color to */ 
     /*  red.  Finally, viewing parameters are set.             */ 
     /*#####################################*/ 
     GLvoid myinit(GLvoid) 
     { 

          /*white background  */
          glClearColor(1.0,1.0,1.0,0.0); 

         /*drawing color red  */
         glColor3f(1.0,0.0,0.0); 

         /*Viewing Configuration  */
         glMatrixMode(GL_PROJECTION);  /*says will specify project.  */
         glLoadIdentity();   /*load identity matrix.*/ 
         gluOrtho2D(0.0,500.0, 0.0, 500.0);  /*specifies Othographic proj*/ 
 

        /*Shift to Model Specification Model  */
        glMatrixMode(GL_MODELVIEW); 
     } 
 
 
 
 

     
Show your work to your instructor.

  Solution
 
 
 
 

Windows VERSION
/*#####################################*/
/*Description:   program to draw three red lines*/
/*   to a GLUT window  that is 500x500 pixels*/
/*Author:  L. Grewe                                       */
/* Windows VERSION                                         */
/*Date: 1-1-99                                               */
/*#####################################*/
 

#include <windows.h>

#include <GL\Gl.h>
#include <GL\glut.h>
#include <stdlib.h>
 

#include <stdio.h>
#include <math.h>

/*Function prototypes*/
GLvoid display(GLvoid);
GLvoid myinit(GLvoid);
 
 

     void main(int argc, char **argv) 
     { 

         glutInit(&argc,argv); /*init.  GLUT window sys.*/ 

         /*there will be a single buffered  window displaying RGB */ 
         glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); 

         glutInitWindowSize(500,500);   /*size in pixels  */
         glutInitWindowPosition(0,0);   /* located lower-left of screen */ 

         /*Create the window using the setup from the previous glut calls*/ 
         glutCreateWindow("Lines Example");  /*title=Lines Example*/ 

         /*tell system what function will be in charge of displaying*/ 
         glutDisplayFunc(display); 
 

         /*Call another function to further initialize window contents*/ 
         myinit(); 

         /*this call causes to go in infinite loop waiting for window i/o */ 
         glutMainLoop(); 

     } 
 
 
 
 

     /*#####################################*/ 
     /*myinit:  this function clears the background of the */ 
     /*  graphics system and sets up the drawing color to */ 
     /*  red.  Finally, viewing parameters are set.             */ 
     /*#####################################*/ 
     GLvoid myinit(GLvoid) 
     { 

          /*white background  */
          glClearColor(1.0,1.0,1.0,0.0); 

         /*drawing color red  */
         glColor3f(1.0,0.0,0.0); 

         /*Viewing Configuration  */
         glMatrixMode(GL_PROJECTION);  /*says will specify project.  */
         glLoadIdentity();   /*load identity matrix.*/ 
         gluOrtho2D(0.0,500.0, 0.0, 500.0);  /*specifies Othographic proj*/ 
 

        /*Shift to Model Specification Model  */
        glMatrixMode(GL_MODELVIEW); 
     } 
 
 
 
 

     
Show your work to your instructor.