Skip to content

Instantly share code, notes, and snippets.

@tuttlem
Created January 5, 2013 07:00
Show Gist options
  • Save tuttlem/4460230 to your computer and use it in GitHub Desktop.
Save tuttlem/4460230 to your computer and use it in GitHub Desktop.
texture class load
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