Archived

This topic is now archived and is closed to further replies.

xlauvillx

Texture mapping question...

Recommended Posts

xlauvillx    122
I''m having a problem with a cTextureMap class I''m creating for my little practice engine I''m working on. If anyone has gone through NeHe''s texture map tutorial you''ll recognize some of the code here. The problem is that for some reason the texture will not bind to objects, or if it does bind.. it doesn''t show up. Here''s the class declaration... class cTextureMap { // file loading method... AUX_RGBImageRec *LoadBmpFile(char *tFilename); public: unsigned int Texture; // texture object cTextureMap(char *filename); // constructor ~cTextureMap(){} // destructor }; Here are the methods... // File loading function... AUX_RGBImageRec *cTextureMap::LoadBmpFile(char *Filename) { FILE *File=NULL; // File Handle if (!Filename) // Make sure a filename was given { return NULL; // If not, return Null } File=fopen(Filename,"r"); // see if the file exists if (File) // does the file exist? { fclose(File); // Close the handle return auxDIBImageLoad(Filename); // Load the bitmap and return a pointer } return NULL; } // constructor sets up the Texture property for the object cTextureMap::cTextureMap(char *filename) { AUX_RGBImageRec *TextureImage[1]; memset(TextureImage,0,sizeof(void *)*1); if (TextureImage[0]=LoadBmpFile(filename)) { glGenTextures(1, &Texture); glBindTexture(GL_TEXTURE_2D, Texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); } if (TextureImage[0]) // if texture exists { if (TextureImage[0]->data) { free(TextureImage[0]->data); } free(TextureImage[0]); } } Then in my globals i set up a texture... cTextureMap tRock("rock.bmp"); That should place the data from "rock.bmp" into tRock.Texture right? Then when i try to bind that texture to my object... glBindTexture(GL_TEXTURE_2D, tRock.Texture); glBegin(GL_QUADS); glVertex etc, etc... glEnd(); It doesn''t work... Please help me find the problem!!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
That is wrong because you are loading the texture before you have an OpenGL context. Since your object is global, it will be created before you have an OpenGL context which means that when you try to upload your texture nothing will happen.

Nate

Share this post


Link to post
Share on other sites