break up Init_Graphics() into Init_SDL() and Init_OpenGL() since they need to be called at separate times
This commit is contained in:
parent
b559ef1be0
commit
b6c5e9e1d7
37
src/GUI.cc
37
src/GUI.cc
@ -9,43 +9,6 @@ namespace jes
|
||||
{
|
||||
bool GUI::load()
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO))
|
||||
{
|
||||
std::cerr << "Failed to initialize SDL!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
atexit(SDL_Quit);
|
||||
|
||||
m_window = SDL_CreateWindow("jes",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
WIDTH,
|
||||
HEIGHT,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||
if (!m_window)
|
||||
{
|
||||
std::cerr << "Failed to create window!" << std::endl;
|
||||
SDL_Quit();
|
||||
return false;
|
||||
}
|
||||
|
||||
(void)SDL_GL_CreateContext(m_window);
|
||||
|
||||
if (gl3wInit() != 0)
|
||||
{
|
||||
std::cerr << "Failed to gl3wInit()" << std::endl;
|
||||
SDL_Quit();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!gl3wIsSupported(3, 0))
|
||||
{
|
||||
std::cerr << "OpenGL 3.0 is not supported!" << std::endl;
|
||||
SDL_Quit();
|
||||
return false;
|
||||
}
|
||||
|
||||
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
m_font_manager = new FontManager();
|
||||
|
@ -13,11 +13,11 @@ typedef struct
|
||||
|
||||
static VALUE ruby_class;
|
||||
|
||||
static void Init_Graphics(void)
|
||||
static void Init_SDL(void)
|
||||
{
|
||||
static bool graphics_initialized = false;
|
||||
static bool initialized = false;
|
||||
|
||||
if (graphics_initialized)
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO))
|
||||
@ -27,6 +27,16 @@ static void Init_Graphics(void)
|
||||
|
||||
atexit(SDL_Quit);
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
static void Init_OpenGL()
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
if (gl3wInit() != 0)
|
||||
{
|
||||
SDL_Quit();
|
||||
@ -38,11 +48,18 @@ static void Init_Graphics(void)
|
||||
SDL_Quit();
|
||||
rb_raise(rb_eRuntimeError, "OpenGL 3.0 is not supported");
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
static void Window_free(void * ptr)
|
||||
{
|
||||
/* TODO */
|
||||
Window * window = (Window *)ptr;
|
||||
|
||||
if (window->sdl_window)
|
||||
SDL_DestroyWindow(window->sdl_window);
|
||||
|
||||
free(window);
|
||||
}
|
||||
|
||||
static VALUE Window_new(VALUE klass)
|
||||
@ -54,7 +71,7 @@ static VALUE Window_new(VALUE klass)
|
||||
rb_raise(rb_eRuntimeError, "Only one Window for now");
|
||||
}
|
||||
|
||||
Init_Graphics();
|
||||
Init_SDL();
|
||||
Window * window = (Window *)malloc(sizeof(Window));
|
||||
window->sdl_window = SDL_CreateWindow("jes",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
@ -70,6 +87,8 @@ static VALUE Window_new(VALUE klass)
|
||||
|
||||
(void)SDL_GL_CreateContext(window->sdl_window);
|
||||
|
||||
Init_OpenGL();
|
||||
|
||||
one_created = true;
|
||||
|
||||
return Data_Wrap_Struct(ruby_class, NULL, Window_free, window);
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <iostream>
|
||||
#include "GUI.h"
|
||||
#include "ruby.h"
|
||||
#include "Window.h"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user