// ------------------------------------------------------ #include
#ifdef MacOSX
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std ;
// ------------------------------------------------------ Global Vars
static int resX = 640 ;
static int resY = 480 ;
static GLenum fillMode = GL_FILL ;
/*
------------------------------------------------------
**OnDraw() ;
**This is where we draw all the stuff.
------------------------------------------------------ OnDraw()
*/
void OnDraw() {
/* Clear screen and depth buffer. */
glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ) ;
/* clear the previous transform */
glLoadIdentity() ;
/*
Set the camera position.
gluLookAt( eye3, aim3, up3 ) ;
*/
gluLookAt( 1,1,10, 0,0,0, 0,1,0) ;
/* Set shading mode - Wire Frame/Flat Shaded/etc. */
//glPolygonMode( GL_FRONT_AND_BACK, fillMode ) ;
/* Draw the Utah teapot */
glutWireTeapot( 1 ) ;
// currently we've been drawing to the back buffer, we need
// to swap the back buffer with the front one to make the image visible
glutSwapBuffers();
}
/*
**OnReshape() ;
**Window resize and related stuff is handeled here.
------------------------------------------------------ OnReshape()
*/
void OnReshape( int w, int h ) {
/* Thou shalt not divide by zero! */
if ( h == 0 ) {
h = 1 ;
}
/* Set the drawable region of the window. */
glViewport( 0, 0, w, h) ;
/* Set the projection matrix. */
glMatrixMode( GL_PROJECTION ) ;
glLoadIdentity() ;
/*
Use perspective camera.
gluPersp...( fov, aspect, near, far ) ;
*/
gluPerspective( 45, (float) w/h, 0.1, 100);
/* Set modelview matrix. */
glMatrixMode( GL_MODELVIEW ) ;
}
/*
------------------------------------------------------
**OnKeyboard() ;
**All Keyboard interaction is handeled here.
------------------------------------------------------ OnKeyboard()
*/
void OnKeyboard( unsigned char key, int x, int y ) {
switch( key ) {
case 27 : /* 27 is the code for ESC. */
cout << "ESC was pressed" << endl ;
exit( 0 ) ; /* Quit applicatio.n */
break ;
case 'w' : /* Toggle wire-frame/flat-shade. */
cout << "w was pressed" << endl ;
fillMode = !fillMode ;
glPolygonMode (GL_FRONT_AND_BACK, fillMode ? GL_FILL : GL_LINE) ;
break ;
case 'f' : /* Translate camera forward. */
cout << "f was pressed" << endl ;
break ;
case 'b' : /* Translate camera backward. */
cout << "b was pressed" << endl ;
break ;
case 'l' : /* Rotate camera left. */
cout << "l was pressed" << endl ;
break ;
case 'r' : /* Rotate camera right. */
cout << "r was pressed" << endl ;
break ;
default:
/* Do nothing. */
break ;
}
glutPostRedisplay() ;
}
/*
------------------------------------------------------ OnInit()
*/
void OnInit() {
/* Enable dept testing */
glEnable( GL_DEPTH_TEST ) ;
}
/*
------------------------------------------------------ OnExit()
*/
void OnExit() {
/* Print exit message */
cout << "Have a nice day :)" << endl ;
}
/*
------------------------------------------------------ main()
*/
int main( int argc, char* argv[] ) {
/* ------------- Initialisation ------------- */
/* initialise glut */
glutInit( &argc, argv ) ;
/* Set display mode. */
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) ;
/* Set polygon mode. */
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ) ;
/* Initial window size. */
glutInitWindowSize( resX, resY ) ;
/* Create Window */
glutCreateWindow(" a1214415::assign1 ");
/* --------------- Call Backs --------------- */
/* Set function for drawing. */
glutDisplayFunc( OnDraw ) ;
/* Set function for screen resize. */
glutReshapeFunc( OnReshape ) ;
/* Pass keyboad function to GLUT */
glutKeyboardFunc( OnKeyboard ) ;
/* --------------- Prog. Init. -------------- */
/* Use custom OnInit(). */
OnInit() ;
/* Call this function on exit. */
atexit(OnExit) ;
/* ------------------- GO! ------------------ */
/* Start the main while loop. */
glutMainLoop() ;
return 0 ;
}