-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOpenGLUtils.cpp
More file actions
26 lines (21 loc) · 821 Bytes
/
OpenGLUtils.cpp
File metadata and controls
26 lines (21 loc) · 821 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
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <vector>
#include <iostream>
void initializeBuffers(GLuint& VAO, GLuint& VBO) {
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0);
}
void updateVertexBuffer(GLuint VBO, const std::vector<float>& vertices) {
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_DYNAMIC_DRAW);
}
void drawCircle(GLuint VAO, GLuint VBO, const std::vector<float>& vertices, GLenum mode) {
glBindVertexArray(VAO);
glDrawArrays(mode, 0, static_cast<GLsizei>(vertices.size() / 2));
glBindVertexArray(0);
}