#ifndef MATERIAL_H #define MATERIAL_H #include #include #include using namespace std; #include "util.h" #include "shader.h" struct texture_execption { texture_execption (string s) : msg(s) { } string msg; }; inline int power_of_two (int input) { int value = 1; while (value < input) { value <<= 1; } return value; } struct material { virtual void enable (view &ctx) = 0; virtual void disable (view &ctx) = 0; virtual ~material (); }; struct simple_material : material { colour diffuse, specular, emission; GLfloat shininess; void enable (view &ctx); void disable (view &ctx); simple_material () : diffuse(1, 0, 1, 1) , specular(1, 0, 1, 1) , emission(1, 0, 1, 1) , shininess(1.) { } }; struct texture { SDL_Surface *image; GLuint name; GLfloat texcoord[4]; GLuint load_texture (SDL_Surface *surface, GLfloat *texcoord); texture(const char *f) { image = IMG_Load (f); if (!image) throw (texture_execption ("Couldn't load " + (string) f + ": " + (string) IMG_GetError ())); name = load_texture (image, (GLfloat*)&texcoord); if (name == 0) throw (texture_execption ("Couldn't make GL Texture, failed to create new RGB SWSurface")); } }; struct test_material { shader::program_object p; texture tex; shader::sampler_2d texvar; shader::uniform_4f lightpos; test_material (); void enable (view &ctx); void disable (view &ctx); }; #endif