generated from karl/cpp-template
31 lines
752 B
C++
31 lines
752 B
C++
#include "VertexBuffer.h"
|
|
|
|
VertexBuffer::VertexBuffer() {
|
|
glGenVertexArrays(1, &vertex_array);
|
|
glGenBuffers(1, &vertex_buffer);
|
|
}
|
|
|
|
void VertexBuffer::set_data(unsigned int size, const void *data, int flag) {
|
|
this->size = size;
|
|
|
|
glBindVertexArray(vertex_array);
|
|
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, size, data, flag);
|
|
|
|
// TODO: Generalize
|
|
// This tells that the data consists of 2xfloat packets
|
|
glEnableVertexAttribArray(0);
|
|
glVertexAttribPointer(0, 2, GL_FLOAT, false, 2 * sizeof(float), 0);
|
|
|
|
glBindVertexArray(0);
|
|
}
|
|
|
|
void VertexBuffer::bind() {
|
|
glBindVertexArray(vertex_array);
|
|
}
|
|
|
|
void VertexBuffer::draw() {
|
|
bind();
|
|
glDrawArrays(GL_TRIANGLES, 0, size);
|
|
} |