Advertisement
thecplusplusguy

load texture to OpenGL

Jul 24th, 2012
1,559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. unsigned int loadTexture(const char* name)
  2. {
  3.     SDL_Surface* img=IMG_Load(name);
  4.     SDL_PixelFormat form={NULL,32,4,0,0,0,0,8,8,8,8,0xff000000,0x00ff0000,0x0000ff00,0x000000ff,0,255};
  5.     SDL_Surface* img2=SDL_ConvertSurface(img,&form,SDL_SWSURFACE);
  6.     unsigned int texture;
  7.     glGenTextures(1,&texture);
  8.     glBindTexture(GL_TEXTURE_2D,texture);
  9.     glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,img2->w,img2->h,0,GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,img2->pixels);
  10.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  11.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  12.     SDL_FreeSurface(img);
  13.     SDL_FreeSurface(img2);
  14.     return texture;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement