lesson 6 question (SDL)
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.
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
Popular Topics
Advertisement