diff --git a/Engine/engine/match b/Engine/engine/match index 7290abd..ef9c672 100755 Binary files a/Engine/engine/match and b/Engine/engine/match differ diff --git a/Engine/engine/shader.cpp b/Engine/engine/shader.cpp index 739411f..34d29e3 100644 --- a/Engine/engine/shader.cpp +++ b/Engine/engine/shader.cpp @@ -9,40 +9,38 @@ #include #include "shader.hpp" - - -Shader::Shader(const std::string vertexPath, const std::string fragmentPath) +const std::string Shader::fileToShader(const std::string shaderPath) { // 1. retrieve the vertex/fragment source code from filePath - std::string vertexCode; - std::string fragmentCode; - std::ifstream vShaderFile; - std::ifstream fShaderFile; + std::string shaderCode; + std::ifstream shaderFile; // ensure ifstream objects can throw exceptions: - vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); - fShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); + shaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); try { // open files - vShaderFile.open(vertexPath); - fShaderFile.open(fragmentPath); - std::stringstream vShaderStream, fShaderStream; + shaderFile.open(shaderPath); + std::stringstream shaderStream; // read file's buffer contents into streams - vShaderStream << vShaderFile.rdbuf(); - fShaderStream << fShaderFile.rdbuf(); + shaderStream << shaderFile.rdbuf(); // close file handlers - vShaderFile.close(); - fShaderFile.close(); + shaderFile.close(); // convert stream into string - vertexCode = vShaderStream.str(); - fragmentCode = fShaderStream.str(); + shaderCode = shaderStream.str(); } catch (std::ifstream::failure& e) { std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ: " << e.what() << std::endl; } - const char* vShaderCode = vertexCode.c_str(); - const char * fShaderCode = fragmentCode.c_str(); + return shaderCode; +} + +Shader::Shader(const std::string vertexPath, const std::string fragmentPath) +{ + const std::string vshaderCodeString = this -> fileToShader(vertexPath); + const std::string fShaderCodeString = this -> fileToShader(fragmentPath); + const char* vShaderCode = vshaderCodeString.c_str(); + const char * fShaderCode = fShaderCodeString.c_str(); // 2. compile shaders unsigned int vertex, fragment; // vertex shader diff --git a/Engine/engine/shader.hpp b/Engine/engine/shader.hpp index a97e13c..4046371 100644 --- a/Engine/engine/shader.hpp +++ b/Engine/engine/shader.hpp @@ -15,7 +15,7 @@ public: // constructor generates the shader on the fly // ------------------------------------------------------------------------ Shader(const std::string vertexPath, const std::string fragmentPath); - + const std::string fileToShader(const std::string shaderPath); // activate the shader // ------------------------------------------------------------------------ void use();