add FlatShader; draw a cursor

This commit is contained in:
josh committed 2016-07-31 23:08:26 -04:00
1 parent 8beea3461c
commit 5a942a61a9
6 files changed
+116

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
#include "FlatShader.h"
#include "Runtime.h"
FlatShader::FlatShader()
{
std::string v_path = Runtime::find(Runtime::SHADER, "flat.v");
std::string f_path = Runtime::find(Runtime::SHADER, "flat.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.position = m_program->get_uniform_location("position");
m_uniforms.color = m_program->get_uniform_location("color");
}
+40
View File
@@ -0,0 +1,40 @@
#ifndef FLATSHADER_H
#define FLATSHADER_H
#include "glcxx.hpp"
#include <memory>
class FlatShader
{
public:
FlatShader();
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);
}
protected:
std::shared_ptr<glcxx::Program> m_program;
struct
{
GLint viewport_size;
GLint color;
GLint position;
} m_uniforms;
};
#endif