Advertisement

Texture Mapping problems

Started by December 26, 2003 01:51 AM
0 comments, last by Running_Wolf 21 years, 2 months ago
Okay, newbie here. I searched the previous posts and couldn''t find what I was looking for so I made a new post. The problem is I am trying to make a class to load as many textures as I would like but I am having problems. When I run a test program all I get is a white quad. Following is my code for the class. Please help is you know what might be the problem. Thanks. class GTexture { private: UINT *TextureData; TGAImage *LoadTGA(char *filename); public: void AllocTexMemory(UINT num_tex); bool CreateTexture(LPSTR filename, int textureID); void SwitchToTexture(int textureID); ~GTexture(); }; void GTexture::AllocTexMemory(UINT num_tex) { TextureData = new UINT[num_tex]; glEnable(GL_TEXTURE_2D); } GTexture::~GTexture() { glDeleteTextures(1, &TextureData[0]); } bool GTexture::CreateTexture(LPSTR filename, int textureID) { AUX_RGBImageRec *pBitmap = NULL; if (!filename) return false; //Load the texture data using GLAUX lib. pBitmap = auxDIBImageLoad(filename); if (pBitmap == NULL) return false; glGenTextures(1, &TextureData[textureID]); glBindTexture(GL_TEXTURE_2D, TextureData[textureID]); glTexImage2D(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); if (pBitmap) { if (pBitmap->data) free(pBitmap->data); free(pBitmap); } return true; } void GTexture::SwitchToTexture(int textureID) { glBindTexture(GL_TEXTURE_2D, TextureData[textureID]); }
L.I.G. == Life Is Good
ok heres what first struck me:

glTexImage2D(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);


the second argument, the level, you have as 3. the level is the mipmap level, starting at 0 for the original texture.. 1 is half the size (the first mipmap level), 2 1/4, etc.

so, you have created a texture, and filled in the 3rd mipmap level...

nothing else however..

so, change that to 0:

glTexImage2D(GL_TEXTURE_2D, 0, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);

and to auto gen the remaining mipmap levels, use gluBuild2DMipmaps...

eg:

gluBuild2DMipmaps(GL_TEXTURE_2D,3,pBitmap->sizeX,pBitmap->sizeY,GL_RGB,GL_UNSINGED_BYTE,pBitmap->data);

put that after the glTexImage2D call..

and btw you really don''t need an array of unsigned ints.. since you will only have one texture per GTexture object... so just make it a single unsigned int and be done with that that way you won''t need the ''AllocTexMemory'' call either.



| - Project-X - | - adDeath - | - my windows XP theme - | - email me - |

This topic is closed to new replies.

Advertisement