Sign in to follow this  

Strange thing loading bmp textures

This topic is 3502 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I use to load bmp textures with: //--[---------------------------------------------] //--[ FILE : GFXBMP.H ] //--[ AUTHOR : WILLIE TANG (willietang@hehe.com) ] //--[ STARTED : 01.05.2003 ] //--[ UPDATED : 01.05.2003 ] //--[---------------------------------------------] #include <stdlib.h> #include <stdio.h> //--[ GLOBAL VARIABLES ]--------------------------> UINT TextureArray[1] = {0}; //--[ FUNCTION PROTOTYPES ]-----------------------> BOOL BitmapLoad(char*,UINT); //--[ FUNCTION IMPLEMENTATION ]-------------------> //--[ BOOL BitmapLoad(char*,UINT) BOOL BitmapLoad(char* Filename, UINT Index) { AUX_RGBImageRec *Bitmap = NULL; FILE *FileHandle = NULL; FileHandle = fopen(Filename,"rb"); if(FileHandle != NULL) { Bitmap = auxDIBImageLoad(Filename); } else { fclose(FileHandle); return(FALSE); } fclose(FileHandle); glGenTextures(1, &TextureArray[Index]); glBindTexture(GL_TEXTURE_2D, TextureArray[Index]); // Build Mipmaps gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Bitmap->sizeX, Bitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, Bitmap->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); if (Bitmap) { if (Bitmap->data) { free(Bitmap->data); } free(Bitmap); } return(TRUE); } Loading with: if(BitmapLoad("grasshex2.bmp", 0) == false) // Ok = grass std::cerr << "Problem with texture"; if(BitmapLoad("grasshex2.bmp", 1) == false) // white color std::cerr << "Problem with texture"; if(BitmapLoad("stone.bmp", 2) == false) // white color std::cerr << "Problem with texture"; if(BitmapLoad("waterhex.bmp", 3) == false) // OK = water std::cerr << "Problem with texture"; if(BitmapLoad("orcs.bmp", 4) == false) // white color std::cerr << "Problem with texture"; if(BitmapLoad("wood.bmp", 5) == false) // white color std::cerr << "Problem with texture"; if(BitmapLoad("wood.bmp", 6) == false) // OK = wood std::cerr << "Problem with texture"; if(BitmapLoad("orcs.bmp", 7) == false) // white color std::cerr << "Problem with texture"; if(BitmapLoad("wood.bmp", 8) == false) // white color std::cerr << "Problem with texture"; if(BitmapLoad("stone.bmp", 9) == false) // OK = stone std::cerr << "Problem with texture"; } And then using glBindTexture( GL_TEXTURE_2D, TextureArray[x] ); Now, this program was working fine but suddenly without changing anything only index [0] and [3] and [6] and [9] giving me the texture that I want.( see above) The rest of the loaded textures giving me just a white flat color. How could this be? As You can see I used the same texture several times to be sure that it got nothing to do with the textures themselves. Any Ideas? Thank You, RenRan

Share this post


Link to post
Share on other sites
first thing I see is:

UINT TextureArray[1] = {0};

you have only allocated 1 space for the 9 texture ids you want to store
and refer to at render time.

UINT TextureArray[9] = {0};

That might solve your problem;

Share this post


Link to post
Share on other sites
Thank You Steven, Ok that did the trick.
Everything is OK now.
I didn't see that, on the other hand I'm rather "new" with C++.

Thanks,

RenRan

Share this post


Link to post
Share on other sites

This topic is 3502 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this