diff options
Diffstat (limited to 'shader.h')
-rw-r--r-- | shader.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/shader.h b/shader.h new file mode 100644 index 0000000..d4ad263 --- /dev/null +++ b/shader.h @@ -0,0 +1,54 @@ +#ifndef _SHADER_H_ +#define _SHADER_H_ + +#include <iostream> +#include <string> +#define GL_GLEXT_PROTOTYPES +#ifndef __APPLE__ +#include <GL/gl.h> +#include <GL/glu.h> +#else +#include <OpenGL/gl.h> +#include <OpenGL/glu.h> +#endif + +class GLBaseShader { + friend class GLShaderProgram; + + protected: + void shader_source(const char *filename); + void shader_source(std::string& filename); + unsigned int shader; + public: + GLBaseShader(GLenum); + ~GLBaseShader(); +}; + +class GLVertexShader : public GLBaseShader { + public: + GLVertexShader() : GLBaseShader(GL_VERTEX_SHADER) {}; + GLVertexShader(const char *s) : GLBaseShader(GL_VERTEX_SHADER) { shader_source(s); }; + GLVertexShader(std::string& s) : GLBaseShader(GL_VERTEX_SHADER) { shader_source(s); }; +}; + +class GLFragmentShader : public GLBaseShader { + public: + GLFragmentShader() : GLBaseShader(GL_FRAGMENT_SHADER) {}; + GLFragmentShader(const char *s) : GLBaseShader(GL_FRAGMENT_SHADER) { shader_source(s); }; + GLFragmentShader(std::string& s) : GLBaseShader(GL_FRAGMENT_SHADER) { shader_source(s); }; +}; + +class GLShaderProgram { + protected: + unsigned int program; + public: + GLShaderProgram(); + ~GLShaderProgram(); + + void attach(GLBaseShader&); + void detach(GLBaseShader&); + void link(); + void use(); +}; + +#endif |