   SDL loads wrong bitmap color??
  I'm using SDL for the first time today, and I've got my model loaded and textured using SDL_LoadBitmap(). What I'm noticing, though, is that all the shades of red become shades of blue. All other colors look fine. Can someone confirm if there is something wrong the SDL_LoadBitmap()?dfiHere's the relevant code, if anyone's curiousSDL_Surface* p_bmpImage = SDL_LoadBMP( k_szFilename );glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );glGenTextures( 1, &m_iTexture );glBindTexture( GL_TEXTURE_2D, m_iTexture );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, p_bmpImage->w, p_bmpImage->h, 0, GL_RGB, GL_UNSIGNED_BYTE, p_bmpImage->pixels );SDL_FreeSurface( p_bmpImage );   
  use GL_BGR instad of GL_RGB in glTexImage2D() for TGA files   ;  There is Nothing Wrong with SDL_LoadBItmap function. THe thing is the Function Store the Pixel Color of the Bitmap BakcWards, you can Flip it by doing this.SDL_Surface *pBitmap[1];    if( strFileName == NULL )  // Return from the function if no file name was passed in   return ;    // We need to load the texture data, so we use a cool function that SDL offers.pBitmap[0] = SDL_LoadBMP(strFileName);    // Load the bitmap and store the data    if(pBitmap[0] == NULL)  // If we can't load the file, quit!    {   cerr << " Failed loading " << strFileName << " : " << SDL_GetError() << endl;   Quit(0);    }    // Generate a texture with the associative texture ID stored in the array    glGenTextures(1, &textureArray[textureID]);   .    // Bind the texture to the texture arrays index and init the texture    glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);int width  = pBitmap[0] -> w;    int height = pBitmap[0] -> h;    unsigned char * data = (unsigned char *) (pBitmap[0] -> pixels);    // the pixel data    unsigned char * newData = new unsigned char[width*height*3];    int channels = 3; // R,G,B    int BytesPerPixel = pBitmap[0] -> format -> BytesPerPixel ;for( int i = 0 ; i < (height / 2) ; ++i )   for( int j = 0 ; j < width * BytesPerPixel; j += BytesPerPixel )  for(int k = 0; k < BytesPerPixel; ++k) swap( data[ (i * width * BytesPerPixel) + j + k], data[ ( (height - i - 1) * width * BytesPerPixel ) + j + k]); for(int i = 0; i < (width * height); ++i)    {   byte r,g,b;   // R,G and B that we will put into pImage   Uint32 pixel_value = 0; // 32 bit unsigned int (as dictated by SDL)    for(int j = BytesPerPixel - 1 ; j >=0; --j) // for each byte in the pixel (from the right)   {  pixel_value = pixel_value << 8;    // left shift pixel value by 8 bits  pixel_value = pixel_value | data[ (i * BytesPerPixel) + j ];   }   SDL_GetRGB(pixel_value, pBitmap[0] -> format, (Uint8 *)&r, (Uint8 *)&g, (Uint8 *)&b);// here we get r,g,b from pixel_value which is stored in the form specified by pBitmap->format   newData[(i * channels) + 0] = r;// in our tImage classes we store r first   newData[(i * channels) + 1] = g;// then g   newData[(i * channels) + 2] = b;// and finally b (for bmps - three channels only)   pixel_value = 0;   // reset pixel , else we get incorrect values of r,g,b    }    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap[0]->w, pBitmap[0]->h, GL_RGB, GL_UNSIGNED_BYTE, newData);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);delete [] newData;SDL_FreeSurface(pBitmap[0]);   ;  Whoa, those were some fast replys! Great catch guys, I totally missed that! Thanks.dfi   ;Quote:Original post by BornToCodeThere is Nothing Wrong with SDL_LoadBItmap function. THe thing is the Function Store the Pixel Color of the Bitmap BakcWards, you can Flip it by doing this.SDL_Surface *pBitmap[1];    if( strFileName == NULL )  // Return from the function if no file name was passed in   return ;    // We need to load the texture data, so we use a cool function that SDL offers.pBitmap[0] = SDL_LoadBMP(strFileName);    // Load the bitmap and store the data    if(pBitmap[0] == NULL)  // If we can't load the file, quit!    {   cerr << " Failed loading " << strFileName << " : " << SDL_GetError() << endl;   Quit(0);    }    // Generate a texture with the associative texture ID stored in the array    glGenTextures(1, &textureArray[textureID]);   .    // Bind the texture to the texture arrays index and init the texture    glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);int width  = pBitmap[0] -> w;    int height = pBitmap[0] -> h;    unsigned char * data = (unsigned char *) (pBitmap[0] -> pixels);    // the pixel data    unsigned char * newData = new unsigned char[width*height*3];    int channels = 3; // R,G,B    int BytesPerPixel = pBitmap[0] -> format -> BytesPerPixel ;for( int i = 0 ; i < (height / 2) ; ++i )   for( int j = 0 ; j < width * BytesPerPixel; j += BytesPerPixel )  for(int k = 0; k < BytesPerPixel; ++k) swap( data[ (i * width * BytesPerPixel) + j + k], data[ ( (height - i - 1) * width * BytesPerPixel ) + j + k]); for(int i = 0; i < (width * height); ++i)    {   byte r,g,b;   // R,G and B that we will put into pImage   Uint32 pixel_value = 0; // 32 bit unsigned int (as dictated by SDL)    for(int j = BytesPerPixel - 1 ; j >=0; --j) // for each byte in the pixel (from the right)   {  pixel_value = pixel_value << 8;    // left shift pixel value by 8 bits  pixel_value = pixel_value | data[ (i * BytesPerPixel) + j ];   }   SDL_GetRGB(pixel_value, pBitmap[0] -> format, (Uint8 *)&r, (Uint8 *)&g, (Uint8 *)&b);// here we get r,g,b from pixel_value which is stored in the form specified by pBitmap->format   newData[(i * channels) + 0] = r;// in our tImage classes we store r first   newData[(i * channels) + 1] = g;// then g   newData[(i * channels) + 2] = b;// and finally b (for bmps - three channels only)   pixel_value = 0;   // reset pixel , else we get incorrect values of r,g,b    }    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap[0]->w, pBitmap[0]->h, GL_RGB, GL_UNSIGNED_BYTE, newData);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);delete [] newData;SDL_FreeSurface(pBitmap[0]);Just use GL_BGR, it's ALOT easier [smile]   ;  the way i found to guarentee that all your images are in the right format, is ti convert the image to a RGB format after you load it. SDL has a function that does just this.SDL_Surface *temp = SDL_LoadBMP("some_img.xxx");    SDL_Surface *surface;    Uint32 rmask, gmask, bmask, amask;    /* SDL interprets each pixel as a 32-bit number, so our masks must depend  on the endianness (byte order) of the machine */#if SDL_BYTEORDER == SDL_BIG_ENDIAN    rmask = 0xff000000;    gmask = 0x00ff0000;    bmask = 0x0000ff00;    amask = 0x000000ff;#else    rmask = 0x000000ff;    gmask = 0x0000ff00;    bmask = 0x00ff0000;    amask = 0xff000000;#endif    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,rmask, gmask, bmask, amask);SDL_BlitSurface(temp,NULL,surface,NULL);SDL_FreeSurface(temp);//now surface is in RGB format!