diff --git a/data/shaders/pbrFragment.glsl b/data/shaders/pbrFragment.glsl index 4571734..5b2f1e8 100644 --- a/data/shaders/pbrFragment.glsl +++ b/data/shaders/pbrFragment.glsl @@ -122,6 +122,7 @@ void main() color = pow(color, vec3(1.0/2.2)); //FragColor = texture(texture_diffuse1, ourTexCoord); - //FragColor = texture(texture_metalness1, ourTexCoord); - FragColor = texture(texture_diffuse1, ourTexCoord) * vec4(color, 0.0); + FragColor = texture(texture_metalness1, ourTexCoord); + //FragColor = texture(texture_diffuse1, ourTexCoord) * vec4(color, 0.0); + //FragColor = vec4(CameraPos,1.0); } diff --git a/src/Error.cpp b/src/Error.cpp index 789b296..5e142eb 100644 --- a/src/Error.cpp +++ b/src/Error.cpp @@ -1,18 +1,18 @@ #include "Error.h" Error::Error(std::string location) { object = location; } -void Error::crash(std::string msg) { +const void Error::crash(std::string msg) const { log("Error: " + msg); throw std::string(object + ": \n" + msg); } -void Error::crash(std::string reason, std::string msg) { +const void Error::crash(std::string reason, std::string msg) const { log("Error: " + reason + ": \n" + msg); throw std::string(object + ": \n" + reason + ": \n" + msg); } -void Error::warn(std::string msg) { +const void Error::warn(std::string msg) const { log("Warining: " + msg); // throw object + ": " + msg; } -void Error::log(std::string msg) { +const void Error::log(std::string msg) const { std::cout << object << ": \n" << msg << std::endl; } diff --git a/src/Error.h b/src/Error.h index d5ec9d0..37fdfef 100644 --- a/src/Error.h +++ b/src/Error.h @@ -11,9 +11,9 @@ public: Error(std::string location); // TODO: make the crash break game loop - void crash(std::string msg); - void crash(std::string reason, std::string msg); - void warn(std::string msg); + const void crash(std::string msg) const; + const void crash(std::string reason, std::string msg) const; + const void warn(std::string msg) const; // TODO: write log issues to a file rather than throw - void log(std::string msg); + const void log(std::string msg) const; }; diff --git a/src/ShaderLoader.cpp b/src/ShaderLoader.cpp index a8d89df..7f8935f 100644 --- a/src/ShaderLoader.cpp +++ b/src/ShaderLoader.cpp @@ -80,19 +80,37 @@ ShaderLoader::ShaderLoader(const char *vertexPath, const char *fragmentPath) { void ShaderLoader::use() { glUseProgram(ID); } void ShaderLoader::setBool(const std::string &name, bool value) const { - glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value); + int uniformLocation = glGetUniformLocation(ID, name.c_str()); + glUniform1i(uniformLocation, (int)value); + + if (uniformLocation == -1) + error.warn("Uniform location " + name + " not found"); } void ShaderLoader::setInt(const std::string &name, int value) const { - glUniform1i(glGetUniformLocation(ID, name.c_str()), value); + int uniformLocation = glGetUniformLocation(ID, name.c_str()); + glUniform1i(uniformLocation, value); + + if (uniformLocation == -1) + error.warn("Uniform location " + name + " not found"); } void ShaderLoader::setFloat(const std::string &name, float value) const { - glUniform1f(glGetUniformLocation(ID, name.c_str()), value); + int uniformLocation = glGetUniformLocation(ID, name.c_str()); + glUniform1f(uniformLocation, value); + + if (uniformLocation == -1) + error.warn("Uniform location " + name + " not found"); } void ShaderLoader::setMat4(const std::string &name, glm::mat4 value) const { - glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, - &value[0][0]); + int uniformLocation = glGetUniformLocation(ID, name.c_str()); + glUniformMatrix4fv(uniformLocation, 1, GL_FALSE, &value[0][0]); + + if (uniformLocation == -1) + error.warn("Uniform location " + name + " not found"); } void ShaderLoader::setVec3(const std::string &name, glm::vec3 value) const { - glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1, - glm::value_ptr(value)); + int uniformLocation = glGetUniformLocation(ID, name.c_str()); + glUniform3fv(uniformLocation, 1, glm::value_ptr(value)); + + if (uniformLocation == -1) + error.warn("Uniform location " + name + " not found"); } diff --git a/src/main.cpp b/src/main.cpp index ed08ed8..1ccf33d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,6 +46,10 @@ int main(int argc, char **argv) { return 1; } + // Set openGL version so RenderDoc works + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + // Create glContext SDL_GLContext glContext = SDL_GL_CreateContext(window); if (!glContext) {