mv src src-c
This commit is contained in:
1 parent
a0b2f660a2
commit
50cd9efd86
75 files changed
No files matched your search
@@ -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");
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "GL.h"
|
||||
|
||||
GL::GL()
|
||||
{
|
||||
m_shaders.text = std::make_shared<TextShader>();
|
||||
m_shaders.text->use();
|
||||
m_shaders.text->set_texture(0);
|
||||
m_shaders.text->set_color(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
m_shaders.rect = std::make_shared<RectShader>();
|
||||
|
||||
GLint rect_coords[] = {
|
||||
0, 0,
|
||||
1, 0,
|
||||
1, 1,
|
||||
0, 1};
|
||||
m_rect_array = glcxx::Array::create();
|
||||
m_rect_array->bind();
|
||||
m_rect_buffer = glcxx::Buffer::create(GL_ARRAY_BUFFER, GL_STATIC_DRAW,
|
||||
rect_coords, sizeof(rect_coords));
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_INT, GL_FALSE, 0, 0);
|
||||
}
|
||||
|
||||
void GL::draw_rect(int x, int y, int width, int height,
|
||||
float r, float g, float b, float a)
|
||||
{
|
||||
m_rect_array->bind();
|
||||
m_shaders.rect->use();
|
||||
m_shaders.rect->set_color(r, g, b, a);
|
||||
m_shaders.rect->set_position(x, y);
|
||||
m_shaders.rect->set_size(width, height);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
}
|
||||
|
||||
void GL::draw_character(int x, int y, uint32_t character, Font & font,
|
||||
float r, float g, float b, float a)
|
||||
{
|
||||
m_shaders.text->use();
|
||||
m_shaders.text->set_color(r, g, b, a);
|
||||
m_shaders.text->set_position(x, y + font.get_baseline_offset());
|
||||
font.get_glyph(character)->render();
|
||||
}
|
||||
|
||||
void GL::resize(int width, int height)
|
||||
{
|
||||
m_shaders.text->use();
|
||||
m_shaders.text->set_viewport_size(width, height);
|
||||
m_shaders.rect->use();
|
||||
m_shaders.rect->set_viewport_size(width, height);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef GL_H
|
||||
#define GL_H
|
||||
|
||||
#include "glcxx.hpp"
|
||||
#include "TextShader.h"
|
||||
#include "FlatShader.h"
|
||||
#include "RectShader.h"
|
||||
#include "Font.h"
|
||||
#include <memory>
|
||||
|
||||
class GL
|
||||
{
|
||||
public:
|
||||
GL();
|
||||
|
||||
void draw_rect(int x, int y, int width, int height,
|
||||
float r, float g, float b, float a);
|
||||
void draw_character(int x, int y, uint32_t character, Font & font,
|
||||
float r, float g, float b, float a);
|
||||
void resize(int width, int height);
|
||||
|
||||
protected:
|
||||
struct
|
||||
{
|
||||
std::shared_ptr<TextShader> text;
|
||||
std::shared_ptr<FlatShader> flat;
|
||||
std::shared_ptr<RectShader> rect;
|
||||
} m_shaders;
|
||||
|
||||
std::shared_ptr<glcxx::Array> m_rect_array;
|
||||
std::shared_ptr<glcxx::Buffer> m_rect_buffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "TextShader.h"
|
||||
#include "Runtime.h"
|
||||
|
||||
TextShader::TextShader()
|
||||
{
|
||||
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");
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef TEXTSHADER_H
|
||||
#define TEXTSHADER_H
|
||||
|
||||
#include "glcxx.hpp"
|
||||
#include <memory>
|
||||
|
||||
class TextShader
|
||||
{
|
||||
public:
|
||||
TextShader();
|
||||
|
||||
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
|
||||
Reference in new issue
Block a user