void setUpGLUT(int argc,char ** argv)
. glutKeyboardFunc(keyboard);
void reverse(int coordinate){ /* ** Reverse the coordinates of the world window ** so that the image turns back to front or ** upside down. Note: x and y are enumerated ** data types declared globally. ** IN: value indicating whether to reverse the ** x or y coordinates. */ GLdouble temp; if(coordinate==y){ temp=yTop; yTop=yBottom; yBottom=temp; } else{ temp=xLeft; xLeft=xRight; xRight=temp; } } void keyboard(unsigned char key,int xMouse,int yMouse){ switch(key){ case 27: exit(0); case 'u':reverse(y); break; case 'b':reverse(x); break; } glutPostRedisplay(); }
void reshape(int w,int h)
and move it to the top of void display()
./* Tell OpenGL to clear out whatever is in ** the PROJECTION matrix and (re)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();
glutSpecialFunc(void (*func)(int key,int xMouse,int yMouse)
to detect keyboard input from special keys, such as the GLUT_KEY_RIGHT
. For a complete list of the special keys that GLUT can detect, consult the GLUT API.
void setUpGLUT(int argc,char ** argv)
.glutSpecialFunc(specialKeys);
void specialKeys(int key,int xMouse,int yMouse){ switch(key){ case GLUT_KEY_RIGHT: xLeft-=0.1; xRight-=0.1; break; } glutPostRedisplay(); }
GLUT_KEY_LEFT
.GLUT_KEY_UP
and GLUT_KEY_DOWN
.void renderView()
with three functions, one for each view. Use the code below if you like.
void bottomView(){ glViewport(xOrigin,yOrigin,width,height/3); glColor3dv(colour[red]); render(star,starSize,GL_LINE_LOOP); } void middleView(){ glViewport(xOrigin,height/3,width,height/3); glColor3dv(colour[cyan]); render(star,starSize,GL_LINE_LOOP); } void topView(){ glViewport(xOrigin,height/3*2,width,height/3); glColor3dv(colour[green]); render(star,starSize,GL_LINE_LOOP); }
void display()
, after clearing the GL_COLOR_BUFFER_BIT
and before glFlush();
.void middleView()
and void topView()
functions, making appropriate changes to render the triangle and circle (as discussed in tutorial #05).