-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathobject.cpp
More file actions
54 lines (47 loc) · 1.51 KB
/
Copy pathobject.cpp
File metadata and controls
54 lines (47 loc) · 1.51 KB
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
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <vector>
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
#include <GL/glew.h>
#include "global.h"
#include "object.h"
using namespace glm;
void Object::setupVAO()
{
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
if (!vertices.empty()) {
GLuint bVertex;
glGenBuffers(1, &bVertex);
glBindBuffer(GL_ARRAY_BUFFER, bVertex);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(vec3), vertices.data(), GL_STATIC_DRAW);
glEnableVertexAttribArray(ATTRIB_POSITION);
glVertexAttribPointer(ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, 0, 0);
}
if (!normals.empty()) {
GLuint bNormal;
glGenBuffers(1, &bNormal);
glBindBuffer(GL_ARRAY_BUFFER, bNormal);
glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(vec3), normals.data(), GL_STATIC_DRAW);
glEnableVertexAttribArray(ATTRIB_NORMAL);
glVertexAttribPointer(ATTRIB_NORMAL, 3, GL_FLOAT, GL_FALSE, 0, 0);
}
if (!texCoords.empty()) {
GLuint bTexCoord;
glGenBuffers(1, &bTexCoord);
glBindBuffer(GL_ARRAY_BUFFER, bTexCoord);
glBufferData(GL_ARRAY_BUFFER, texCoords.size() * sizeof(vec2), texCoords.data(), GL_STATIC_DRAW);
glEnableVertexAttribArray(ATTRIB_TEXCOORD);
glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, 0);
}
if (!indices.empty()) {
GLuint bIndex;
glGenBuffers(1, &bIndex);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bIndex);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), indices.data(), GL_STATIC_DRAW);
}
}
void Object::bind()
{
glBindVertexArray(vao);
}