Some students have reported they were unable to download freecommandLinetools.exe from Borland. This is probably a temporary problem.
Use the program you were working on in the last tutorial, square.c, and specify the size and position of the GLUT window.
/* ** manage GLUT window */ int width = 300; int height = 300; int xPosition = -1; int yPosition = -1;
setUpGLUT. The position of the code is important.
void setUpGLUT(int argc,char ** argv){
glutInit(&argc,argv);
glutInitWindowSize(width, height);
glutInitWindowPosition(xPosition, yPosition);
glutCreateWindow("Square");
/*
** Register callbacks.
*/
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
}
width, height, xPosition, yPosition are the default values, so there will be no change in the appearance of the application. What is the significance of the negative values for xPosition, yPosition?
Use the same program and experiment changing the world coordinate system.
/* ** manage world coordinates */ GLdouble xLeft = -1.0; GLdouble xRight = 1.0; GLdouble yBottom = -1.0; GLdouble yTop = 1.0;
xLeft, yBottom is the bottom left hand corner of your virtual 2D world and xRight, yTop is the top right hand corner. C requires that you position functions above functions that call them. Place setProjection above display.
void setProjection(void){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(xLeft, xRight, yBottom, yTop);
glMatrixMode(GL_MODELVIEW);
}
void display(void){
setProjection();
/*
** Clear the window with the background colour before
** (re)rendering.
*/
glClear(GL_COLOR_BUFFER_BIT);
glColor3fv(colour[orange]);
render(square,NUM_VERTICES_FOR_SQUARE,GL_POLYGON);
/*
** Cause all OpenGL commands to be executed.
*/
glFlush();
}
xLeft, xRight, yBottom, yTop are the defaults, so there will be no change in the appearance. Change the values and observe what happens.
xLeft -2.0, -0.5, 0.0 xRight 2.0, 0.5, 1.0 yBottom -2.0, -0.5, 0.0 yTop 2.0, 0.5, 1.0
Use the same program, add code to render the image of a star. Change the world coordinate system so that the full image can be seen.
#define STAR_VERTICES 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}
};
render(star, STAR_VERTICES, GL_LINE_LOOP);
In Lecture #02 Week #02, you recorded the coordinates of the star.
Start working on Assignment 1, which has been available since 31st July 06. If you did not receive a handout in the lecture, ask me for one .
Copyright © 2006 Fran Soddell