In tutorial #03 you worked out the coordinates of vertices representing a star and an elephant. In this tutorial you will develop programs to display outlines of these objects. You will also fill the star with colour using GL_TRIANGLE_FAN or your own algorithm.
The Star
Start with the example program,
star1. This renders the outline of a star. However, only a small portion of the star is visible.
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}
};
/* ** coordinate system management */ GLdouble xLeft=0.0; GLdouble xRight=4.0; GLdouble yBottom=0.0; GLdouble yTop=4.0;
glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(xLeft,xRight,yBottom,yTop);
glutReshapeFunc(reshape);
void reshape(int w,int h){
if(w < h)
h = w;
else
w = h;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,w,h);
}
glBegin(GL_TRIANGLE_FAN);
glVertex2d(2.0,2.0);
for(i=0;i<starSize;i++)
glVertex2dv(star[i]);
glVertex2dv(star[0]);
glEnd();
Can you add code that will render each triangle of the fan in a different colour?
Fran Soddell     last updated 05 August 2002 F.Soddell@bendigo.latrobe.edu.au