summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-12-20 20:21:40 +0100
committerGitHub <noreply@github.com>2018-12-20 20:21:40 +0100
commitd8201e470891376d74a2b9e28743e8ba2f57174e (patch)
treebf748a539a3c9c18e3fefcba0c2be4ab5e0c67a8 /src
parentMerge pull request #28 from uis246/iss11 (diff)
parentFixes #29 (diff)
downloadAltCraft-d8201e470891376d74a2b9e28743e8ba2f57174e.tar
AltCraft-d8201e470891376d74a2b9e28743e8ba2f57174e.tar.gz
AltCraft-d8201e470891376d74a2b9e28743e8ba2f57174e.tar.bz2
AltCraft-d8201e470891376d74a2b9e28743e8ba2f57174e.tar.lz
AltCraft-d8201e470891376d74a2b9e28743e8ba2f57174e.tar.xz
AltCraft-d8201e470891376d74a2b9e28743e8ba2f57174e.tar.zst
AltCraft-d8201e470891376d74a2b9e28743e8ba2f57174e.zip
Diffstat (limited to 'src')
-rw-r--r--src/RendererEntity.cpp62
-rw-r--r--src/RendererEntity.hpp4
-rw-r--r--src/RendererWorld.cpp19
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
+}