add a rectangle shader
This commit is contained in:
1 parent
6d8c8e76a9
commit
c852e9991b
6 files changed
+130
No files matched your search
@@ -0,0 +1,18 @@
|
||||
#include "RectShader.h"
|
||||
#include "Runtime.h"
|
||||
|
||||
RectShader::RectShader()
|
||||
{
|
||||
std::string v_path = Runtime::find(Runtime::SHADER, "rect.v");
|
||||
std::string f_path = Runtime::find(Runtime::SHADER, "rect.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.color = m_program->get_uniform_location("color");
|
||||
m_uniforms.position = m_program->get_uniform_location("position");
|
||||
m_uniforms.size = m_program->get_uniform_location("size");
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef RECTSHADER_H
|
||||
#define RECTSHADER_H
|
||||
|
||||
#include "glcxx.hpp"
|
||||
#include <memory>
|
||||
|
||||
class RectShader
|
||||
{
|
||||
public:
|
||||
RectShader();
|
||||
|
||||
void use() { m_program->use(); }
|
||||
|
||||
void set_viewport_size(int width, int height)
|
||||
{
|
||||
glUniform2i(m_uniforms.viewport_size, width, height);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void set_size(int x, int y)
|
||||
{
|
||||
glUniform2i(m_uniforms.size, x, y);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<glcxx::Program> m_program;
|
||||
|
||||
struct
|
||||
{
|
||||
GLint viewport_size;
|
||||
GLint color;
|
||||
GLint position;
|
||||
GLint size;
|
||||
} m_uniforms;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user