From f111b7f74024ba6d47c0d802185406aa9eacfa50 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Sun, 4 Apr 2021 14:41:23 +0000 Subject: Shader: read file with shader source code --- src/graphics/Shader.cpp | 14 ++++++++++++-- src/graphics/Shader.hpp | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/graphics') 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 +#include #include #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; } }; -- cgit v1.2.3-18-g5258