diff options
-rw-r--r-- | include/Texture.h | 22 | ||||
-rw-r--r-- | src/Texture.cpp | 40 |
2 files changed, 62 insertions, 0 deletions
diff --git a/include/Texture.h b/include/Texture.h new file mode 100644 index 0000000..45c8df1 --- /dev/null +++ b/include/Texture.h @@ -0,0 +1,22 @@ +#ifndef TEXTURE_H +#define TEXTURE_H + +#include <common.h> + +namespace Texture{ + GLuint loadTexture(const char *fileName); +} + +class Texturec{ +public: + Texturec(uint amt, ...); + void bindNext(); + void bindPrev(); + + GLuint *image; +private: + int texState; + +}; + +#endif //TEXTURE_H
\ No newline at end of file diff --git a/src/Texture.cpp b/src/Texture.cpp new file mode 100644 index 0000000..93a3792 --- /dev/null +++ b/src/Texture.cpp @@ -0,0 +1,40 @@ +#include <Texture.h> + +namespace Texture{ + GLuint loadTexture(const char *fileName){ + SDL_Surface *image = IMG_Load(fileName); + + if(!image)return 0; + DEBUG_printf("Loaded image file: %s\n", fileName); + unsigned object = 0; //creates a new unsigned variable for the texture + + glGenTextures(1, &object); //turns "object" into a texture + glBindTexture(GL_TEXTURE_2D, object); //binds "object" to the top of the stack + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //sets the "min" filter + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //the the "max" filter of the stack + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //Wrap the texture to the matrix + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //Wrap the texutre to the matrix + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); //sets the texture to the image file loaded above + + SDL_FreeSurface(image); //Free surface + return object; + } +} + +Texturec::Texturec(uint amt, ...){ + image = new GLuint(amt); + va_list fNames; + va_start(fNames, amt); + for(int i = 0; i < amt; i++){ + char* f = va_arg(fNames, char*); + image[i] = Texture::loadTexture(f); + } + va_end(fNames); +} + +void Texturec::bindNext(){ + //glBindTexture(GL_TEXTURE_2D); +}
\ No newline at end of file |