add Window rendering capabilities
This commit is contained in:
parent
a19f17481b
commit
d68cd6a396
@ -18,7 +18,7 @@ module Widget
|
|||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
if @x > 0 and @y > 0
|
if @width > 0 and @height > 0
|
||||||
render_begin
|
render_begin
|
||||||
render
|
render
|
||||||
children.each do |child|
|
children.each do |child|
|
||||||
|
@ -82,6 +82,22 @@ static void Window_free(void * ptr)
|
|||||||
delete window;
|
delete window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void resize()
|
||||||
|
{
|
||||||
|
GLint viewport_size[2];
|
||||||
|
Window * window;
|
||||||
|
Data_Get_Struct(window_instance, Window, window);
|
||||||
|
SDL_GetWindowSize(window->sdl_window, &viewport_size[0], &viewport_size[1]);
|
||||||
|
glViewport(0, 0, viewport_size[0], viewport_size[1]);
|
||||||
|
rb_funcall(window_instance,
|
||||||
|
rb_intern("resize"),
|
||||||
|
4,
|
||||||
|
INT2FIX(0),
|
||||||
|
INT2FIX(0),
|
||||||
|
INT2FIX(viewport_size[0]),
|
||||||
|
INT2FIX(viewport_size[1]));
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE Window_new(VALUE klass)
|
static VALUE Window_new(VALUE klass)
|
||||||
{
|
{
|
||||||
static bool one_created = false;
|
static bool one_created = false;
|
||||||
@ -117,21 +133,18 @@ static VALUE Window_new(VALUE klass)
|
|||||||
one_created = true;
|
one_created = true;
|
||||||
|
|
||||||
VALUE rv = Data_Wrap_Struct(ruby_class, NULL, Window_free, window);
|
VALUE rv = Data_Wrap_Struct(ruby_class, NULL, Window_free, window);
|
||||||
rb_obj_call_init(rv, 0, NULL);
|
|
||||||
/* TODO: remove window_instance and map SDL_Window * to Window Ruby object
|
/* TODO: remove window_instance and map SDL_Window * to Window Ruby object
|
||||||
* to support multiple windows. */
|
* to support multiple windows. */
|
||||||
window_instance = rv;
|
window_instance = rv;
|
||||||
|
rb_obj_call_init(rv, 0, NULL);
|
||||||
|
resize();
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resize()
|
static void draw()
|
||||||
{
|
{
|
||||||
GLint viewport_size[2];
|
rb_funcall(window_instance, rb_intern("draw"), 0);
|
||||||
Window * window;
|
|
||||||
Data_Get_Struct(window_instance, Window, window);
|
|
||||||
SDL_GetWindowSize(window->sdl_window, &viewport_size[0], &viewport_size[1]);
|
|
||||||
glViewport(0, 0, viewport_size[0], viewport_size[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE Window_event_loop(VALUE klass)
|
static VALUE Window_event_loop(VALUE klass)
|
||||||
@ -152,11 +165,11 @@ static VALUE Window_event_loop(VALUE klass)
|
|||||||
switch (event.window.event)
|
switch (event.window.event)
|
||||||
{
|
{
|
||||||
case SDL_WINDOWEVENT_EXPOSED:
|
case SDL_WINDOWEVENT_EXPOSED:
|
||||||
// draw();
|
draw();
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_RESIZED:
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
resize();
|
resize();
|
||||||
// draw();
|
draw();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,9 +178,28 @@ static VALUE Window_event_loop(VALUE klass)
|
|||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE Window_render(VALUE self)
|
||||||
|
{
|
||||||
|
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE Window_render_end(VALUE self)
|
||||||
|
{
|
||||||
|
Window * window;
|
||||||
|
Data_Get_Struct(window_instance, Window, window);
|
||||||
|
SDL_GL_SwapWindow(window->sdl_window);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
void Window_Init(void)
|
void Window_Init(void)
|
||||||
{
|
{
|
||||||
ruby_class = rb_define_class("Window", rb_cObject);
|
ruby_class = rb_define_class("Window", rb_cObject);
|
||||||
rb_define_singleton_method(ruby_class, "new", (VALUE(*)(...))Window_new, 0);
|
rb_define_singleton_method(ruby_class, "new", (VALUE(*)(...))Window_new, 0);
|
||||||
rb_define_singleton_method(ruby_class, "event_loop", (VALUE(*)(...))Window_event_loop, 0);
|
rb_define_singleton_method(ruby_class, "event_loop", (VALUE(*)(...))Window_event_loop, 0);
|
||||||
|
rb_define_method(ruby_class, "render", (VALUE(*)(...))Window_render, 0);
|
||||||
|
rb_define_method(ruby_class, "render_end", (VALUE(*)(...))Window_render_end, 0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user