add GL.draw_text and Widget#draw_text
This commit is contained in:
parent
0ca8e044b2
commit
67682df332
@ -34,4 +34,8 @@ module Widget
|
|||||||
def draw_rect(x, y, width, height, r, g, b, a)
|
def draw_rect(x, y, width, height, r, g, b, a)
|
||||||
GL.draw_rect(@x + x, @y + y, width, height, r, g, b, a)
|
GL.draw_rect(@x + x, @y + y, width, height, r, g, b, a)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def draw_text(font, x, y, string, r, g, b, a)
|
||||||
|
GL.draw_text(font, @x + x, @y + y, string, r, g, b, a)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
29
src/GL.cc
29
src/GL.cc
@ -3,6 +3,7 @@
|
|||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
#include "GLBuffer.h"
|
#include "GLBuffer.h"
|
||||||
#include "GLProgram.h"
|
#include "GLProgram.h"
|
||||||
|
#include "Font.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -42,11 +43,39 @@ static VALUE GL_draw_rect(VALUE klass,
|
|||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE GL_draw_text(VALUE klass,
|
||||||
|
VALUE font, VALUE x, VALUE y, VALUE string,
|
||||||
|
VALUE r, VALUE g, VALUE b, VALUE a)
|
||||||
|
{
|
||||||
|
int x_int = FIX2INT(x);
|
||||||
|
glUseProgram(programs[PROGRAM_TEXT]->id);
|
||||||
|
glUniform1i(programs[PROGRAM_TEXT]->uniforms[UNIFORM_TEXTURE], 0);
|
||||||
|
glUniform4f(programs[PROGRAM_TEXT]->uniforms[UNIFORM_COLOR],
|
||||||
|
NUM2DBL(r),
|
||||||
|
NUM2DBL(g),
|
||||||
|
NUM2DBL(b),
|
||||||
|
NUM2DBL(a));
|
||||||
|
|
||||||
|
int length = RSTRING_LEN(string);
|
||||||
|
const char * string_ptr = RSTRING_PTR(string);
|
||||||
|
int advance = FIX2INT(rb_iv_get(font, "@advance"));
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
glUniform2i(programs[PROGRAM_TEXT]->uniforms[UNIFORM_POSITION], x_int, FIX2INT(y));
|
||||||
|
Font_RenderGlyph(font, string_ptr[i]);
|
||||||
|
x_int += advance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
void GL_Init()
|
void GL_Init()
|
||||||
{
|
{
|
||||||
ruby_module = rb_define_module("GL");
|
ruby_module = rb_define_module("GL");
|
||||||
rb_define_singleton_method(ruby_module, "draw_rect",
|
rb_define_singleton_method(ruby_module, "draw_rect",
|
||||||
(VALUE(*)(...))GL_draw_rect, 8);
|
(VALUE(*)(...))GL_draw_rect, 8);
|
||||||
|
rb_define_singleton_method(ruby_module, "draw_text",
|
||||||
|
(VALUE(*)(...))GL_draw_text, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_gl_buffers()
|
static void load_gl_buffers()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user