diff --git a/src/gui/Programs/TextProgram.cc b/src/gui/Programs/TextProgram.cc new file mode 100644 index 0000000..c918ab1 --- /dev/null +++ b/src/gui/Programs/TextProgram.cc @@ -0,0 +1,18 @@ +#include "TextProgram.h" +#include "Runtime.h" + +TextProgram::TextProgram() +{ + std::string v_path = Runtime::find(Runtime::SHADER, "text.v"); + std::string f_path = Runtime::find(Runtime::SHADER, "text.f"); + + m_program = glcxx::Program::create( + glcxx::Shader::create_from_file(GL_VERTEX_SHADER, v_path.c_str()), + glcxx::Shader::create_from_file(GL_FRAGMENT_SHADER, f_path.c_str()), + "coords", 0); + + m_uniforms.viewport_size = m_program->get_uniform_location("viewport_size"); + m_uniforms.texture = m_program->get_uniform_location("texture"); + m_uniforms.color = m_program->get_uniform_location("color"); + m_uniforms.position = m_program->get_uniform_location("position"); +} diff --git a/src/gui/Programs/TextProgram.h b/src/gui/Programs/TextProgram.h new file mode 100644 index 0000000..51a1524 --- /dev/null +++ b/src/gui/Programs/TextProgram.h @@ -0,0 +1,46 @@ +#ifndef TEXTPROGRAM_H +#define TEXTPROGRAM_H + +#include "glcxx.hpp" +#include + +class TextProgram +{ +public: + TextProgram(); + + void use() { m_program->use(); } + + void set_viewport_size(int width, int height) + { + glUniform2i(m_uniforms.viewport_size, width, height); + } + + void set_texture(int texture) + { + glUniform1i(m_uniforms.texture, texture); + } + + void set_color(float r, float g, float b, float a) + { + glUniform4f(m_uniforms.color, r, g, b, a); + } + + void set_position(int x, int y) + { + glUniform2i(m_uniforms.position, x, y); + } + +protected: + std::shared_ptr m_program; + + struct + { + GLint viewport_size; + GLint texture; + GLint color; + GLint position; + } m_uniforms; +}; + +#endif