Created
January 5, 2013 07:00
-
-
Save tuttlem/4460230 to your computer and use it in GitHub Desktop.
texture class load
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SDL_Surface *surface = NULL; | |
if ((surface = IMG_Load(filename.c_str()))) { | |
_colours = surface->format->BytesPerPixel; | |
// get the image format | |
if (_colours == 4) { | |
if (surface->format->Rmask == 0x000000ff) { | |
_format = GL_RGBA; | |
} else { | |
_format = GL_BGRA; | |
} | |
} else if (_colours == 3) { | |
if (surface->format->Rmask == 0x000000ff) { | |
_format = GL_RGB; | |
} else { | |
_format = GL_BGR; | |
} | |
} | |
// generate the gl texture | |
glGenTextures(1, &_texture); | |
glBindTexture(GL_TEXTURE_2D, _texture); | |
// set filter parameters | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
// send the loaded binary into open gl | |
glTexImage2D(GL_TEXTURE_2D, 0, _colours, | |
surface->w, surface->h, | |
0, _format, | |
GL_UNSIGNED_BYTE, surface->pixels); | |
SDL_FreeSurface(surface); | |
} else { | |
return false; | |
} | |
return true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment