diff --git a/.vscode/settings.json b/.vscode/settings.json index 2ca0233..4fb9809 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -104,6 +104,7 @@ "Parameterfv", "Parameteri", "RENDERLOOP", - "VERTICE" + "VERTICE", + "vshader" ] } \ No newline at end of file diff --git a/Engine/engine/Shaders/fragmentShaderTextureUniform.fs b/Engine/engine/Shaders/fragmentShaderTextureUniform.fs index 9dc0c42..c8c2ed8 100644 --- a/Engine/engine/Shaders/fragmentShaderTextureUniform.fs +++ b/Engine/engine/Shaders/fragmentShaderTextureUniform.fs @@ -7,7 +7,7 @@ in vec2 TexCoord; // texture samplers uniform sampler2D texture1; uniform sampler2D texture2; -uniform int mixProportions; // set in OGL code +uniform float mixProportions; // set in OGL code void main() { diff --git a/Engine/engine/draw.cpp b/Engine/engine/draw.cpp index 98e86d6..dcaab95 100644 --- a/Engine/engine/draw.cpp +++ b/Engine/engine/draw.cpp @@ -6,12 +6,15 @@ #include #include +#include #include #include #include #include #include #include +#include /* srand, rand */ +#include /* time */ #include "./constants.hpp" #include "./misc.hpp" @@ -176,7 +179,7 @@ drawFigureReturn drawFigure(const int whatToDraw) { texture_constants::AWESOME_FACE_ARGUMENT }; offsetsStruct offsets = offsetsStruct(); - const std::vector uniformInfo = {"ourColor"}; + const std::vector uniformInfo = {"mixProportions"}; return draw( constants::VERTEX_SHADER_TEXTURE_FILENAME, constants::FRAGMENT_SHADER_TEXTURE_UNIFORM_FILENAME, @@ -185,7 +188,7 @@ drawFigureReturn drawFigure(const int whatToDraw) { constants::TEXTURE_INDICES, constants::TEXTURE_INDICES_SIZE, true, true, textureInfoArray, - offsets); + offsets, uniformInfo); } default: throw "No function for this draw call"; @@ -237,7 +240,14 @@ drawFigureReturn draw(const char* vertexPath, const char* fragmentPath, configureVertexAttribute(colorIncluded, textureIncluded); if (uniformName.size() > 0) { - updateUniformColor(ourShader.ID, uniformName.at(0)); + if(uniformName.at(0) == "ourColor") { + updateUniformColor(ourShader, uniformName.at(0)); + } + if(uniformName.at(0) == "mixProportions") { + srand (time(NULL)); + const float randomNumber = static_cast (rand()) / static_cast (RAND_MAX); + ourShader.setFloat(uniformName.at(0), randomNumber); + } } drawTextureArray(textureInfo, ourShader); @@ -269,18 +279,15 @@ drawFigureReturn draw(const char* vertexPath, const char* fragmentPath, return newReturn; } -void updateUniformColor(const unsigned int shaderProgram, +void updateUniformColor(const Shader shaderProgram, std::string uniformName) { // update the uniform color const float timeValue = glfwGetTime(); // retrieve running time const float greenValue = sin(timeValue) / 2.0f + 0.5f; // vary the color from 0.0 to 1.0 using sin // query the location of our uniform - const int vertexColorLocation = - glGetUniformLocation(shaderProgram, uniformName.c_str()); + shaderProgram.set4Float(uniformName, 0.0f, greenValue, 0.0f, 1.0f); // if glGetUniformLocation returns -1 it could not find the location - if (vertexColorLocation != -1) { - glUniform4f(vertexColorLocation, 0.0f, greenValue, 0.0f, 1.0f); /* we set the uniform value using glUniform4f 4f means that it expects 4 floats few of possible postfixes: @@ -291,6 +298,5 @@ void updateUniformColor(const unsigned int shaderProgram, fv: the function expects a float vector/array as its value. */ } -} #endif // #ifndef DRAW_CPP diff --git a/Engine/engine/draw.hpp b/Engine/engine/draw.hpp index 76c883f..e858456 100644 --- a/Engine/engine/draw.hpp +++ b/Engine/engine/draw.hpp @@ -27,7 +27,7 @@ struct drawFigureReturn { drawFigureReturn drawFigure(const int whatToDraw); -void updateUniformColor(const unsigned int shaderProgram, +void updateUniformColor(const Shader shaderProgram, const std::string uniformName); drawFigureReturn draw( diff --git a/Engine/engine/match b/Engine/engine/match index ba5d0e2..143e71c 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 a506214..920d8e3 100644 --- a/Engine/engine/shader.cpp +++ b/Engine/engine/shader.cpp @@ -78,6 +78,10 @@ void Shader::setFloat(const std::string &name, float value) const { glUniform1f(glGetUniformLocation(ID, name.c_str()), value); } +void Shader::set4Float(const std::string &name, const float floatOne, const float floatTwo, const float floatThree, const float floatFour) const { + glUniform4f(glGetUniformLocation(ID, name.c_str()), floatOne, floatTwo, floatThree, floatFour); +} + void Shader::checkCompileErrors(unsigned int shader, std::string type) { int success; char infoLog[1024]; diff --git a/Engine/engine/shader.hpp b/Engine/engine/shader.hpp index 41bfc82..188c150 100644 --- a/Engine/engine/shader.hpp +++ b/Engine/engine/shader.hpp @@ -27,6 +27,8 @@ class Shader { // ------------------------------------------------------------------------ void setFloat(const std::string &name, float value) const; + void set4Float(const std::string &name, const float floatOne, const float floatTwo, const float floatThree, const float floatFour) const; + private: // utility function for checking shader compilation/linking errors. // ------------------------------------------------------------------------