INT32GP Graphics Programming: Tutorial #07
Hints for Assignment 1

B1.11 3:00pm Mon 19 Aug 02
B1.11 12midday Tues 20 Aug 02
Note: This tutorial is scheduled in the Indy Lab

Useful Links

List of colours and RGB values

Handy mathematics Facts for Graphics - includes an approximation of PI to 35 decimal points.

Toggling between fullscreen and window mode

The following GLUT function will set your application to full screen mode.
glutFullScreen();
Use the following code (or similar) to return to window mode.
glutReshapeWindow(width,height);
glutPositionWindow(xPosition,yPosition);
It is a mistake to leave out glutPositionWindow(xPosition,yPosition). Try it on the SGI machines. I found that this mistake in my code did not show up on my PC. The GLUT PC implementation returned the window to its original or default position. It is was easy to debug the program on the SGI machines.

Capturing images of your output

For PCs, use <ALT><Print Screen> while the program is running. Paste the image into Paint and save as a JPEG file to include in you html documentation.

For SGIs, find the Media Tools such as mediarecorder and mediaconvert.

Circle

  1. Include math.h and globally declare a constant for PI
    #include <math.h>
    #define PI 3.14159
  2. Declare global arrays (for circles or other nGons that you intend to use), to be filled with values. Here is an example.
    enum {x,y};
    typedef GLdouble vertexType [2];
    #define CIRCLE_SIZE 64
    vertexType circle1[CIRCLE_SIZE];
    vertexType circle2[CIRCLE_SIZE];
    vertexType equilateral[3];
    vertexType pentagon[5];
    
  3. Write a general nGon function based on the following pseudocode.
    IN: an array (nGon) of vertexType,
        the xCentre (double) of the nGon,the yCentre of the nGon,
        the numVertices (integer) of the nGon,
        the radius (double) of the nGon
    
    angle = 2 * PI / numVertices
    for(i=0;i<numVertices;i++){
       nGon[i][x]=centreX+radius*cos(i*angle)
       nGon[i][y]=centreY+radius*sin(i*angle)
    }
    
  4. Write an initialise() function to be called from the top of main eg.
    calculateNgon(equilateral,2.0,1.0,3,1.5);
    calculateNgon(circle1,0.0,0.0,CIRCLE_SIZE,1.0);
    calculateNgon(pentagon,1.5,1.5,5,0.5);
  5. To render the nGons, reuse your general render function. Eg. call the following from display
    render(circle1,CIRCLE_SIZE,GL_POLYGON);
    render(equilateral,3,GL_LINE_LOOP);
Fran Soddell email:F.Soddell@bendigo.latrobe.edu.au
last updated 16 August 2002