Added projection matrix; Now 3D
This commit is contained in:
parent
bd8df1c2cf
commit
4f1ea8327a
@ -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;
|
||||
}
|
||||
|
@ -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 };
|
||||
}
|
||||
|
||||
|
@ -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<float>(2);
|
||||
//TODO: Change this to 3
|
||||
m_vao->push<float>(3);
|
||||
m_vao->finishBufferLayout();
|
||||
m_ib = new IndexBuffer(indexBufferData, indexBufferCount);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <Windows.h>
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
#include "Entity.h"
|
||||
|
||||
@ -26,5 +27,7 @@ namespace nf {
|
||||
std::vector<Entity*> m_lGame;
|
||||
std::vector<Drawable*> m_lUI;
|
||||
Shader* m_defaultShader;
|
||||
|
||||
glm::mat4 proj;
|
||||
};
|
||||
}
|
@ -12,7 +12,6 @@ namespace nf {
|
||||
|
||||
void bind();
|
||||
void setUniform(const char* name, glm::mat4& data);
|
||||
|
||||
static unsigned int current;
|
||||
|
||||
~Shader();
|
||||
|
Reference in New Issue
Block a user