aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graphics/Shader.cpp14
-rw-r--r--src/graphics/Shader.hpp2
2 files changed, 13 insertions, 3 deletions
diff --git a/src/graphics/Shader.cpp b/src/graphics/Shader.cpp
index 35a451d..740b055 100644
--- a/src/graphics/Shader.cpp
+++ b/src/graphics/Shader.cpp
@@ -1,6 +1,9 @@
+#include <string.h>
+#include <errno.h>
#include <GL/glew.h>
#include "Shader.hpp"
+#include "../xstdlib/xstdlib.hpp"
Shader::~Shader()
{
@@ -10,16 +13,23 @@ Shader::~Shader()
delete[] error_log;
}
-int Shader::Compile(const char *source, GLenum shaderType)
+int Shader::Compile(const char *path, GLenum shaderType)
{
GLint success;
+ char *source;
+ error_log = new char[GL_INFO_LOG_LENGTH];
+
+ source = xfread(path, "rb");
+ if(!source) {
+ strcpy(error_log, strerror(errno));
+ return 1;
+ }
shader_id = glCreateShader(shaderType);
glShaderSource(shader_id, 1, &source, NULL);
glCompileShader(shader_id);
glGetShaderiv(shader_id, GL_COMPILE_STATUS, &success);
if(success == 0) {
- error_log = new char[GL_INFO_LOG_LENGTH];
glGetShaderInfoLog(shader_id, GL_INFO_LOG_LENGTH, NULL, error_log);
return 1;
}
diff --git a/src/graphics/Shader.hpp b/src/graphics/Shader.hpp
index 81841ad..d37d2c1 100644
--- a/src/graphics/Shader.hpp
+++ b/src/graphics/Shader.hpp
@@ -9,7 +9,7 @@ public:
Shader() : shader_id(0), error_log(0) { }
~Shader();
- int Compile(const char *source, GLenum shaderType);
+ int Compile(const char *path, GLenum shaderType);
char *GetError() { return error_log; }
GLuint GetID() { return shader_id; }
};