GUI: load GL shaders/programs
This commit is contained in:
parent
c5de5ae479
commit
23a24e4af4
@ -1,6 +1,7 @@
|
|||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
#include "gl3w.h"
|
#include "gl3w.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "jes/Runtime.h"
|
||||||
|
|
||||||
#define WIDTH 500
|
#define WIDTH 500
|
||||||
#define HEIGHT 500
|
#define HEIGHT 500
|
||||||
@ -53,6 +54,47 @@ namespace jes
|
|||||||
if (!m_font_manager->load())
|
if (!m_font_manager->load())
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,17 +4,28 @@
|
|||||||
#include "jes/Ref.h"
|
#include "jes/Ref.h"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include "FontManager.h"
|
#include "FontManager.h"
|
||||||
|
#include "GLProgram.h"
|
||||||
|
|
||||||
namespace jes
|
namespace jes
|
||||||
{
|
{
|
||||||
class GUI
|
class GUI
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROGRAM_TEXT,
|
||||||
|
PROGRAM_BASIC,
|
||||||
|
PROGRAM_RECT,
|
||||||
|
PROGRAM_COUNT,
|
||||||
|
};
|
||||||
bool load();
|
bool load();
|
||||||
int run();
|
int run();
|
||||||
protected:
|
protected:
|
||||||
|
bool load_shaders();
|
||||||
|
|
||||||
SDL_Window * m_window;
|
SDL_Window * m_window;
|
||||||
FontManagerRef m_font_manager;
|
FontManagerRef m_font_manager;
|
||||||
|
GLProgramRef m_programs[PROGRAM_COUNT];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Ref<GUI> GUIRef;
|
typedef Ref<GUI> GUIRef;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user