-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimitive.cpp
More file actions
44 lines (34 loc) · 983 Bytes
/
Primitive.cpp
File metadata and controls
44 lines (34 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "Primitive.h"
Primitive::Primitive() : vaoID(0), vboID(0)
{
position = glm::vec3(0.0f);
rotation = glm::vec3(0.0f);
scale = glm::vec3(1.0f);
}
Primitive::~Primitive()
{
glDeleteVertexArrays(1, &vaoID);
glDeleteBuffers(1, &vboID);
}
void Primitive::bindVertexArray()
{
glBindVertexArray(vaoID);
}
void Primitive::unbindVertexArray()
{
glBindVertexArray(0);
}
void Primitive::createIDs()
{
glGenVertexArrays(1, &vaoID);
glGenBuffers(1, &vboID);
glBindVertexArray(vaoID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), &vertices[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, normal));
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}