lesson 6 question (SDL)

Started by
3 comments, last by Lutyo 18 years, 6 months ago
in the texture lesson, the blue NeHe bitmap turned brown, anyone know why?
Advertisement
Looks blue to me.
If you have not changed any code and just run the program and it turns brown, chances are theres something wrong with your computer. Try restarting first, then if that does not fix it, update your video drivers.
the Visual C++ one was blue, but the SDL one was brown.
Well, the pixel data is stored in b, g, r(blue, green, red) format in a bmp file. SDL_LoadBMP does not change this order, you have to convert it to r, g, b. Somehow this part is missing from lesson 6. Here is a simple example:

int TEXTURE::LoadBMP(const char *fname){  int i, size;  unsigned char *data, swp;    SDL_Surface *bmp;    bmp=SDL_LoadBMP(fname);    if(!bmp)    return 0;    if(bmp->format->BitsPerPixel!=24)    {    SDL_FreeSurface(bmp);    return 0;    }    size=3*bmp->w*bmp->h;        //we change bgr to rgb  data=(unsigned char*)bmp->pixels;  for(i=0;i<size;i+=3)    {    swp=data;    data=data[i+2];    data[i+2]=swp;    }    glGenTextures(1,&id);  glBindTexture(GL_TEXTURE_2D,id);    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,bmp->w,bmp->h,0,GL_RGB,GL_UNSIGNED_BYTE,data);  SDL_FreeSurface(bmp);  return 1;}

This topic is closed to new replies.

Advertisement