From 4f1ea8327a11d622b27d6a75e2b70b4b83f278f3 Mon Sep 17 00:00:00 2001 From: "Grayson Riffe (Laptop)" Date: Fri, 27 Aug 2021 12:57:30 -0500 Subject: [PATCH] Added projection matrix; Now 3D --- NothinFancy/res/defaultShader/vertex.shader | 2 +- NothinFancy/src/Renderer/Drawable/Entity.cpp | 3 ++- NothinFancy/src/Renderer/Drawable/Model.cpp | 3 +-- NothinFancy/src/Renderer/Renderer.cpp | 2 ++ NothinFancy/src/Renderer/Shader.cpp | 2 +- NothinFancy/src/include/Entity.h | 2 +- NothinFancy/src/include/NothinFancy.h | 3 ++- NothinFancy/src/include/Renderer.h | 3 +++ NothinFancy/src/include/Shader.h | 1 - 9 files changed, 13 insertions(+), 8 deletions(-) diff --git a/NothinFancy/res/defaultShader/vertex.shader b/NothinFancy/res/defaultShader/vertex.shader index 3527294..194f98b 100644 --- a/NothinFancy/res/defaultShader/vertex.shader +++ b/NothinFancy/res/defaultShader/vertex.shader @@ -11,6 +11,6 @@ out vec2 texCoord; void main() { //gl_Position = proj * view * model * vec4(pos, 1.0); - gl_Position = model * vec4(pos, 1.0); + gl_Position = proj * model * vec4(pos, 1.0); texCoord = texCoords; } diff --git a/NothinFancy/src/Renderer/Drawable/Entity.cpp b/NothinFancy/src/Renderer/Drawable/Entity.cpp index b76abf3..3df5cef 100644 --- a/NothinFancy/src/Renderer/Drawable/Entity.cpp +++ b/NothinFancy/src/Renderer/Drawable/Entity.cpp @@ -2,6 +2,7 @@ namespace nf { Entity::Entity() : + m_model(nullptr), m_position(0.0), m_rotation(0.0), m_scale(1.0) @@ -14,7 +15,7 @@ namespace nf { m_model->create(vertexBufferData, vertexBufferSize, indexBufferData, indexBufferCount); } - void Entity::setLocation(float x, float y, float z) { + void Entity::setPosition(float x, float y, float z) { m_position = { x, y, z }; } diff --git a/NothinFancy/src/Renderer/Drawable/Model.cpp b/NothinFancy/src/Renderer/Drawable/Model.cpp index 63f11d5..9958fb4 100644 --- a/NothinFancy/src/Renderer/Drawable/Model.cpp +++ b/NothinFancy/src/Renderer/Drawable/Model.cpp @@ -9,8 +9,7 @@ namespace nf { void Model::create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount) { m_vao = new VertexArray; m_vao->addBuffer(vertexBufferData, vertexBufferSize); - m_vao->push(2); - //TODO: Change this to 3 + m_vao->push(3); m_vao->finishBufferLayout(); m_ib = new IndexBuffer(indexBufferData, indexBufferCount); } diff --git a/NothinFancy/src/Renderer/Renderer.cpp b/NothinFancy/src/Renderer/Renderer.cpp index 4bf9944..e31c301 100644 --- a/NothinFancy/src/Renderer/Renderer.cpp +++ b/NothinFancy/src/Renderer/Renderer.cpp @@ -70,11 +70,13 @@ namespace nf { void Renderer::doFrame() { glViewport(0, 0, m_app->getConfig().width, m_app->getConfig().height); + proj = glm::perspective(glm::radians(45.0f), (float)m_app->getConfig().width / (float)m_app->getConfig().height, 0.1f, 100.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); for (Entity* draw : m_lGame) { Entity& curr = *draw; curr.bind(m_defaultShader); + m_defaultShader->setUniform("proj", proj); glDrawElements(GL_TRIANGLES, curr.getModel()->getIndexCount(), GL_UNSIGNED_INT, nullptr); } m_lGame.clear(); diff --git a/NothinFancy/src/Renderer/Shader.cpp b/NothinFancy/src/Renderer/Shader.cpp index 64f4e8c..9c9f921 100644 --- a/NothinFancy/src/Renderer/Shader.cpp +++ b/NothinFancy/src/Renderer/Shader.cpp @@ -51,7 +51,7 @@ namespace nf { } void Shader::setUniform(const char* name, glm::mat4& data) { - if (m_uniformLocations.find(name) != m_uniformLocations.end()) + if (m_uniformLocations.find(name) == m_uniformLocations.end()) getUniformLocation(name); glUniformMatrix4fv(m_uniformLocations[name], 1, GL_FALSE, glm::value_ptr(data)); } diff --git a/NothinFancy/src/include/Entity.h b/NothinFancy/src/include/Entity.h index 39ef8d0..3bf2ddd 100644 --- a/NothinFancy/src/include/Entity.h +++ b/NothinFancy/src/include/Entity.h @@ -13,7 +13,7 @@ namespace nf { void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount); //TODO: Do this using loaded assets somehow - void setLocation(float x, float y, float z); + void setPosition(float x, float y, float z); void setRotation(float x, float y, float z); void setScale(float x); void setScale(float x, float y, float z); diff --git a/NothinFancy/src/include/NothinFancy.h b/NothinFancy/src/include/NothinFancy.h index 5afc391..4bf6a8b 100644 --- a/NothinFancy/src/include/NothinFancy.h +++ b/NothinFancy/src/include/NothinFancy.h @@ -23,7 +23,8 @@ namespace nf { Entity(); void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount); - void setLocation(float x, float y, float z); + //TODO: Do this using loaded assets somehow + void setPosition(float x, float y, float z); void setRotation(float x, float y, float z); void setScale(float x); void setScale(float x, float y, float z); diff --git a/NothinFancy/src/include/Renderer.h b/NothinFancy/src/include/Renderer.h index 9c4b1e5..28f5f3f 100644 --- a/NothinFancy/src/include/Renderer.h +++ b/NothinFancy/src/include/Renderer.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include "glm/glm.hpp" #include "Entity.h" @@ -26,5 +27,7 @@ namespace nf { std::vector m_lGame; std::vector m_lUI; Shader* m_defaultShader; + + glm::mat4 proj; }; } \ No newline at end of file diff --git a/NothinFancy/src/include/Shader.h b/NothinFancy/src/include/Shader.h index 3f34082..5b93d7b 100644 --- a/NothinFancy/src/include/Shader.h +++ b/NothinFancy/src/include/Shader.h @@ -12,7 +12,6 @@ namespace nf { void bind(); void setUniform(const char* name, glm::mat4& data); - static unsigned int current; ~Shader();