diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-08-20 17:21:29 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-08-20 17:21:29 +0200 |
commit | c62e2cd49649109f0135e56ee8add0dab2254d01 (patch) | |
tree | 7e6240186a3801daf0189d1883081b93b5f1eb5c /src/RendererSky.cpp | |
parent | 2017-08-19 (diff) | |
download | AltCraft-c62e2cd49649109f0135e56ee8add0dab2254d01.tar AltCraft-c62e2cd49649109f0135e56ee8add0dab2254d01.tar.gz AltCraft-c62e2cd49649109f0135e56ee8add0dab2254d01.tar.bz2 AltCraft-c62e2cd49649109f0135e56ee8add0dab2254d01.tar.lz AltCraft-c62e2cd49649109f0135e56ee8add0dab2254d01.tar.xz AltCraft-c62e2cd49649109f0135e56ee8add0dab2254d01.tar.zst AltCraft-c62e2cd49649109f0135e56ee8add0dab2254d01.zip |
Diffstat (limited to '')
-rw-r--r-- | src/RendererSky.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/src/RendererSky.cpp b/src/RendererSky.cpp new file mode 100644 index 0000000..e0e367b --- /dev/null +++ b/src/RendererSky.cpp @@ -0,0 +1,140 @@ +#include "RendererSky.hpp" + +const GLfloat vertices[] = { + //Z+ edge + -0.5f, -0.5f, 0.5f, + -0.5f, 0.5f, 0.5f, + 0.5f, -0.5f, 0.5f, + 0.5f, -0.5f, 0.5f, + -0.5f, 0.5f, 0.5f, + 0.5f, 0.5f, 0.5f, + + //Z- edge + -0.5f, 0.5f, -0.5f, + -0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, + -0.5f, 0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, + 0.5f, 0.5f, -0.5f, + + //X+ edge + -0.5f, -0.5f, 0.5f, + -0.5f, -0.5f, -0.5f, + -0.5f, 0.5f, -0.5f, + -0.5f, -0.5f, 0.5f, + -0.5f, 0.5f, -0.5f, + -0.5f, 0.5f, 0.5f, + + //X- edge + 0.5f, 0.5f, -0.5f, + 0.5f, -0.5f, 0.5f, + 0.5f, 0.5f, 0.5f, + 0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, 0.5f, + 0.5f, 0.5f, -0.5f, + + //Y+ edge + -0.5f, 0.5f, 0.5f, + 0.5f, 0.5f, -0.5f, + 0.5f, 0.5f, 0.5f, + -0.5f, 0.5f, -0.5f, + 0.5f, 0.5f, -0.5f, + -0.5f, 0.5f, 0.5f, + + //Y- edge + 0.5f, -0.5f, -0.5f, + -0.5f, -0.5f, 0.5f, + 0.5f, -0.5f, 0.5f, + 0.5f, -0.5f, -0.5f, + -0.5f, -0.5f, -0.5f, + -0.5f, -0.5f, 0.5f, +}; + +const GLfloat uv_coords[] = { + //Z+ + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 0.0f, + 1.0f, 1.0f, + + //Z- + 1.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 0.0f, + 0.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 1.0f, + + //X+ + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 0.0f, 1.0f, + 1.0f, 0.0f, + 1.0f, 1.0f, + + //X- + 0.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 0.0f, + 1.0f, 1.0f, + + //Y+ + 0.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 0.0f, + 1.0f, 1.0f, + + //Y- + 1.0f, 0.0f, + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 1.0f, + 1.0f, 0.0f, +}; + +RendererSky::RendererSky() { + glGenBuffers(1, &VboVert); + glBindBuffer(GL_ARRAY_BUFFER, VboVert); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + + glGenBuffers(1, &VboUv); + glBindBuffer(GL_ARRAY_BUFFER, VboUv); + glBufferData(GL_ARRAY_BUFFER, sizeof(uv_coords), uv_coords, GL_STATIC_DRAW); + glGenVertexArrays(1, &Vao); + + glBindVertexArray(Vao); + { + glBindBuffer(GL_ARRAY_BUFFER, VboVert); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0); + glEnableVertexAttribArray(0); + + glBindBuffer(GL_ARRAY_BUFFER, VboUv); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid*)0); + glEnableVertexAttribArray(1); + } + glBindVertexArray(0); + glCheckError(); +} + +RendererSky::~RendererSky() +{ + glDeleteBuffers(1, &VboVert); + glDeleteBuffers(1, &VboUv); + glDeleteVertexArrays(1, &Vao); + //glCheckError(); +} + +void RendererSky::Render(RenderState &renderState) +{ + renderState.SetActiveVao(Vao); + glDrawArrays(GL_TRIANGLES, 0, 36); + glCheckError(); +} |