diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-05-16 21:44:32 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-05-16 21:44:32 +0200 |
commit | a524cfdd2756ac945040ca9bed576fb2f68f8c9f (patch) | |
tree | 000874591e87ae5ce7f162214337b49bc1ba0e0b /texture.cpp |
Imported project.
Diffstat (limited to 'texture.cpp')
-rw-r--r-- | texture.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/texture.cpp b/texture.cpp new file mode 100644 index 0000000..ca9d8e7 --- /dev/null +++ b/texture.cpp @@ -0,0 +1,29 @@ +#ifndef __APPLE__ +#include <GL/gl.h> +#include <GL/glut.h> +#else +#include <OpenGL/gl.h> +#include <GLUT/glut.h> +#endif +#include <stdexcept> +#include "texture.h" +#include <stdio.h> + +unsigned int Texture::tex() { + return texture; +} + +void Texture::build() { + if(!data) { + throw(std::runtime_error("No texture data")); + } + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + if(byte_per_pixel == 4) { + gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); + } else if(byte_per_pixel == 3) { + gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data); + } +} |