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 "util/stb_image.h"
// Continue: https://learnopengl.com/Getting-started/Transformations
// Chapter: GLM
// Continue: https://learnopengl.com/Getting-started/Coordinate-Systems
// Chapter: not started
//
// 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)
@ -165,9 +165,15 @@ int main()
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->setInt("ourTexture1", 0);
shader->setInt("ourTexture2", 1);
shader->SetInt("ourTexture1", 0);
shader->SetInt("ourTexture2", 1);
shader->SetMatrix("transform", transform);
//float time = glfwGetTime();
//float greenValue = (sin(time) / 2.0f) + 0.5f;
//shader->setFloat("ourColour", 0.0f, greenValue, 0.0f, 0.0f);

View File

@ -3,6 +3,8 @@
#include <vector>
#include <string>
#include <glad/glad.h>
#include <glm/gtc/type_ptr.hpp>
#include "Enums.h"
@ -23,31 +25,36 @@ namespace Nebulix
/// </summary>
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
void SetMatrix(const std::string& name, glm::mat4 mat) const
{
glUniformMatrix4fv(glGetUniformLocation(shaderId, name.c_str()), 1, GL_FALSE, glm::value_ptr(mat));
}
private:
std::string &_vertexFile, &_fragmentFile;
GLuint shaderId;

View File

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