From eab5c4e5e0c5ab1e2345efcb058f7b72276f10b6 Mon Sep 17 00:00:00 2001 From: 4VRDriver <44267643+4VRDriver@users.noreply.github.com> Date: Fri, 4 Sep 2020 11:33:59 +0200 Subject: [PATCH] Change Vertex floats to vectors --- CMakeLists.txt | 1 + Camera.cpp | 2 -- Controller.cpp | 32 ++++++++++++++++++++------------ Mesh.cpp | 1 + Mesh.h | 1 + Texture.h | 3 +++ VertexBuffer.cpp | 6 +++--- defines.h | 17 ++++++++--------- 8 files changed, 37 insertions(+), 26 deletions(-) create mode 100644 Mesh.cpp create mode 100644 Mesh.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1632fa6..6934676 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ add_executable(Fall-Fever VertexBuffer.cpp Texture.cpp Camera.cpp + Mesh.cpp ) target_link_libraries( diff --git a/Camera.cpp b/Camera.cpp index 4d19673..896c825 100644 --- a/Camera.cpp +++ b/Camera.cpp @@ -1,8 +1,6 @@ #include "Camera.h" #include "eventActions.h" -#include - Camera::Camera(float fov, int width, int height) { this->fov = fov; viewMatrix = glm::mat4(1.0f); diff --git a/Controller.cpp b/Controller.cpp index 133baea..613bbd5 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -45,18 +45,26 @@ void Controller::run() { shaderProgram.bind(); Vertex vertices[] = { - Vertex{-0.5f, -0.5f, 0.0f, - 0.0f, 0.0f, - 1.0f, 0.0f, 0.0f, 1.0f}, - Vertex{0.5f, -0.5f, 0.0f, - 1.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 1.0f}, - Vertex{-0.5f, 0.5f, 0.0f, - 0.0f, 1.0f, - 0.0f, 0.0f, 1.0f, 1.0f}, - Vertex{0.5f, 0.5f, 0.0f, - 1.0f, 1.0f, - 0.0f, 0.0f, 1.0f, 1.0f} + Vertex{ + glm::vec3(-0.5f, -0.5f, 0.0f), + glm::vec2(0.0f, 0.0f), + glm::vec3(0.0f, 0.0f, 0.0f), + glm::vec4(1.0f, 0.0f, 0.0f, 1.0f)}, + Vertex{ + glm::vec3(0.5f, -0.5f, 0.0f), + glm::vec2(1.0f, 0.0f), + glm::vec3(0.0f, 0.0f, 0.0f), + glm::vec4(0.0f, 1.0f, 0.0f, 1.0f)}, + Vertex{ + glm::vec3(-0.5f, 0.5f, 0.0f), + glm::vec2(0.0f, 1.0f), + glm::vec3(0.0f, 0.0f, 0.0f), + glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)}, + Vertex{ + glm::vec3(0.5f, 0.5f, 0.0f), + glm::vec2(1.0f, 1.0f), + glm::vec3(0.0f, 0.0f, 0.0f), + glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)} }; uint32_t indices[] = { diff --git a/Mesh.cpp b/Mesh.cpp new file mode 100644 index 0000000..49582af --- /dev/null +++ b/Mesh.cpp @@ -0,0 +1 @@ +#include "Mesh.h" diff --git a/Mesh.h b/Mesh.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/Mesh.h @@ -0,0 +1 @@ +#pragma once diff --git a/Texture.h b/Texture.h index 28c2f27..0917bc5 100644 --- a/Texture.h +++ b/Texture.h @@ -2,6 +2,7 @@ #include #include +#include class Texture { @@ -21,6 +22,8 @@ private: GLuint textureId; + std::string textureType; + GLuint shaderProgramId; }; \ No newline at end of file diff --git a/VertexBuffer.cpp b/VertexBuffer.cpp index d9b38f5..07441f1 100644 --- a/VertexBuffer.cpp +++ b/VertexBuffer.cpp @@ -18,15 +18,15 @@ VertexBuffer::VertexBuffer(void *vertexData, void *indexData, uint32_t numVertic // Position glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(struct Vertex, x)); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(struct Vertex, position)); // UV Texture Mapping glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(struct Vertex, u)); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(struct Vertex, textureCoords)); // Color glEnableVertexAttribArray(2); - glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(struct Vertex, r)); + glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(struct Vertex, color)); // This will also unbind the vertex buffer glBindVertexArray(0); diff --git a/defines.h b/defines.h index 04b353f..dbb0d5f 100644 --- a/defines.h +++ b/defines.h @@ -1,20 +1,19 @@ #pragma once +#include + #define INIT_WINDOW_WIDTH 960 #define INIT_WINDOW_HEIGHT 720 struct Vertex { // Postition - float x; - float y; - float z; + glm::vec3 position; // UV Texture Mapping - float u; - float v; + glm::vec2 textureCoords; + + // Normal vector + glm::vec3 normal; // Color - float r; - float g; - float b; - float a; + glm::vec4 color; };