Change Vertex floats to vectors
This commit is contained in:
@@ -24,6 +24,7 @@ add_executable(Fall-Fever
|
||||
VertexBuffer.cpp
|
||||
Texture.cpp
|
||||
Camera.cpp
|
||||
Mesh.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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[] = {
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
@@ -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);
|
||||
|
||||
17
defines.h
17
defines.h
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user