diff options
Diffstat (limited to 'src/render.cpp')
-rw-r--r-- | src/render.cpp | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/render.cpp b/src/render.cpp index 0f0b138..9362134 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -167,19 +167,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 +218,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 +407,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) |