load GL buffers

This commit is contained in:
Josh Holtrop 2014-07-26 11:16:35 -04:00
parent 5c52ed0c4d
commit b455fb9e15

View File

@ -1,4 +1,5 @@
#include "gl3w.h"
#include "GLBuffer.h"
#include "ruby.h"
#include "Window.h"
#include <SDL.h>
@ -9,6 +10,7 @@
typedef struct
{
SDL_Window * sdl_window;
GLBufferRef rect_buffer;
} Window;
static VALUE ruby_class;
@ -30,6 +32,23 @@ static void Init_SDL()
initialized = true;
}
static void load_gl_buffers(Window * window)
{
static const GLint rect_coords[4][2] = {
{0, 0},
{1, 0},
{0, 1},
{1, 1},
};
window->rect_buffer = new GLBuffer();
if (!window->rect_buffer->create(GL_ARRAY_BUFFER, GL_STATIC_DRAW,
&rect_coords, sizeof(rect_coords)))
{
rb_raise(rb_eRuntimeError, "Failed to create rectangle VBO");
}
}
static void Init_OpenGL()
{
static bool initialized = false;
@ -92,6 +111,8 @@ static VALUE Window_new(VALUE klass)
Init_OpenGL();
load_gl_buffers(window);
one_created = true;
VALUE rv = Data_Wrap_Struct(ruby_class, NULL, Window_free, window);