Sign in to follow this  

opengl bitmap textures problem

Recommended Posts

have been having problems creating textures from bitmaps in opengl it works fine using bitmaps i've downloaded (the ones included with nehe tutorials) however when i try creating my own in paint the program doesnt display them (just shows a white box) texture loading functions (straight from nehe)
AUX_RGBImageRec *LoadBMP(char *Filename)
   FILE *File = NULL;      //filehandle

   if(!Filename) {         //make sure a filename was given

   File = fopen(Filename, "r");     //check to see if file exists

   if(File) {
      return(auxDIBImageLoad(Filename));     //loads the bitmap and returns a pointer


int LoadGLTextures(void)
   int Status = FALSE;

   AUX_RGBImageRec *TextureImage[1];      //create storage space for texture

   memset(TextureImage, 0, sizeof(void *)*1);      //set the pointer to NULL (make sure its empty)

   //load bitmap, if bitmaps not found quit
   if(TextureImage[0]=LoadBMP("data/tri.bmp")) {
      Status = TRUE;

      glGenTextures(1, &texture[0]);      //create the texture

      //typical texture generation using data from the bitmap
      glBindTexture(GL_TEXTURE_2D, texture[0]);

      //texture filters

      //generate the texture
      glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

      if(TextureImage[0]) {                     //if texture exists
         if(TextureImage[0]->data) {            //if texture image exists
            free(TextureImage[0]->data);        //free the texture image memory

         free(TextureImage[0]);                 //free the image structure


relevant SDL init code
   //set up SDL/GL window properties
   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);

only thing i can think of is its something to do with that bitmaps rgba values, both bitmaps (nehe and mine) are 24bit and have tried changing the SDL bitmap settings above to r=8, g=8, b=8 but still get the same anyone know what paint saves bitmaps as or what i'm missing (or anyway to get opengl to load any type of bitmap)? thanks

Share this post

Link to post
Share on other sites
The problem is probably that you don't have the right dimensions...All textures need to be dimensions that are powers of two (2,4,8,16,32,64,128,256...1024...). If they are off, you will not be able to load the texture.

Share this post

Link to post
Share on other sites

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