Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int debug = 0, myGl = GL_LINEAR;
- SDL_Surface *flipSurface(SDL_Surface *surface);
- GLuint loadTextureNearest(const char *filename)
- {
- myGl = GL_NEAREST;
- return loadTexture(filename, false);
- }
- GLuint loadTexture(const char *filename, bool useMipMap)
- {
- GLuint glID;
- SDL_Surface *picture_surface, *gl_surface, *gl_fliped_surface;
- Uint32 rmask, gmask, bmask, amask;
- picture_surface = IMG_Load(filename);
- log(filename);
- if(picture_surface == NULL)
- return 0;
- log(filename);
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- rmask = 0xff000000;
- gmask = 0x00ff0000;
- bmask = 0x0000ff00;
- amask = 0x000000ff;
- #else
- rmask = 0x000000ff;
- gmask = 0x0000ff00;
- bmask = 0x00ff0000;
- amask = 0xff000000;
- #endif
- SDL_PixelFormat format = *(picture_surface->format);
- format.BitsPerPixel = 32;
- format.BytesPerPixel = 4;
- format.Rmask = rmask;
- format.Gmask = gmask;
- format.Bmask = bmask;
- format.Amask = amask;
- gl_surface = SDL_ConvertSurface(picture_surface, &format, SDL_SWSURFACE);
- gl_fliped_surface = flipSurface(gl_surface);
- /*glBindTexture(GL_TEXTURE_2D, 0); // free the old bind texture if deleted
- glGenTextures(1,&myTexture);//myTexture == 24 (as the glDelete was ok)
- glBindTexture(GL_TEXTURE_2D,myTexture);
- bIsTexture = glIsTexture(myTexture);*/
- glGenTextures(1, &glID);
- glBindTexture(GL_TEXTURE_2D, glID);
- if(useMipMap)
- {
- gluBuild2DMipmaps(GL_TEXTURE_2D, 4, gl_fliped_surface->w, gl_fliped_surface->h, GL_RGBA, GL_UNSIGNED_BYTE, gl_fliped_surface->pixels);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- }
- else
- {
- glTexImage2D(GL_TEXTURE_2D, 0, 4, gl_fliped_surface->w, gl_fliped_surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, gl_fliped_surface->pixels);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myGl);
- }
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myGl);
- SDL_FreeSurface(gl_fliped_surface);
- SDL_FreeSurface(gl_surface);
- SDL_FreeSurface(picture_surface);
- return glID;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement