diff options
author | uis <uis9936@gmail.com> | 2018-12-19 12:45:39 +0100 |
---|---|---|
committer | uis <uis9936@gmail.com> | 2018-12-20 20:01:07 +0100 |
commit | 3770fee3778f74112d3687ad0c382f0aefa5d7a4 (patch) | |
tree | bf748a539a3c9c18e3fefcba0c2be4ab5e0c67a8 /src | |
parent | #11 Single field for ip and port (diff) | |
download | AltCraft-3770fee3778f74112d3687ad0c382f0aefa5d7a4.tar AltCraft-3770fee3778f74112d3687ad0c382f0aefa5d7a4.tar.gz AltCraft-3770fee3778f74112d3687ad0c382f0aefa5d7a4.tar.bz2 AltCraft-3770fee3778f74112d3687ad0c382f0aefa5d7a4.tar.lz AltCraft-3770fee3778f74112d3687ad0c382f0aefa5d7a4.tar.xz AltCraft-3770fee3778f74112d3687ad0c382f0aefa5d7a4.tar.zst AltCraft-3770fee3778f74112d3687ad0c382f0aefa5d7a4.zip |
Diffstat (limited to '')
-rw-r--r-- | src/RendererEntity.cpp | 62 | ||||
-rw-r--r-- | src/RendererEntity.hpp | 4 | ||||
-rw-r--r-- | src/RendererWorld.cpp | 19 |
3 files changed, 32 insertions, 53 deletions
diff --git a/src/RendererEntity.cpp b/src/RendererEntity.cpp index a987139..d465a07 100644 --- a/src/RendererEntity.cpp +++ b/src/RendererEntity.cpp @@ -8,53 +8,30 @@ #include "Renderer.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, 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, 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, -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, + 0.5f, 0.5f, 0.5f, + 0.5f, 0.5f, -0.5f }; const GLfloat uv_coords[] = { @@ -110,12 +87,7 @@ const GLfloat uv_coords[] = { const GLuint magic = 993214; GLuint Vbo = magic,Vao = magic,Vbo2 = magic; -RendererEntity::RendererEntity(World *ptr, unsigned int id) -{ - world = ptr; - entityId = id; - - +GLuint RendererEntity::GetVao(){ if (Vbo == magic) { glGenBuffers(1, &Vbo); glBindBuffer(GL_ARRAY_BUFFER, Vbo); @@ -128,7 +100,7 @@ RendererEntity::RendererEntity(World *ptr, unsigned int id) glGenVertexArrays(1, &Vao); glBindVertexArray(Vao); { - glBindBuffer(GL_ARRAY_BUFFER, Vbo); + glBindBuffer(GL_ARRAY_BUFFER, Vbo); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0); glEnableVertexAttribArray(0); @@ -138,13 +110,19 @@ RendererEntity::RendererEntity(World *ptr, unsigned int id) } glBindVertexArray(0); } + return Vao; +} + +RendererEntity::RendererEntity(World *ptr, unsigned int id) +{ + world = ptr; + entityId = id; } RendererEntity::~RendererEntity() { } void RendererEntity::Render(RenderState & renderState) { - renderState.SetActiveVao(Vao); glm::mat4 model = glm::mat4(1.0); Entity& entity = world->GetEntity(entityId); model = glm::translate(model, entity.pos.glm()); @@ -154,7 +132,7 @@ void RendererEntity::Render(RenderState & renderState) { glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); glUniform3f(colorLoc, entity.renderColor.x, entity.renderColor.y, entity.renderColor.z); glCheckError(); - glDrawArrays(GL_LINE_STRIP, 0, 36); + glDrawArrays(GL_LINES, 0, 24); glCheckError(); -}
\ No newline at end of file +} diff --git a/src/RendererEntity.hpp b/src/RendererEntity.hpp index 76548c6..51d4163 100644 --- a/src/RendererEntity.hpp +++ b/src/RendererEntity.hpp @@ -16,4 +16,6 @@ public: GLint modelLoc = 0; GLint colorLoc = 0; -};
\ No newline at end of file + + static GLuint GetVao(); +}; diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index bb8c8f4..e1dd52c 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -291,13 +291,13 @@ void RendererWorld::Render(RenderState & renderState) { glCheckError(); modelLoc = glGetUniformLocation(entityShader->Program, "model"); colorLoc = glGetUniformLocation(entityShader->Program, "color"); + + renderState.SetActiveVao(RendererEntity::GetVao()); for (auto& it : entities) { it.modelLoc = modelLoc; it.colorLoc = colorLoc; it.Render(renderState); } - glLineWidth(1.0); - glCheckError(); //Render selected block Vector selectedBlock = gs->selectedBlock; @@ -311,16 +311,14 @@ void RendererWorld::Render(RenderState & renderState) { glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); glUniform3f(colorLoc, 0.0, 0.0, 0.0); glCheckError(); - glDrawArrays(GL_LINE_STRIP, 0, 36); + glDrawArrays(GL_LINES, 0, 24); } - glLineWidth(1.0f); - glCheckError(); } //Render raycast hit - bool renderHit = false; + const bool renderHit = false; if (renderHit) { - VectorF hit = gs->raycastHit; + VectorF hit = gs->raycastHit; glLineWidth(2.0f); { glm::mat4 model; @@ -334,10 +332,11 @@ void RendererWorld::Render(RenderState & renderState) { glCheckError(); glDrawArrays(GL_LINE_STRIP, 0, 36); } - glLineWidth(1.0f); - glCheckError(); } + glLineWidth(1.0); + glCheckError(); + //Render sky renderState.TimeOfDay = gs->TimeOfDay; renderState.SetActiveShader(skyShader->Program); @@ -464,4 +463,4 @@ void RendererWorld::Update(double timeToUpdate) { GameState* RendererWorld::GameStatePtr() { return gs; -}
\ No newline at end of file +} |