Finished transformations section

This commit is contained in:
Daniel 2023-07-29 18:47:40 +02:00
parent 46ee2d9102
commit de5a6d1bfd
3 changed files with 26 additions and 11 deletions

View File

@ -10,8 +10,8 @@
#include "shaders/Shader.h" #include "shaders/Shader.h"
#include "util/stb_image.h" #include "util/stb_image.h"
// Continue: https://learnopengl.com/Getting-started/Transformations // Continue: https://learnopengl.com/Getting-started/Coordinate-Systems
// Chapter: GLM // Chapter: not started
// //
// TODO: look at project->properties->VC++ Directories-> change everything to the Environment var // TODO: look at project->properties->VC++ Directories-> change everything to the Environment var
// For the "real" Nebulix Engine setup everything so it can be compiled/used with VSCode/CLion and not just VS (so basically having an "external" folder which has open gl, GLAD, etc. in it or something like this) // For the "real" Nebulix Engine setup everything so it can be compiled/used with VSCode/CLion and not just VS (so basically having an "external" folder which has open gl, GLAD, etc. in it or something like this)
@ -165,9 +165,15 @@ int main()
ProcessInput(window); ProcessInput(window);
glm::mat4 transform = glm::mat4(1.0f);
transform = glm::rotate(transform, (float)glfwGetTime(), glm::vec3(0, 0, 1.0f));
transform = glm::translate(transform, glm::vec3(glm::sin((float)glfwGetTime()), 0, 0));
//transform = glm::scale(transform, glm::vec3(glm::sin((float)glfwGetTime())));
shader->Use(); shader->Use();
shader->setInt("ourTexture1", 0); shader->SetInt("ourTexture1", 0);
shader->setInt("ourTexture2", 1); shader->SetInt("ourTexture2", 1);
shader->SetMatrix("transform", transform);
//float time = glfwGetTime(); //float time = glfwGetTime();
//float greenValue = (sin(time) / 2.0f) + 0.5f; //float greenValue = (sin(time) / 2.0f) + 0.5f;
//shader->setFloat("ourColour", 0.0f, greenValue, 0.0f, 0.0f); //shader->setFloat("ourColour", 0.0f, greenValue, 0.0f, 0.0f);

View File

@ -3,6 +3,8 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <glad/glad.h> #include <glad/glad.h>
#include <glm/gtc/type_ptr.hpp>
#include "Enums.h" #include "Enums.h"
@ -23,31 +25,36 @@ namespace Nebulix
/// </summary> /// </summary>
void Use() { glUseProgram(shaderId); } void Use() { glUseProgram(shaderId); }
void setBool(const std::string& name, bool value) const void SetBool(const std::string& name, bool value) const
{ {
glUniform1i(glGetUniformLocation(shaderId, name.c_str()), (int)value); glUniform1i(glGetUniformLocation(shaderId, name.c_str()), (int)value);
} }
void setInt(const std::string& name, int value) const void SetInt(const std::string& name, int value) const
{ {
glUniform1i(glGetUniformLocation(shaderId, name.c_str()), value); glUniform1i(glGetUniformLocation(shaderId, name.c_str()), value);
} }
void setFloat(const std::string& name, float x) const void SetFloat(const std::string& name, float x) const
{ {
glUniform1f(glGetUniformLocation(shaderId, name.c_str()), x); glUniform1f(glGetUniformLocation(shaderId, name.c_str()), x);
} }
void setFloat(const std::string& name, float x, float y) const void SetFloat(const std::string& name, float x, float y) const
{ {
glUniform2f(glGetUniformLocation(shaderId, name.c_str()), x, y); glUniform2f(glGetUniformLocation(shaderId, name.c_str()), x, y);
} }
void setFloat(const std::string& name, float x, float y, float z) const void SetFloat(const std::string& name, float x, float y, float z) const
{ {
glUniform3f(glGetUniformLocation(shaderId, name.c_str()), x, y, z); glUniform3f(glGetUniformLocation(shaderId, name.c_str()), x, y, z);
} }
void setFloat(const std::string& name, float x, float y, float z, float w) const void SetFloat(const std::string& name, float x, float y, float z, float w) const
{ {
glUniform4f(glGetUniformLocation(shaderId, name.c_str()), x, y, z, w); glUniform4f(glGetUniformLocation(shaderId, name.c_str()), x, y, z, w);
} }
void SetMatrix(const std::string& name, glm::mat4 mat) const
{
glUniformMatrix4fv(glGetUniformLocation(shaderId, name.c_str()), 1, GL_FALSE, glm::value_ptr(mat));
}
private: private:
std::string &_vertexFile, &_fragmentFile; std::string &_vertexFile, &_fragmentFile;
GLuint shaderId; GLuint shaderId;

View File

@ -6,9 +6,11 @@ layout (location = 2) in vec2 aTexCoord;
out vec3 ourColour; out vec3 ourColour;
out vec2 texCoord; out vec2 texCoord;
uniform mat4 transform;
void main() void main()
{ {
gl_Position = vec4(aPos, 1.0); gl_Position = transform * vec4(aPos, 1.0);
ourColour = aColour; ourColour = aColour;
texCoord = aTexCoord; texCoord = aTexCoord;
} }