diff options
author | Joursoir <chat@joursoir.net> | 2021-04-04 14:41:23 +0000 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2021-04-04 14:41:23 +0000 |
commit | f111b7f74024ba6d47c0d802185406aa9eacfa50 (patch) | |
tree | dfa85a0a73f35bfd3da83b59750aa50afe066137 /src/graphics | |
parent | 685ff91f73d4aa437d801e0c93dee2b904eb8880 (diff) | |
download | space-simulator-f111b7f74024ba6d47c0d802185406aa9eacfa50.tar.gz space-simulator-f111b7f74024ba6d47c0d802185406aa9eacfa50.tar.bz2 space-simulator-f111b7f74024ba6d47c0d802185406aa9eacfa50.zip |
Shader: read file with shader source code
Diffstat (limited to 'src/graphics')
-rw-r--r-- | src/graphics/Shader.cpp | 14 | ||||
-rw-r--r-- | src/graphics/Shader.hpp | 2 |
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; } }; |