#ifdef MAC #include #include #include #else #include #include #include #endif void twErrorCheck(char* file, int line) { int err=glGetError(); if(err!=GL_NO_ERROR) { char* msg; switch(err) { case GL_INVALID_ENUM: msg="Invalid Enum"; break; case GL_INVALID_VALUE: msg="Invalid Value"; break; case GL_INVALID_OPERATION: msg="Invalid Operation"; break; case GL_STACK_OVERFLOW: msg="Stack Overflow"; break; case GL_STACK_UNDERFLOW: msg="Stack Underflow"; break; case GL_OUT_OF_MEMORY: msg="Out of Memory"; break; case GL_TABLE_TOO_LARGE: msg="Table too large"; break; } printf("Error %s discovered in check at line %d in %s\n",msg,line,file); } } // The following macro makes it easier to figure out what line noticed the // error. Remember that the error could have been caused by any OpenGL // call since the previous error check. #define twError() twErrorCheck(__FILE__,__LINE__) void twDisplayInit(GLclampf bgR, GLclampf bgG, GLclampf bgB) { glClearColor(bgR,bgG,bgB,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); twError(); } // Clears to 75% gray void twDisplayInit() { twDisplayInit(0.75,0.75,0.75); } // Puts camera on Z axis, looking at origin, with +Y being up. void twCamera(float distance) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90,1,1,2*distance); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,distance, 0,0,0, 0,1,0); twError(); } void twCamera() { twCamera(10); } static GLint windowWidth; static GLint windowHeight; void twInitWindowSize(GLint xsize, GLint ysize) { glutInitWindowSize(xsize,ysize); windowWidth=xsize; windowHeight=ysize; } void twInitWindowSize() { twInitWindowSize(400,400); } /* ===================================================================== The following is an extremely simplified form of the U.S. flag. It's 8x4 and looks like B B R R R R R R B B W W W W W W R R R R R R R R W W W W W W W W where B means Blue, R means Red, and W means White. We'll use RGBA to avoid alignment issues. Notice that both dimensions are powers of two. */ const int FlagWidth = 8; const int FlagHeight = 4; GLubyte Flag[FlagHeight][FlagWidth][4]; void flaginit() { // The following constants stand for the RGBA indices. const int RED=0; const int GREEN=1; const int BLUE=2; const int ALPHA=3; int i,j; // The whole flag has max alpha for(i=0; i