Change Vertex floats to vectors

This commit is contained in:
4VRDriver
2020-09-04 11:33:59 +02:00
parent f8da266fc0
commit eab5c4e5e0
8 changed files with 37 additions and 26 deletions

View File

@@ -24,6 +24,7 @@ add_executable(Fall-Fever
VertexBuffer.cpp
Texture.cpp
Camera.cpp
Mesh.cpp
)
target_link_libraries(

View File

@@ -1,8 +1,6 @@
#include "Camera.h"
#include "eventActions.h"
#include <iostream>
Camera::Camera(float fov, int width, int height) {
this->fov = fov;
viewMatrix = glm::mat4(1.0f);

View File

@@ -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[] = {

1
Mesh.cpp Normal file
View File

@@ -0,0 +1 @@
#include "Mesh.h"

1
Mesh.h Normal file
View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -2,6 +2,7 @@
#include <cstdint>
#include <glad/glad.h>
#include <string>
class Texture {
@@ -21,6 +22,8 @@ private:
GLuint textureId;
std::string textureType;
GLuint shaderProgramId;
};

View File

@@ -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);

View File

@@ -1,20 +1,19 @@
#pragma once
#include <glm/glm.hpp>
#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;
};