allowed for buffer data updating

This commit is contained in:
Lauchmelder 2021-11-18 15:16:31 +01:00
parent e1e149e5c7
commit a206be747c
4 changed files with 14 additions and 40 deletions

1
README.md Normal file
View file

@ -0,0 +1 @@
#Spherical Harmonics

View file

@ -21,6 +21,7 @@ Model::Model(std::vector<float>&& vertices, std::vector<unsigned int>&& indices)
Model::~Model() Model::~Model()
{ {
} }
void Model::Draw() void Model::Draw()
@ -35,18 +36,23 @@ void Model::CreateVAO()
glBindVertexArray(vao); glBindVertexArray(vao);
glGenBuffers(1, &vbo); glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_STATIC_DRAW);
glGenBuffers(1, &ebo); glGenBuffers(1, &ebo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(), GL_STATIC_DRAW);
UpdateBufferData();
DefineVAOLayout(); DefineVAOLayout();
glBindVertexArray(0); glBindVertexArray(0);
} }
void Model::UpdateBufferData()
{
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(), GL_STATIC_DRAW);
}
void Model::DefineVAOLayout() void Model::DefineVAOLayout()
{ {
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);

View file

@ -14,6 +14,7 @@ public:
protected: protected:
void CreateVAO(); void CreateVAO();
void UpdateBufferData();
virtual void DefineVAOLayout(); virtual void DefineVAOLayout();
protected: protected:

View file

@ -5,7 +5,6 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include "Model.hpp"
#include "Orbital.hpp" #include "Orbital.hpp"
#include "Shader.hpp" #include "Shader.hpp"
#include "Camera.hpp" #include "Camera.hpp"
@ -55,40 +54,7 @@ int main(int argc, char** argv)
return -1; return -1;
} }
Model triangle( Orbital orbital(2, 1);
{
-1.0f, -1.0f, 1.0f, // Front Bottom, Left
-1.0f, 1.0f, 1.0f, // Front Top Left
1.0f, 1.0f, 1.0f, // Front Top Right
1.0f, -1.0f, 1.0f, // Front Bottom Right
-1.0f, -1.0f, -1.0f, // Back Bottom, Left
-1.0f, 1.0f, -1.0f, // Back Top Left
1.0f, 1.0f, -1.0f, // Back Top Right
1.0f, -1.0f, -1.0f, // Back Bottom Right
},
{
0, 1, 2,
0, 2, 3,
3, 2, 6,
3, 6, 7,
4, 5, 1,
4, 1, 0,
1, 5, 6,
1, 6, 2,
4, 0, 3,
4, 3, 7,
7, 6, 5,
7, 5, 4
}
);
Orbital orbital(4, 2);
glm::mat4 modelMatrix = glm::mat4(1.0f); glm::mat4 modelMatrix = glm::mat4(1.0f);
modelMatrix = glm::rotate(modelMatrix, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f)); modelMatrix = glm::rotate(modelMatrix, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));