Jump to content
  • Advertisement
Sign in to follow this  
jaikc

opengl bitmap textures problem

This topic is 5039 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

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
      return(NULL);
   }

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

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

   return(NULL);
}

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
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

      //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
      }
   }

   return(Status);
}

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);
   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!