Advertisement
Benjamin_Loison

GLuint loadTextureNearest() and GLuint loadTexture(const cha

Jul 12th, 2017
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. int debug = 0, myGl = GL_LINEAR;
  2.  
  3. SDL_Surface *flipSurface(SDL_Surface *surface);
  4.  
  5. GLuint loadTextureNearest(const char *filename)
  6. {
  7.     myGl = GL_NEAREST;
  8.     return loadTexture(filename, false);
  9. }
  10.  
  11. GLuint loadTexture(const char *filename, bool useMipMap)
  12. {
  13.     GLuint glID;
  14.     SDL_Surface *picture_surface, *gl_surface, *gl_fliped_surface;
  15.     Uint32 rmask, gmask, bmask, amask;
  16.     picture_surface = IMG_Load(filename);
  17.     log(filename);
  18.     if(picture_surface == NULL)
  19.         return 0;
  20.     log(filename);
  21.     #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  22.         rmask = 0xff000000;
  23.         gmask = 0x00ff0000;
  24.         bmask = 0x0000ff00;
  25.         amask = 0x000000ff;
  26.     #else
  27.         rmask = 0x000000ff;
  28.         gmask = 0x0000ff00;
  29.         bmask = 0x00ff0000;
  30.         amask = 0xff000000;
  31.     #endif
  32.     SDL_PixelFormat format = *(picture_surface->format);
  33.     format.BitsPerPixel = 32;
  34.     format.BytesPerPixel = 4;
  35.     format.Rmask = rmask;
  36.     format.Gmask = gmask;
  37.     format.Bmask = bmask;
  38.     format.Amask = amask;
  39.     gl_surface = SDL_ConvertSurface(picture_surface, &format, SDL_SWSURFACE);
  40.     gl_fliped_surface = flipSurface(gl_surface);
  41.  
  42.     /*glBindTexture(GL_TEXTURE_2D, 0); // free the old bind texture if deleted
  43.     glGenTextures(1,&myTexture);//myTexture == 24 (as the glDelete was ok)
  44.     glBindTexture(GL_TEXTURE_2D,myTexture);
  45.     bIsTexture = glIsTexture(myTexture);*/
  46.  
  47.     glGenTextures(1, &glID);
  48.     glBindTexture(GL_TEXTURE_2D, glID);
  49.     if(useMipMap)
  50.     {
  51.         gluBuild2DMipmaps(GL_TEXTURE_2D, 4, gl_fliped_surface->w, gl_fliped_surface->h, GL_RGBA, GL_UNSIGNED_BYTE, gl_fliped_surface->pixels);
  52.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  53.     }
  54.     else
  55.     {
  56.         glTexImage2D(GL_TEXTURE_2D, 0, 4, gl_fliped_surface->w, gl_fliped_surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, gl_fliped_surface->pixels);
  57.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myGl);
  58.     }
  59.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myGl);
  60.     SDL_FreeSurface(gl_fliped_surface);
  61.     SDL_FreeSurface(gl_surface);
  62.     SDL_FreeSurface(picture_surface);
  63.     return glID;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement