// GLUT drawing code // by including draw.h, we ensure that the exported prototypes // match the function definitions #include "draw.h" // Apple's annoying non-standard GL include location #if defined(__APPLE__) || defined(MACOSX) #include #else #include #endif #include #include #include using namespace std; // style to use when drawing DrawStyle drawStyle = DRAW_TEAPOT; // update frame count void updateFrame(int m) { static int frame[4]={0,0,0,0}; static int inc[4]={0,0,0,0}; const int max=500; if (m==9) // reset to start frame[0] = frame[1] = frame[2] = frame[3] = 0; else if (m==1) --inc[0]; // red else if (m==2) ++inc[0]; else if (m==3) --inc[1]; // green else if (m==4) ++inc[1]; else if (m==5) --inc[2]; // blue else if (m==6) ++inc[2]; else if (m==7) --inc[3]; // alpha else if (m==8) ++inc[3]; if (m==0 || m==9) { // stop changing inc[0] = inc[1] = inc[2] = inc[3] = 0; glutPostRedisplay(); } else if (inc[0] != 0 || inc[1] != 0 || inc[2] != 0 || inc[3] != 0) glutPostRedisplay(); float color[4]; for(int i=0; i<4; ++i) { frame[i] += inc[i]; if (frame[i] < 0) {inc[i] = 0; frame[i] = 0;} if (frame[i] > max) {inc[i] = 0; frame[i] = max;} color[i] = (float)frame[i]/max; } glColor4fv(color); } // draw teapot (scaled to 90, center of rotation translated to middle) void drawTeapot() { // draw teapot glPushMatrix(); glTranslatef(-10,0,0); glutSolidTeapot(90); glPopMatrix(); } // draw sphere // hand coded since GLU reuses some texture coordinates along // the seam, which isn't too good for my "unwrapping" examples void drawSphere() { // draw sphere glPushMatrix(); glScalef(90,90,90); const int n_s=40, n_t=20; GLfloat ds=1./n_s, dt=1./n_t; GLfloat s=0, cos_s=1, sin_s=0; GLfloat cos_ds = cos(2*M_PI*ds), sin_ds = sin(2*M_PI*ds); GLfloat cos_dt = cos( M_PI*dt), sin_dt = sin( M_PI*dt); for(int i = 0; i