From b19265bfa91e55c564b75aadcabd212ac89cf349 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 10 Oct 2016 19:17:19 -0500 Subject: the revival, entityx --- include/render.hpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 include/render.hpp (limited to 'include/render.hpp') diff --git a/include/render.hpp b/include/render.hpp new file mode 100644 index 0000000..0a2adcd --- /dev/null +++ b/include/render.hpp @@ -0,0 +1,79 @@ +#ifndef RENDER_HPP_ +#define RENDER_HPP_ + +#include + +#include +#include + +#include +#include + +/** + * @class Shader + * @brief Handles a texture shader, allowing it's use in the program. + */ +class Shader { +public: + GLuint shader; + GLint coord; + GLint tex; + std::vector uniform; + + void create(const char *vert, const char *frag) { + shader = create_program(vert, frag); + coord = get_attrib(shader, "coord2d"); + tex = get_attrib(shader, "tex_coord"); + } + + inline void addUniform(const char *name) { + uniform.push_back(get_uniform(shader, name)); + } + + inline void use(void) { + glUseProgram(shader); + } + + inline void unuse(void) { + glUseProgram(0); + } + + inline void enable(void) { + glEnableVertexAttribArray(coord); + glEnableVertexAttribArray(tex); + } + + inline void disable(void) { + glDisableVertexAttribArray(coord); + glDisableVertexAttribArray(tex); + } + + ~Shader(void) { + uniform.clear(); + } +}; + +typedef enum { + WU_texture = 0, + WU_ortho, + WU_tex_color, + WU_transform, + WU_ambient, + WU_light_impact, + WU_light, + WU_light_color, + WU_light_size +} WorldUniform; + +namespace Render { + extern Shader worldShader; + extern Shader textShader; + + void initShaders(void); + + void useShader(Shader *s); + + void drawRect(vec2 ll, vec2 ur, float z); +} + +#endif // RENDER_HPP_ -- cgit v1.2.3