Add Gl.draw_rect().
This commit is contained in:
parent
e51953445b
commit
a53b53e864
@ -13,24 +13,47 @@ class Gl
|
||||
private FlatProgram m_flat_program;
|
||||
private TextProgram m_text_program;
|
||||
private RectProgram m_rect_program;
|
||||
private gltk.Array m_rect_array;
|
||||
private gltk.Buffer m_rect_buffer;
|
||||
|
||||
this()
|
||||
private void build_flat_program()
|
||||
{
|
||||
m_flat_program = new FlatProgram(
|
||||
build_shader(GL_VERTEX_SHADER, "share/jes/shaders/flat.v.glsl"),
|
||||
build_shader(GL_FRAGMENT_SHADER, "share/jes/shaders/flat.f.glsl"),
|
||||
"coords", 0);
|
||||
}
|
||||
|
||||
private void build_text_program()
|
||||
{
|
||||
m_text_program = new TextProgram(
|
||||
build_shader(GL_VERTEX_SHADER, "share/jes/shaders/text.v.glsl"),
|
||||
build_shader(GL_FRAGMENT_SHADER, "share/jes/shaders/text.f.glsl"),
|
||||
"coords", 0);
|
||||
m_text_program.use();
|
||||
m_text_program.set_texture(0);
|
||||
}
|
||||
|
||||
private void build_rect_program()
|
||||
{
|
||||
m_rect_program = new RectProgram(
|
||||
build_shader(GL_VERTEX_SHADER, "share/jes/shaders/rect.v.glsl"),
|
||||
build_shader(GL_FRAGMENT_SHADER, "share/jes/shaders/rect.f.glsl"),
|
||||
"coords", 0);
|
||||
m_rect_array = new gltk.Array();
|
||||
m_rect_array.bind();
|
||||
m_rect_buffer = new gltk.Buffer(GL_ARRAY_BUFFER);
|
||||
GLint[] rect_coords = [0, 0, 1, 0, 1, 1, 0, 1];
|
||||
m_rect_buffer.set_buffer_data(GL_STATIC_DRAW, rect_coords);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_INT, GL_FALSE, 0, null);
|
||||
}
|
||||
|
||||
this()
|
||||
{
|
||||
build_flat_program();
|
||||
build_text_program();
|
||||
build_rect_program();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glEnable(GL_BLEND);
|
||||
@ -57,6 +80,17 @@ class Gl
|
||||
glyph.render();
|
||||
}
|
||||
|
||||
void draw_rect(int x, int y, int width, int height,
|
||||
float r, float g, float b, float a)
|
||||
{
|
||||
m_rect_array.bind();
|
||||
m_rect_program.use();
|
||||
m_rect_program.set_color(r, g, b, a);
|
||||
m_rect_program.set_position(x, y);
|
||||
m_rect_program.set_size(width, height);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
}
|
||||
|
||||
private gltk.Shader build_shader(GLenum shader_type, string filename)
|
||||
{
|
||||
auto shader = new gltk.Shader(shader_type);
|
||||
|
@ -37,6 +37,7 @@ class Window
|
||||
{
|
||||
glClearColor(0.5, 0.0, 1.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_gl.draw_rect(50, 50, 20, 20, 0.0, 0.2, 0.4, 1.0);
|
||||
m_gl.draw_character(m_font, 'h', 50, 50, 1.0, 0.9, 0.8, 1.0);
|
||||
m_window.swap_buffers();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user