Jump to content
  • Advertisement
Sign in to follow this  
SpacedOut

lesson 6 question (SDL)

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

Advertisement
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.

Share this post


Link to post
Share on other sites
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;
}

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!