diff --git a/src/gui/GUI.cc b/src/gui/GUI.cc index 51e63e5..546a7c2 100644 --- a/src/gui/GUI.cc +++ b/src/gui/GUI.cc @@ -1,6 +1,7 @@ #include "GUI.h" #include "gl3w.h" #include +#include "jes/Runtime.h" #define WIDTH 500 #define HEIGHT 500 @@ -53,6 +54,47 @@ namespace jes if (!m_font_manager->load()) return false; + if (!load_shaders()) + return false; + + return true; + } + + bool GUI::load_shaders() + { + static const char * shader_sources[PROGRAM_COUNT][2] = { + {"text.v.glsl", "text.f.glsl"}, + {"basic.v.glsl", "basic.f.glsl"}, + {"rect.v.glsl", "basic.f.glsl"}, + }; + + for (int i = 0; i < PROGRAM_COUNT; i++) + { + PathRef shader_paths[2]; + GLShaderRef shaders[2]; + + m_programs[i] = new GLProgram(); + + for (int j = 0; j < 2; j++) + { + shader_paths[j] = Runtime::locate(Runtime::SHADER, shader_sources[i][j]); + if (shader_paths[j] == NULL) + { + std::cerr << "Could not find shader source " << shader_sources[i][j] << std::endl; + return false; + } + shaders[j] = new GLShader(); + if (!shaders[j]->create(j == 0 ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER, shader_paths[j])) + { + return false; + } + + m_programs[i]->attach_shader(shaders[j]); + } + if (!m_programs[i]->link()) + return false; + } + return true; } diff --git a/src/gui/GUI.h b/src/gui/GUI.h index f4fcf42..9b466c5 100644 --- a/src/gui/GUI.h +++ b/src/gui/GUI.h @@ -4,17 +4,28 @@ #include "jes/Ref.h" #include #include "FontManager.h" +#include "GLProgram.h" namespace jes { class GUI { public: + enum + { + PROGRAM_TEXT, + PROGRAM_BASIC, + PROGRAM_RECT, + PROGRAM_COUNT, + }; bool load(); int run(); protected: + bool load_shaders(); + SDL_Window * m_window; FontManagerRef m_font_manager; + GLProgramRef m_programs[PROGRAM_COUNT]; }; typedef Ref GUIRef;