132001f49Smrg/* 232001f49Smrg * Use glCopyTexSubImage2D to draw animated gears on the sides of a box. 332001f49Smrg * 432001f49Smrg * Brian Paul 532001f49Smrg * 27 January 2006 632001f49Smrg */ 732001f49Smrg 832001f49Smrg#include <math.h> 932001f49Smrg#include <stdlib.h> 1032001f49Smrg#include <stdio.h> 1132001f49Smrg#include <string.h> 1232001f49Smrg#include "glut_wrap.h" 1332001f49Smrg 1432001f49Smrg#ifndef M_PI 1532001f49Smrg#define M_PI 3.14159265 1632001f49Smrg#endif 1732001f49Smrg 1832001f49Smrgstatic GLint WinWidth = 800, WinHeight = 500; 1932001f49Smrgstatic GLint TexWidth, TexHeight; 2032001f49Smrgstatic GLuint TexObj = 1; 2132001f49Smrgstatic GLenum IntFormat = GL_RGB; 2232001f49Smrg 2332001f49Smrgstatic GLboolean WireFrame = GL_FALSE; 2432001f49Smrg 2532001f49Smrgstatic GLint T0 = 0; 2632001f49Smrgstatic GLint Frames = 0; 2732001f49Smrgstatic GLint Win = 0; 2832001f49Smrg 2932001f49Smrgstatic GLfloat ViewRotX = 20.0, ViewRotY = 30.0, ViewRotZ = 0.0; 3032001f49Smrgstatic GLint Gear1, Gear2, Gear3; 3132001f49Smrgstatic GLfloat GearRot = 0.0; 3232001f49Smrgstatic GLfloat CubeRot = 0.0; 3332001f49Smrg 3432001f49Smrg 3532001f49Smrg/** 3632001f49Smrg Draw a gear wheel. You'll probably want to call this function when 3732001f49Smrg building a display list since we do a lot of trig here. 3832001f49Smrg 3932001f49Smrg Input: inner_radius - radius of hole at center 4032001f49Smrg outer_radius - radius at center of teeth 4132001f49Smrg width - width of gear 4232001f49Smrg teeth - number of teeth 4332001f49Smrg tooth_depth - depth of tooth 4432001f49Smrg **/ 4532001f49Smrgstatic void 4632001f49Smrggear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, 4732001f49Smrg GLint teeth, GLfloat tooth_depth) 4832001f49Smrg{ 4932001f49Smrg GLint i; 5032001f49Smrg GLfloat r0, r1, r2; 5132001f49Smrg GLfloat angle, da; 5232001f49Smrg GLfloat u, v, len; 5332001f49Smrg 5432001f49Smrg r0 = inner_radius; 5532001f49Smrg r1 = outer_radius - tooth_depth / 2.0; 5632001f49Smrg r2 = outer_radius + tooth_depth / 2.0; 5732001f49Smrg 5832001f49Smrg da = 2.0 * M_PI / teeth / 4.0; 5932001f49Smrg 6032001f49Smrg glShadeModel(GL_FLAT); 6132001f49Smrg 6232001f49Smrg glNormal3f(0.0, 0.0, 1.0); 6332001f49Smrg 6432001f49Smrg /* draw front face */ 6532001f49Smrg glBegin(GL_QUAD_STRIP); 6632001f49Smrg for (i = 0; i <= teeth; i++) { 6732001f49Smrg angle = i * 2.0 * M_PI / teeth; 6832001f49Smrg glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); 6932001f49Smrg glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); 7032001f49Smrg if (i < teeth) { 7132001f49Smrg glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); 7232001f49Smrg glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); 7332001f49Smrg } 7432001f49Smrg } 7532001f49Smrg glEnd(); 7632001f49Smrg 7732001f49Smrg /* draw front sides of teeth */ 7832001f49Smrg glBegin(GL_QUADS); 7932001f49Smrg da = 2.0 * M_PI / teeth / 4.0; 8032001f49Smrg for (i = 0; i < teeth; i++) { 8132001f49Smrg angle = i * 2.0 * M_PI / teeth; 8232001f49Smrg 8332001f49Smrg glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); 8432001f49Smrg glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); 8532001f49Smrg glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5); 8632001f49Smrg glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); 8732001f49Smrg } 8832001f49Smrg glEnd(); 8932001f49Smrg 9032001f49Smrg glNormal3f(0.0, 0.0, -1.0); 9132001f49Smrg 9232001f49Smrg /* draw back face */ 9332001f49Smrg glBegin(GL_QUAD_STRIP); 9432001f49Smrg for (i = 0; i <= teeth; i++) { 9532001f49Smrg angle = i * 2.0 * M_PI / teeth; 9632001f49Smrg glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); 9732001f49Smrg glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); 9832001f49Smrg if (i < teeth) { 9932001f49Smrg glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); 10032001f49Smrg glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); 10132001f49Smrg } 10232001f49Smrg } 10332001f49Smrg glEnd(); 10432001f49Smrg 10532001f49Smrg /* draw back sides of teeth */ 10632001f49Smrg glBegin(GL_QUADS); 10732001f49Smrg da = 2.0 * M_PI / teeth / 4.0; 10832001f49Smrg for (i = 0; i < teeth; i++) { 10932001f49Smrg angle = i * 2.0 * M_PI / teeth; 11032001f49Smrg 11132001f49Smrg glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); 11232001f49Smrg glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5); 11332001f49Smrg glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); 11432001f49Smrg glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); 11532001f49Smrg } 11632001f49Smrg glEnd(); 11732001f49Smrg 11832001f49Smrg /* draw outward faces of teeth */ 11932001f49Smrg glBegin(GL_QUAD_STRIP); 12032001f49Smrg for (i = 0; i < teeth; i++) { 12132001f49Smrg angle = i * 2.0 * M_PI / teeth; 12232001f49Smrg 12332001f49Smrg glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); 12432001f49Smrg glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); 12532001f49Smrg u = r2 * cos(angle + da) - r1 * cos(angle); 12632001f49Smrg v = r2 * sin(angle + da) - r1 * sin(angle); 12732001f49Smrg len = sqrt(u * u + v * v); 12832001f49Smrg u /= len; 12932001f49Smrg v /= len; 13032001f49Smrg glNormal3f(v, -u, 0.0); 13132001f49Smrg glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); 13232001f49Smrg glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); 13332001f49Smrg glNormal3f(cos(angle), sin(angle), 0.0); 13432001f49Smrg glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5); 13532001f49Smrg glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5); 13632001f49Smrg u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); 13732001f49Smrg v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); 13832001f49Smrg glNormal3f(v, -u, 0.0); 13932001f49Smrg glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); 14032001f49Smrg glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); 14132001f49Smrg glNormal3f(cos(angle), sin(angle), 0.0); 14232001f49Smrg } 14332001f49Smrg 14432001f49Smrg glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); 14532001f49Smrg glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); 14632001f49Smrg 14732001f49Smrg glEnd(); 14832001f49Smrg 14932001f49Smrg glShadeModel(GL_SMOOTH); 15032001f49Smrg 15132001f49Smrg /* draw inside radius cylinder */ 15232001f49Smrg glBegin(GL_QUAD_STRIP); 15332001f49Smrg for (i = 0; i <= teeth; i++) { 15432001f49Smrg angle = i * 2.0 * M_PI / teeth; 15532001f49Smrg glNormal3f(-cos(angle), -sin(angle), 0.0); 15632001f49Smrg glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); 15732001f49Smrg glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); 15832001f49Smrg } 15932001f49Smrg glEnd(); 16032001f49Smrg 16132001f49Smrg} 16232001f49Smrg 16332001f49Smrgstatic void 16432001f49Smrgcleanup(void) 16532001f49Smrg{ 16632001f49Smrg glDeleteTextures(1, &TexObj); 16732001f49Smrg glDeleteLists(Gear1, 1); 16832001f49Smrg glDeleteLists(Gear2, 1); 16932001f49Smrg glDeleteLists(Gear3, 1); 17032001f49Smrg glutDestroyWindow(Win); 17132001f49Smrg} 17232001f49Smrg 17332001f49Smrg 17432001f49Smrgstatic void 17532001f49SmrgDrawGears(void) 17632001f49Smrg{ 17732001f49Smrg if (WireFrame) { 17832001f49Smrg glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 17932001f49Smrg } 18032001f49Smrg 18132001f49Smrg glPushMatrix(); 18232001f49Smrg glRotatef(20/*ViewRotX*/, 1.0, 0.0, 0.0); 18332001f49Smrg glRotatef(ViewRotY, 0.0, 1.0, 0.0); 18432001f49Smrg glRotatef(ViewRotZ, 0.0, 0.0, 1.0); 18532001f49Smrg 18632001f49Smrg glPushMatrix(); 18732001f49Smrg glTranslatef(-3.0, -2.0, 0.0); 18832001f49Smrg glRotatef(GearRot, 0.0, 0.0, 1.0); 18932001f49Smrg glCallList(Gear1); 19032001f49Smrg glPopMatrix(); 19132001f49Smrg 19232001f49Smrg glPushMatrix(); 19332001f49Smrg glTranslatef(3.1, -2.0, 0.0); 19432001f49Smrg glRotatef(-2.0 * GearRot - 9.0, 0.0, 0.0, 1.0); 19532001f49Smrg glCallList(Gear2); 19632001f49Smrg glPopMatrix(); 19732001f49Smrg 19832001f49Smrg glPushMatrix(); 19932001f49Smrg glTranslatef(-3.1, 4.2, 0.0); 20032001f49Smrg glRotatef(-2.0 * GearRot - 25.0, 0.0, 0.0, 1.0); 20132001f49Smrg glCallList(Gear3); 20232001f49Smrg glPopMatrix(); 20332001f49Smrg 20432001f49Smrg glPopMatrix(); 20532001f49Smrg 20632001f49Smrg glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 20732001f49Smrg} 20832001f49Smrg 20932001f49Smrg 21032001f49Smrgstatic void 21132001f49SmrgDrawCube(void) 21232001f49Smrg{ 21332001f49Smrg static const GLfloat texcoords[4][2] = { 21432001f49Smrg { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } 21532001f49Smrg }; 21632001f49Smrg static const GLfloat vertices[4][2] = { 21732001f49Smrg { -1, -1 }, { 1, -1 }, { 1, 1 }, { -1, 1 } 21832001f49Smrg }; 21932001f49Smrg static const GLfloat xforms[6][4] = { 22032001f49Smrg { 0, 0, 1, 0 }, 22132001f49Smrg { 90, 0, 1, 0 }, 22232001f49Smrg { 180, 0, 1, 0 }, 22332001f49Smrg { 270, 0, 1, 0 }, 22432001f49Smrg { 90, 1, 0, 0 }, 22532001f49Smrg { -90, 1, 0, 0 } 22632001f49Smrg }; 22732001f49Smrg static const GLfloat mat[4] = { 1.0, 1.0, 0.5, 1.0 }; 22832001f49Smrg GLint i, j; 22932001f49Smrg 23032001f49Smrg glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat); 23132001f49Smrg glEnable(GL_TEXTURE_2D); 23232001f49Smrg 23332001f49Smrg glPushMatrix(); 23432001f49Smrg glRotatef(ViewRotX, 1.0, 0.0, 0.0); 23532001f49Smrg glRotatef(15, 1, 0, 0); 23632001f49Smrg glRotatef(CubeRot, 0, 1, 0); 23732001f49Smrg glScalef(4, 4, 4); 23832001f49Smrg 23932001f49Smrg for (i = 0; i < 6; i++) { 24032001f49Smrg glPushMatrix(); 24132001f49Smrg glRotatef(xforms[i][0], xforms[i][1], xforms[i][2], xforms[i][3]); 24232001f49Smrg glTranslatef(0, 0, 1.1); 24332001f49Smrg glBegin(GL_POLYGON); 24432001f49Smrg glNormal3f(0, 0, 1); 24532001f49Smrg for (j = 0; j < 4; j++) { 24632001f49Smrg glTexCoord2fv(texcoords[j]); 24732001f49Smrg glVertex2fv(vertices[j]); 24832001f49Smrg } 24932001f49Smrg glEnd(); 25032001f49Smrg glPopMatrix(); 25132001f49Smrg } 25232001f49Smrg glPopMatrix(); 25332001f49Smrg 25432001f49Smrg glDisable(GL_TEXTURE_2D); 25532001f49Smrg} 25632001f49Smrg 25732001f49Smrg 25832001f49Smrgstatic void 25932001f49Smrgdraw(void) 26032001f49Smrg{ 26132001f49Smrg float ar; 26232001f49Smrg 26332001f49Smrg glMatrixMode(GL_MODELVIEW); 26432001f49Smrg glLoadIdentity(); 26532001f49Smrg glTranslatef(0.0, 0.0, -40.0); 26632001f49Smrg 26732001f49Smrg /* clear whole depth buffer */ 26832001f49Smrg glDisable(GL_SCISSOR_TEST); 26932001f49Smrg glClear(GL_DEPTH_BUFFER_BIT); 27032001f49Smrg glEnable(GL_SCISSOR_TEST); 27132001f49Smrg 27232001f49Smrg /* clear upper-left corner of color buffer (unused space) */ 27332001f49Smrg glScissor(0, TexHeight, TexWidth, WinHeight - TexHeight); 27432001f49Smrg glClearColor(0.0, 0.0, 0.0, 0.0); 27532001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 27632001f49Smrg 27732001f49Smrg /* clear lower-left corner of color buffer */ 27832001f49Smrg glViewport(0, 0, TexWidth, TexHeight); 27932001f49Smrg glScissor(0, 0, TexWidth, TexHeight); 28032001f49Smrg glClearColor(1, 1, 1, 0); 28132001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 28232001f49Smrg 28332001f49Smrg /* draw gears in lower-left corner */ 28432001f49Smrg glMatrixMode(GL_PROJECTION); 28532001f49Smrg glLoadIdentity(); 28632001f49Smrg glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 60.0); 28732001f49Smrg glMatrixMode(GL_MODELVIEW); 28832001f49Smrg DrawGears(); 28932001f49Smrg 29032001f49Smrg /* copy color buffer to texture */ 29132001f49Smrg glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TexWidth, TexHeight); 29232001f49Smrg 29332001f49Smrg /* clear right half of color buffer */ 29432001f49Smrg glViewport(TexWidth, 0, WinWidth - TexWidth, WinHeight); 29532001f49Smrg glScissor(TexWidth, 0, WinWidth - TexWidth, WinHeight); 29632001f49Smrg glClearColor(0.5, 0.5, 0.8, 0.0); 29732001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 29832001f49Smrg 29932001f49Smrg /* draw textured cube in right half of window */ 30032001f49Smrg ar = (float) (WinWidth - TexWidth) / WinHeight; 30132001f49Smrg glMatrixMode(GL_PROJECTION); 30232001f49Smrg glLoadIdentity(); 30332001f49Smrg glFrustum(-ar, ar, -1.0, 1.0, 5.0, 60.0); 30432001f49Smrg glMatrixMode(GL_MODELVIEW); 30532001f49Smrg DrawCube(); 30632001f49Smrg 30732001f49Smrg /* finish up */ 30832001f49Smrg glutSwapBuffers(); 30932001f49Smrg 31032001f49Smrg Frames++; 31132001f49Smrg { 31232001f49Smrg GLint t = glutGet(GLUT_ELAPSED_TIME); 31332001f49Smrg if (t - T0 >= 5000) { 31432001f49Smrg GLfloat seconds = (t - T0) / 1000.0; 31532001f49Smrg GLfloat fps = Frames / seconds; 31632001f49Smrg printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); 31732001f49Smrg fflush(stdout); 31832001f49Smrg T0 = t; 31932001f49Smrg Frames = 0; 32032001f49Smrg } 32132001f49Smrg } 32232001f49Smrg} 32332001f49Smrg 32432001f49Smrg 32532001f49Smrgstatic void 32632001f49Smrgidle(void) 32732001f49Smrg{ 32832001f49Smrg static double t0 = -1.; 32932001f49Smrg double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; 33032001f49Smrg if (t0 < 0.0) 33132001f49Smrg t0 = t; 33232001f49Smrg dt = t - t0; 33332001f49Smrg t0 = t; 33432001f49Smrg 33532001f49Smrg /* fmod to prevent overflow */ 33632001f49Smrg GearRot = fmod(GearRot + 70.0 * dt, 360.0); /* 70 deg/sec */ 33732001f49Smrg CubeRot = fmod(CubeRot + 15.0 * dt, 360.0); /* 15 deg/sec */ 33832001f49Smrg 33932001f49Smrg glutPostRedisplay(); 34032001f49Smrg} 34132001f49Smrg 34232001f49Smrg 34332001f49Smrg/* change view angle, exit upon ESC */ 34432001f49Smrgstatic void 34532001f49Smrgkey(unsigned char k, int x, int y) 34632001f49Smrg{ 34732001f49Smrg (void) x; 34832001f49Smrg (void) y; 34932001f49Smrg switch (k) { 35032001f49Smrg case 'w': 35132001f49Smrg WireFrame = !WireFrame; 35232001f49Smrg break; 35332001f49Smrg case 'z': 35432001f49Smrg ViewRotZ += 5.0; 35532001f49Smrg break; 35632001f49Smrg case 'Z': 35732001f49Smrg ViewRotZ -= 5.0; 35832001f49Smrg break; 35932001f49Smrg case 27: /* Escape */ 36032001f49Smrg cleanup(); 36132001f49Smrg exit(0); 36232001f49Smrg break; 36332001f49Smrg default: 36432001f49Smrg return; 36532001f49Smrg } 36632001f49Smrg glutPostRedisplay(); 36732001f49Smrg} 36832001f49Smrg 36932001f49Smrg/* change view angle */ 37032001f49Smrgstatic void 37132001f49Smrgspecial(int k, int x, int y) 37232001f49Smrg{ 37332001f49Smrg (void) x; 37432001f49Smrg (void) y; 37532001f49Smrg switch (k) { 37632001f49Smrg case GLUT_KEY_UP: 37732001f49Smrg ViewRotX += 5.0; 37832001f49Smrg break; 37932001f49Smrg case GLUT_KEY_DOWN: 38032001f49Smrg ViewRotX -= 5.0; 38132001f49Smrg break; 38232001f49Smrg case GLUT_KEY_LEFT: 38332001f49Smrg ViewRotY += 5.0; 38432001f49Smrg break; 38532001f49Smrg case GLUT_KEY_RIGHT: 38632001f49Smrg ViewRotY -= 5.0; 38732001f49Smrg break; 38832001f49Smrg default: 38932001f49Smrg return; 39032001f49Smrg } 39132001f49Smrg glutPostRedisplay(); 39232001f49Smrg} 39332001f49Smrg 39432001f49Smrg 39532001f49Smrg/* new window size or exposure */ 39632001f49Smrgstatic void 39732001f49Smrgreshape(int width, int height) 39832001f49Smrg{ 39932001f49Smrg WinWidth = width; 40032001f49Smrg WinHeight = height; 40132001f49Smrg} 40232001f49Smrg 40332001f49Smrg 40432001f49Smrgstatic void 40532001f49Smrginit(int argc, char *argv[]) 40632001f49Smrg{ 40732001f49Smrg static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0}; 40832001f49Smrg static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0}; 40932001f49Smrg static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0}; 41032001f49Smrg static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0}; 41132001f49Smrg GLint i; 41232001f49Smrg 41332001f49Smrg glLightfv(GL_LIGHT0, GL_POSITION, pos); 41432001f49Smrg#if 0 41532001f49Smrg glEnable(GL_CULL_FACE); 41632001f49Smrg#endif 41732001f49Smrg glEnable(GL_LIGHTING); 41832001f49Smrg glEnable(GL_LIGHT0); 41932001f49Smrg glEnable(GL_DEPTH_TEST); 42032001f49Smrg 42132001f49Smrg /* make the gears */ 42232001f49Smrg Gear1 = glGenLists(1); 42332001f49Smrg glNewList(Gear1, GL_COMPILE); 42432001f49Smrg glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); 42532001f49Smrg gear(1.0, 4.0, 1.0, 20, 0.7); 42632001f49Smrg glEndList(); 42732001f49Smrg 42832001f49Smrg Gear2 = glGenLists(1); 42932001f49Smrg glNewList(Gear2, GL_COMPILE); 43032001f49Smrg glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); 43132001f49Smrg gear(0.5, 2.0, 2.0, 10, 0.7); 43232001f49Smrg glEndList(); 43332001f49Smrg 43432001f49Smrg Gear3 = glGenLists(1); 43532001f49Smrg glNewList(Gear3, GL_COMPILE); 43632001f49Smrg glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); 43732001f49Smrg gear(1.3, 2.0, 0.5, 10, 0.7); 43832001f49Smrg glEndList(); 43932001f49Smrg 44032001f49Smrg glEnable(GL_NORMALIZE); 44132001f49Smrg 44232001f49Smrg /* xxx make size dynamic */ 44332001f49Smrg TexWidth = 256; 44432001f49Smrg TexHeight = 256; 44532001f49Smrg 44632001f49Smrg glBindTexture(GL_TEXTURE_2D, TexObj); 44732001f49Smrg glTexImage2D(GL_TEXTURE_2D, 0, IntFormat, TexWidth, TexHeight, 0, 44832001f49Smrg GL_RGBA, GL_UNSIGNED_BYTE, NULL); 44932001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 45032001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 45132001f49Smrg glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 45232001f49Smrg 45332001f49Smrg for ( i=1; i<argc; i++ ) { 45432001f49Smrg if (strcmp(argv[i], "-info")==0) { 45532001f49Smrg printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 45632001f49Smrg printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 45732001f49Smrg printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); 45832001f49Smrg printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); 45932001f49Smrg } 46032001f49Smrg } 46132001f49Smrg} 46232001f49Smrg 46332001f49Smrg 46432001f49Smrgstatic void 46532001f49Smrgvisible(int vis) 46632001f49Smrg{ 46732001f49Smrg if (vis == GLUT_VISIBLE) 46832001f49Smrg glutIdleFunc(idle); 46932001f49Smrg else 47032001f49Smrg glutIdleFunc(NULL); 47132001f49Smrg} 47232001f49Smrg 47332001f49Smrg 47432001f49Smrgint 47532001f49Smrgmain(int argc, char *argv[]) 47632001f49Smrg{ 47732001f49Smrg glutInitWindowSize(WinWidth, WinHeight); 47832001f49Smrg glutInit(&argc, argv); 47932001f49Smrg glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); 48032001f49Smrg 48132001f49Smrg Win = glutCreateWindow("gearbox"); 48232001f49Smrg init(argc, argv); 48332001f49Smrg 48432001f49Smrg glutDisplayFunc(draw); 48532001f49Smrg glutReshapeFunc(reshape); 48632001f49Smrg glutKeyboardFunc(key); 48732001f49Smrg glutSpecialFunc(special); 48832001f49Smrg glutVisibilityFunc(visible); 48932001f49Smrg 49032001f49Smrg glutMainLoop(); 49132001f49Smrg return 0; /* ANSI C requires main to return int. */ 49232001f49Smrg} 493