From c6739a753e31e8d239b662fbfc7d9ac7e7c0621e Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Thu, 22 Oct 2015 09:23:08 -0400 Subject: Commented more of entities, added new texture namespace and class --- include/common.h | 7 ++++++- include/entities.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/common.h b/include/common.h index d5f1456..e46cf86 100644 --- a/include/common.h +++ b/include/common.h @@ -21,6 +21,11 @@ #include #include +/* + * Include file headers +*/ +#include + /* * Create a basic 2-point structure for coordinate saving */ @@ -88,7 +93,7 @@ extern unsigned int deltaTime; * */ -GLuint loadTexture(const char *fileName); +//GLuint loadTexture(const char *fileName); /* * Prints a formatted debug message to the console, along with the callee's file and line diff --git a/include/entities.h b/include/entities.h index fab2ca5..f9fe842 100644 --- a/include/entities.h +++ b/include/entities.h @@ -57,6 +57,7 @@ public: char* name; GENDER gender; GLuint texture[3]; //TODO: ADD TEXTURES + Texturec* tex; void spawn(float, float); -- cgit v1.2.3 From d15062f7f2563761660e665d0940d9c0d1a7883c Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Thu, 22 Oct 2015 09:23:35 -0400 Subject: Commented more of entities, added new texture namespace and class --- include/Texture.h | 22 ++++++++++++++++++++++ src/Texture.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 include/Texture.h create mode 100644 src/Texture.cpp (limited to 'include') 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 + +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 + +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 -- cgit v1.2.3