GUI: load GL shaders/programs
This commit is contained in:
parent
c5de5ae479
commit
23a24e4af4
@ -1,6 +1,7 @@
|
||||
#include "GUI.h"
|
||||
#include "gl3w.h"
|
||||
#include <iostream>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -4,17 +4,28 @@
|
||||
#include "jes/Ref.h"
|
||||
#include <SDL.h>
|
||||
#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<GUI> GUIRef;
|
||||
|
Loading…
x
Reference in New Issue
Block a user