From 267bebfc227c94f543a39e2aa75fb101bc06932e Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Fri, 21 May 2010 19:24:51 +0200 Subject: Moved engine-sources to seperate subdirectory. --- engine/texture.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 engine/texture.cpp (limited to 'engine/texture.cpp') diff --git a/engine/texture.cpp b/engine/texture.cpp new file mode 100644 index 0000000..ca9d8e7 --- /dev/null +++ b/engine/texture.cpp @@ -0,0 +1,29 @@ +#ifndef __APPLE__ +#include +#include +#else +#include +#include +#endif +#include +#include "texture.h" +#include + +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); + } +} -- cgit v1.2.3