Jump to content

  • Log In with Google      Sign In   
  • Create Account


Texture mapping question...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 xlauvillx   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 September 2001 - 03:05 PM

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!!

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 02 September 2001 - 04:49 PM

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

#3 xlauvillx   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 September 2001 - 05:11 PM

YES! Thanks Nate for seeing my mistake... it works perfectly now.

Thanks




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS