add TextProgram
This commit is contained in:
parent
54b7e302d0
commit
d2f39cbddc
18
src/gui/Programs/TextProgram.cc
Normal file
18
src/gui/Programs/TextProgram.cc
Normal file
@ -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");
|
||||
}
|
46
src/gui/Programs/TextProgram.h
Normal file
46
src/gui/Programs/TextProgram.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef TEXTPROGRAM_H
|
||||
#define TEXTPROGRAM_H
|
||||
|
||||
#include "glcxx.hpp"
|
||||
#include <memory>
|
||||
|
||||
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<glcxx::Program> m_program;
|
||||
|
||||
struct
|
||||
{
|
||||
GLint viewport_size;
|
||||
GLint texture;
|
||||
GLint color;
|
||||
GLint position;
|
||||
} m_uniforms;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user