diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-06-21 13:15:59 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-06-21 13:15:59 +0100 |
commit | 4e8c07d3fd949287fc2361284a5a7704e642396e (patch) | |
tree | 18d7e5c2d41cedb00a29ac303637102c7d4b157d /src/sprite.cpp | |
parent | f3e75c7f821675740736b46094382d55c7e6ee5c (diff) | |
download | YAGE-4e8c07d3fd949287fc2361284a5a7704e642396e.tar.gz YAGE-4e8c07d3fd949287fc2361284a5a7704e642396e.zip |
Correcting indentation and removed vector2d.cpp
Diffstat (limited to 'src/sprite.cpp')
-rw-r--r-- | src/sprite.cpp | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/src/sprite.cpp b/src/sprite.cpp index 010b43a7..cd8f328d 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp @@ -12,71 +12,71 @@ Sprite::Sprite() Sprite::~Sprite() { - if(vbo_id_ != 0) - glDeleteBuffers(1, &vbo_id_); + if(vbo_id_ != 0) + glDeleteBuffers(1, &vbo_id_); } void Sprite::init(float x, float y, float width, float height, const std::string &texture_path) { - x_ = x; - y_ = y; - width_ = width; - height_ = height; - texture_ = ResourceManager::getTexture(texture_path); + x_ = x; + y_ = y; + width_ = width; + height_ = height; + texture_ = ResourceManager::getTexture(texture_path); - if(vbo_id_ == 0) - glGenBuffers(1, &vbo_id_); + if(vbo_id_ == 0) + glGenBuffers(1, &vbo_id_); - Vertex vertex_data[6]; + Vertex vertex_data[6]; - vertex_data[0].setPosition(x+width, y+height); - vertex_data[0].setUv(1.f, 1.f); + vertex_data[0].setPosition(x+width, y+height); + vertex_data[0].setUv(1.f, 1.f); - vertex_data[1].setPosition(x, y+height); - vertex_data[1].setUv(0.f, 1.f); + vertex_data[1].setPosition(x, y+height); + vertex_data[1].setUv(0.f, 1.f); - vertex_data[2].setPosition(x, y); - vertex_data[2].setUv(0.f, 0.f); + vertex_data[2].setPosition(x, y); + vertex_data[2].setUv(0.f, 0.f); - vertex_data[3].setPosition(x, y); - vertex_data[3].setUv(0.f, 0.f); + vertex_data[3].setPosition(x, y); + vertex_data[3].setUv(0.f, 0.f); - vertex_data[4].setPosition(x+width, y+height); - vertex_data[4].setUv(1.f, 1.f); + vertex_data[4].setPosition(x+width, y+height); + vertex_data[4].setUv(1.f, 1.f); - vertex_data[5].setPosition(x+width, y); - vertex_data[5].setUv(1.f, 0.f); + vertex_data[5].setPosition(x+width, y); + vertex_data[5].setUv(1.f, 0.f); - for(int i = 0; i < 6; ++i) - vertex_data[i].setColor(255, 0, 255, 255); + for(int i = 0; i < 6; ++i) + vertex_data[i].setColor(255, 0, 255, 255); - vertex_data[1].setColor(0, 255, 255, 255); - vertex_data[4].setColor(255, 0, 0, 255); + vertex_data[1].setColor(0, 255, 255, 255); + vertex_data[4].setColor(255, 0, 0, 255); - glBindBuffer(GL_ARRAY_BUFFER, vbo_id_); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, vbo_id_); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); } void Sprite::draw() { - glBindTexture(GL_TEXTURE_2D, texture_.id); - glBindBuffer(GL_ARRAY_BUFFER, vbo_id_); + glBindTexture(GL_TEXTURE_2D, texture_.id); + glBindBuffer(GL_ARRAY_BUFFER, vbo_id_); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glEnableVertexAttribArray(2); - - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, position)); - glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (void *)offsetof(Vertex, color)); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, uv)); - glDrawArrays(GL_TRIANGLES, 0, 6); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, position)); + glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (void *)offsetof(Vertex, color)); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, uv)); + glDrawArrays(GL_TRIANGLES, 0, 6); - glDisableVertexAttribArray(2); - glDisableVertexAttribArray(1); - glDisableVertexAttribArray(0); + glDisableVertexAttribArray(2); + glDisableVertexAttribArray(1); + glDisableVertexAttribArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); } } // yage |