diff options
author | Adrian Kummerlaender | 2018-05-21 21:16:56 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2018-05-21 21:20:08 +0200 |
commit | 617fec827652d216e2d1e5015f816c4400655d73 (patch) | |
tree | c2bdce2d375bebc4b7c9907543d57aeb642f7f82 /src/texture_display_buffer.h | |
parent | a8feed9d7951c9a947562ed687c704851a31ea9b (diff) | |
download | computicle-617fec827652d216e2d1e5015f816c4400655d73.tar computicle-617fec827652d216e2d1e5015f816c4400655d73.tar.gz computicle-617fec827652d216e2d1e5015f816c4400655d73.tar.bz2 computicle-617fec827652d216e2d1e5015f816c4400655d73.tar.lz computicle-617fec827652d216e2d1e5015f816c4400655d73.tar.xz computicle-617fec827652d216e2d1e5015f816c4400655d73.tar.zst computicle-617fec827652d216e2d1e5015f816c4400655d73.zip |
Abstract texture display buffer, shader
Diffstat (limited to 'src/texture_display_buffer.h')
-rw-r--r-- | src/texture_display_buffer.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/texture_display_buffer.h b/src/texture_display_buffer.h new file mode 100644 index 0000000..530b99d --- /dev/null +++ b/src/texture_display_buffer.h @@ -0,0 +1,59 @@ +#pragma once + +#include <vector> + +class TextureDisplayBuffer { +private: + const std::vector<GLfloat> _data; + + GLuint _texture; + GLuint _array; + GLuint _buffer; + +public: + TextureDisplayBuffer(GLuint texture): + _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 + }, + _texture(texture) { + 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))); + } + + ~TextureDisplayBuffer() { + glDeleteBuffers(1, &_buffer); + glDeleteVertexArrays(1, &_array); + } + + void draw() const { + glBindVertexArray(_array); + glBindTexture(GL_TEXTURE_2D, _texture); + glDrawArrays(GL_TRIANGLES, 0, 6); + } + + GLuint getBuffer() const { + return _buffer; + } +}; |