aboutsummaryrefslogtreecommitdiffstats
path: root/src/render.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/render.cpp')
-rw-r--r--src/render.cpp71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/render.cpp b/src/render.cpp
index 0f0b138..0c60eed 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -69,6 +69,20 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
glEnable(GL_CULL_FACE);
glEnable(GL_POLYGON_OFFSET_FILL);
+ /************
+ * CAMERA *
+ ************/
+ try {
+ if (player.has_component<Position>()) {
+ Position *pos = player.component<Position>().get();
+ camPos.y = pos->y;
+ camPos.x = pos->x;
+ }
+ } catch (...) { // If the player doesn't exist or anything goes wrong
+ camPos.y = 0.0f;
+ camPos.x = 0.0f;
+ }
+
glm::mat4 view = glm::lookAt(camPos, // Pos
camPos + rot, // Facing
@@ -101,7 +115,6 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
glUseProgram(s);
-
glUniformMatrix4fv(v, 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(p, 1, GL_FALSE, glm::value_ptr(projection));
glUniformMatrix4fv(m, 1, GL_FALSE, glm::value_ptr(model));
@@ -114,20 +127,6 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
GLfloat amb[4] = {1.0f, 1.0f, 1.0f, 0.0f};
glUniform4fv(b, 1, amb);
- /************
- * CAMERA *
- ************/
- try {
- if (player.has_component<Position>()) {
- Position *pos = player.component<Position>().get();
- camPos.y = pos->y;
- camPos.x = pos->x;
- }
- } catch (...) { // If the player doesn't exist or anything goes wrong
- camPos.y = 0.0f;
- camPos.x = 0.0f;
- }
-
/**************
* LIGHTING *
**************/
@@ -167,19 +166,18 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
//if (e.has_component<Scripted>()) {
// e.component<Scripted>()->updateRender();
//}
-
- float w = 0.5f;
- float h = (float)rend.texture.height/rend.texture.width;
+
+ auto& c = rend.corners;
GLuint tri_vbo;
GLfloat tri_data[] = {
- (float)p.x-w, (float)p.y , 0.0f, 0.0f, 1.0f, 1.0f,
- (float)p.x+w, (float)p.y , 0.0f, 1.0f, 1.0f, 1.0f,
- (float)p.x-w, (float)p.y+h, 0.0f, 0.0f, 0.0f, 1.0f,
-
- (float)p.x+w, (float)p.y , 0.0f, 1.0f, 1.0f, 1.0f,
- (float)p.x+w, (float)p.y+h, 0.0f, 1.0f, 0.0f, 1.0f,
- (float)p.x-w, (float)p.y+h, 0.0f, 0.0f, 0.0f, 1.0f,
+ p.x+c[0].x, p.y+c[0].y, 0.0f, 0.0f, 1.0f, 1.0f,
+ p.x+c[1].x, p.y+c[1].y, 0.0f, 1.0f, 1.0f, 1.0f,
+ p.x+c[2].x, p.y+c[2].y, 0.0f, 0.0f, 0.0f, 1.0f,
+
+ p.x+c[1].x, p.y+c[1].y, 0.0f, 1.0f, 1.0f, 1.0f,
+ p.x+c[3].x, p.y+c[3].y, 0.0f, 1.0f, 0.0f, 1.0f,
+ p.x+c[2].x, p.y+c[2].y, 0.0f, 0.0f, 0.0f, 1.0f,
};
bool flipped = false;
@@ -219,24 +217,25 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
});
glUniform1i(f, 0);
- // If we were given a world VBO render it
- if (worldVBO) {
+ for (auto& w : worldRenders) {
+ auto& layer = w.second;
+
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, worldTexture);
+ glBindTexture(GL_TEXTURE_2D, layer.tex);
glUniform1i(q, 0);
glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, worldNormal);
+ glBindTexture(GL_TEXTURE_2D, layer.normal);
glUniform1i(n, 1);
- glBindBuffer(GL_ARRAY_BUFFER, worldVBO);
+ glBindBuffer(GL_ARRAY_BUFFER, w.first);
glVertexAttribPointer(a, 3, GL_FLOAT, GL_FALSE,
6*sizeof(float), 0);
glVertexAttribPointer(t, 2, GL_FLOAT, GL_FALSE,
6*sizeof(float), (void*)(3*sizeof(float)));
glVertexAttribPointer(r, 1, GL_FLOAT, GL_FALSE,
6*sizeof(float), (void*)(5*sizeof(float)));
- glDrawArrays(GL_TRIANGLES, 0, worldVertex);
+ glDrawArrays(GL_TRIANGLES, 0, layer.vertex);
}
glDisableVertexAttribArray(a);
@@ -407,10 +406,12 @@ void RenderSystem::receive(const NewRenderEvent &nre)
void RenderSystem::receive(const WorldMeshUpdateEvent &wmu)
{
- worldVBO = wmu.worldVBO;
- worldVertex = wmu.numVertex;
- worldTexture = wmu.worldTexture;
- worldNormal = wmu.worldNormal;
+ worldRenders.insert_or_assign(
+ wmu.worldVBO,
+ WorldRenderData(wmu.worldTexture,
+ wmu.worldNormal,
+ wmu.numVertex)
+ );
}
void RenderSystem::receive(const entityx::ComponentAddedEvent<Player> &cae)