#include "Club.h" #include #include //#include #include #define PI 3.14159 //#define BITMAP_ID 0x4D42 // the universal bitmap ID // Prototype //static unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader); const double Club::DEF_SLOPE = 0.5; const double Club::SCALE = 1.0; Club::Club(double slope) : hClub(0), hTexture(0), slope_(slope) { // Nothing (more) to do } void Club::initializeGraphics() { //// Read in the texture. //// The file name is hard-coded //// is hard-coded as club.bmp //BITMAPINFOHEADER bitmapInfoHeader; // bitmap info header //unsigned char* bitmapData; // the bitmap data //bitmapData = LoadBitmapFile("club.bmp", &bitmapInfoHeader); //// generate texture object //unsigned int hTexture; //glGenTextures(1,&hTexture); //// create texture //glEnable(GL_TEXTURE_2D); //glBindTexture(GL_TEXTURE_2D, hTexture); //// the following two commands tell openGL how to interpolate texture //// values between the sampled values in your texture bitmap //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //// the following two commands tell openGL how to extend the texture //// when needed //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //// replace color of textured object //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //// now give it the texture map //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmapInfoHeader.biWidth, // bitmapInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, // bitmapData); // Define a few handy colors GLfloat gray9[] = {0.9, 0.9, 0.9, 1.0}; GLfloat gray8[] = {0.8, 0.8, 0.8, 1.0}; GLfloat gray5[] = {0.5, 0.5, 0.5, 1.0}; GLfloat gray4[] = {0.4, 0.4, 0.4, 1.0}; GLfloat gray3[] = {0.3, 0.3, 0.3, 1.0}; GLfloat brown[] = {0.5, 0.4, 0.2, 1.0}; // initialize the club display list // the geometry is created once at initialization hClub = glGenLists(1); glNewList(hClub, GL_COMPILE); // // draw the shaft of the club with its texture // // enable & bind the texture // glEnable(GL_TEXTURE_2D); // glBindTexture(GL_TEXTURE_2D, hTexture); // position and orient the shaft glPushMatrix(); glTranslatef(SCALE * 0.1f, SCALE * 0.4f, SCALE * 0.0f); glRotatef(10.0f,0.0f,0.0f,1.0f); // create the cylinder int numStrips=10; float topRadius=SCALE * 0.2; float bottomRadius=SCALE * 0.1; float clubHeight=SCALE * 5.0; glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,brown); glBegin(GL_QUAD_STRIP); for (int i=0;ibiSizeImage); // // // verify memory allocation // if (!bitmapImage) // { // free(bitmapImage); // fclose(filePtr); // return NULL; // } // // // read in the bitmap image data // fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr); // // // make sure bitmap image data was read // if (bitmapImage == NULL) // { // fclose(filePtr); // return NULL; // } // // // swap the R and B values to get RGB since the bitmap color format is in BGR // for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3) // { // tempRGB = bitmapImage[imageIdx]; // bitmapImage[imageIdx] = bitmapImage[imageIdx + 2]; // bitmapImage[imageIdx + 2] = tempRGB; // } // // // close the file and return the bitmap image data // fclose(filePtr); // return bitmapImage; //}