aboutsummaryrefslogtreecommitdiff
path: root/src/buffer/vertex/texture_display_vertex_buffer.cc
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-26 13:20:47 +0200
committerAdrian Kummerlaender2018-05-26 13:21:40 +0200
commit34052b51e00c939a35294d7085cadb5111484dd3 (patch)
tree03a5b1e350e47e2aa8551393ef67b2124ad50ddb /src/buffer/vertex/texture_display_vertex_buffer.cc
parentf728e4c8d202de241673a13ce61570b6acb4bba7 (diff)
downloadcomputicle-34052b51e00c939a35294d7085cadb5111484dd3.tar
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.gz
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.bz2
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.lz
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.xz
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.zst
computicle-34052b51e00c939a35294d7085cadb5111484dd3.zip
Separate headers into compilation units
Diffstat (limited to 'src/buffer/vertex/texture_display_vertex_buffer.cc')
-rw-r--r--src/buffer/vertex/texture_display_vertex_buffer.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/buffer/vertex/texture_display_vertex_buffer.cc b/src/buffer/vertex/texture_display_vertex_buffer.cc
new file mode 100644
index 0000000..005ea76
--- /dev/null
+++ b/src/buffer/vertex/texture_display_vertex_buffer.cc
@@ -0,0 +1,46 @@
+#include "texture_display_vertex_buffer.h"
+
+TextureDisplayVertexBuffer::TextureDisplayVertexBuffer():
+ _data{
+ -1.f, 1.f, 0.f, 1.f,
+ -1.f, -1.f, 0.f, 0.f,
+ 1.f, -1.f, 1.f, 0.f,
+
+ -1.f, 1.f, 0.f, 1.f,
+ 1.f, -1.f, 1.f, 0.f,
+ 1.f, 1.f, 1.f, 1.f
+ } {
+ glGenVertexArrays(1, &_array);
+ glGenBuffers(1, &_buffer);
+
+ glBindVertexArray(_array);
+ glBindBuffer(GL_ARRAY_BUFFER, _buffer);
+ glBufferData(
+ GL_ARRAY_BUFFER,
+ _data.size() * sizeof(GLfloat),
+ _data.data(),
+ GL_STATIC_DRAW
+ );
+
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(
+ 0, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat), (void*)0);
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(
+ 1, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat), (void*)(2*sizeof(GLfloat)));
+}
+
+TextureDisplayVertexBuffer::~TextureDisplayVertexBuffer() {
+ glDeleteBuffers(1, &_buffer);
+ glDeleteVertexArrays(1, &_array);
+}
+
+GLuint TextureDisplayVertexBuffer::getBuffer() const {
+ return _buffer;
+}
+
+void TextureDisplayVertexBuffer::draw(const std::vector<GLuint>& textures) const {
+ glBindVertexArray(_array);
+ glBindTextures(textures[0], textures.size(), textures.data());
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+}