Created
May 19, 2013 17:48
-
-
Save kcbanner/5608395 to your computer and use it in GitHub Desktop.
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
Texture2D::Texture2D(Resource* image, | |
GLenum wrapping_mode, | |
GLenum min_mag_filter):Texture(GL_TEXTURE_2D) { | |
unsigned error; | |
unsigned char* imageData; | |
unsigned w, h; | |
GLenum texture_format; | |
// | |
// Load PNG | |
// | |
texture_format = GL_RGBA; | |
error = LodePNG_decode32(&imageData, &w, &h, | |
(const unsigned char*)image->get_data(), | |
image->get_size()); | |
if (error) { | |
throw Exception("PNG load error: " + std::string(LodePNG_error_text(error))); | |
} | |
width_ = w; | |
height_ = h; | |
Bind(); | |
SetParameteri(GL_TEXTURE_MIN_FILTER, min_mag_filter); | |
SetParameteri(GL_TEXTURE_MAG_FILTER, min_mag_filter); | |
SetParameteri(GL_TEXTURE_WRAP_S, wrapping_mode); | |
SetParameteri(GL_TEXTURE_WRAP_T, wrapping_mode); | |
glTexImage2D(target_, | |
0, texture_format, | |
width_, height_, | |
0, texture_format, GL_UNSIGNED_BYTE, | |
imageData); | |
glGenerateMipmap(GL_TEXTURE_2D); | |
free(imageData); | |
Unbind(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment