** File:          star2.c
** Description:   Renders the outline of a star.
**                Demonstrates setting up the abstract
**                world coordinates and the physical viewport.
** Rev:           1.0
** Created:       06 August 2002
** Last Update:   08 August 2002
** Author:        Fran Soddell
** Email:         F.Soddell@bendigo.latrobe.edu.au
*/
#include <GL/glut.h>
/*
** window and viewport management
*/
int width=300;
int height=300;
int xPosition=50;
int yPosition=50;
int xOrigin=0;
int yOrigin=0;
/*
** world coordinate management
*/
GLdouble xLeft=0.0;
GLdouble xRight=4.0;
GLdouble yBottom=0.0;
GLdouble yTop=4.0;
/*
** colour management
*/
#define NUM_COLOURS 9
#define ALPHA 1.0
enum {black,
      red,green,blue,yellow,magenta,cyan,
      orange,white
};
typedef GLdouble colourType[3];
colourType colour[]={
   {0.0,0.0,0.0},
   {1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0},
   {1.0,1.0,0.0},{1.0,0.0,1.0},{0.0,1.0,1.0},
   {1.0,0.35,0.0},{1.0,1.0,1.0}
};
int current = orange;
/*
** model management
*/
enum {x,y};
typedef GLdouble vertexType [2];
int starSize=10;
vertexType star[]={
   {0.8,0.1},{1.95,1.1},{3.2,0.4},
   {2.6,1.9},{3.5,2.9},{2.2,2.7},
   {1.6,3.8},{1.3,2.6},{0.1,2.3},
   {1.1,1.6}
};
GLint lineWidth=3;
/*
**  ***********************************************************
*/
void render(vertexType * image, int numVertices, GLenum mode){
   int i;
   glBegin(mode);
      for(i=0;i<numVertices;i++)
         glVertex2d(image[i][x],image[i][y]);
   glEnd();
}
void renderView(){
   int i;
   glColor3dv(colour[orange]);
   render(star,starSize,GL_LINE_LOOP);
}
void display(){
   /*
   ** Clear the window with the background colour before
   ** (re)rendering.
   */
   glClear(GL_COLOR_BUFFER_BIT);
   renderView();
   glFlush();
}
void reshape(int w,int h){
   /*
   ** Set the global width and height
   ** to the current GLUT values.
   */
   width=w;
   height=h;
   /*
   ** Set the viewport to the whole GLUT window.
   ** This is the default.
   */
   glViewport(xOrigin,yOrigin,width,height);
   /*
   ** Tell OpenGL to clear out whatever is in
   ** the PROJECTION matrix and set the abstract
   ** world coordinates.
   */
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluOrtho2D(xLeft,xRight,yBottom,yTop);
   /*
   ** It is a good programming habit to return the
   ** matrix mode to the default MODELVIEW matrix.
   */
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}
void setUpGLUT(int argc,char ** argv){
   glutInit(&argc,argv);
   /*
   ** The variables, width, height, xPosition,
   ** and yPosition are global because I may
   ** wish to change them from many functions
   ** as the program is running.
   */
   glutInitWindowSize(width,height);
   glutInitWindowPosition(xPosition,yPosition);
   /*
   ** If a user enters a string on the command line
   ** use that as the title for the window, otherwise
   ** use a default title.
   */
   if(argc > 1)
      glutCreateWindow(argv[1]);
   else
      glutCreateWindow("Star");
   /*
   ** Register callbacks.
   */
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
}
void initialiseGL(){
   /*
   ** Set the background colour
   ** (clear colour) to white.
   */
   glClearColor(1,1,1,ALPHA);
   glLineWidth(lineWidth);
}
int main(int argc,char ** argv){
   setUpGLUT(argc,argv);
   initialiseGL();
   /*
   ** Display window and enter the GLUT event
   ** processing loop.
   */
   glutMainLoop();
   return 0;
}
&amp;lt;/pre&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;</pre></body></html>