Abstracted away the creation of buffers

Added a transform
Updated the TODO.md
Updated default shaders to include the apropriate three 4x4 matrices to
render in 3D
This commit is contained in:
2022-05-04 15:27:42 +02:00
parent af4a114fad
commit eb0e7f7a51
8 changed files with 131 additions and 50 deletions

View File

@ -0,0 +1,47 @@
#include <MyGraphicsEngine/Buffer.h>
int Buffer::getBufferID() {
return id;
}
void Buffer::createBuffer() {
glGenBuffers(1, (GLuint*) &id);
}
void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
if (elementBuffer) {
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
}
else {
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
}
}
void Buffer::Bind(bool elementBuffer = false ) {
if (elementBuffer) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
}
else {
glBindBuffer(GL_ARRAY_BUFFER, id);
}
}
void Buffer::Unbind(bool elementBuffer = false) {
if (elementBuffer) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
else {
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
void Buffer::Delete() {
glDeleteBuffers(1, (GLuint*) &id);
}

View File

@ -0,0 +1,19 @@
#pragma once
#include <glad/glad.h>
class Buffer {
private:
unsigned int id;
public:
int getBufferID();
void createBuffer();
void setBufferData(void* data, size_t dataSize, bool elementBuffer );
void Bind(bool elementBuffer);
void Unbind(bool elementBuffer);
void Delete();
};

View File

@ -0,0 +1,8 @@
#pragma once
#include <glm/glm.hpp>
struct Transform {
glm::vec3 Position;
glm::vec3 Rotation;
glm::vec3 Scale;
};

View File

@ -1,7 +1,7 @@
#version 330 core
#version 440 core
out vec4 FragColor;
void main{
void main(){
FragColor = vec4(0.0f, 1.0f, 0.0f , 1.0f);
}

View File

@ -1,6 +1,10 @@
#version 330 core
layout in vec3 aPos;
#version 440 core
in layout(location=0) vec3 aPos;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
void main() {
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
gl_Position = P * V * M * vec4(aPos.x, aPos.y, aPos.z, 1.0);
}