From 6b9528c2ae3097a254aa3c889aa076b16528f227 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 26 Jun 2023 09:59:08 +0200 Subject: [PATCH] add face culling --- src/render/Renderer.cpp | 2 ++ src/render/loader/WorldLoader.cpp | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index de7712b..b46505b 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -50,8 +50,10 @@ bool Renderer::Init() { glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LESS); + glFrontFace(GL_CW); InitShaders(); return true; } diff --git a/src/render/loader/WorldLoader.cpp b/src/render/loader/WorldLoader.cpp index 55cf311..153ce74 100644 --- a/src/render/loader/WorldLoader.cpp +++ b/src/render/loader/WorldLoader.cpp @@ -71,12 +71,12 @@ GL::VertexArray LoadWorldModel(const td::game::World* world) { continue; positions.insert(positions.end(), { - static_cast(chunkX + tileX), 0, static_cast(chunkY + tileY), - static_cast(chunkX + tileX + 1), 0, static_cast(chunkY + tileY), - static_cast(chunkX + tileX), 0, static_cast(chunkY + tileY + 1), + static_cast(chunkX + tileX), 0, static_cast(chunkY + tileY), + static_cast(chunkX + tileX + 1), 0, static_cast(chunkY + tileY), + static_cast(chunkX + tileX), 0, static_cast(chunkY + tileY + 1), - static_cast(chunkX + tileX + 1), 0, static_cast(chunkY + tileY), - static_cast(chunkX + tileX), 0, static_cast(chunkY + tileY + 1), + static_cast(chunkX + tileX), 0, static_cast(chunkY + tileY + 1), + static_cast(chunkX + tileX + 1), 0, static_cast(chunkY + tileY), static_cast(chunkX + tileX + 1), 0, static_cast(chunkY + tileY + 1) }); @@ -103,8 +103,8 @@ GL::VertexArray LoadWorldModel(const td::game::World* world) { float fromY = spawn.GetTopLeft().GetY(), toY = spawn.GetBottomRight().GetY(); positions.insert(positions.end(), { - fromX, 0, fromY, fromX, 0, toY, + fromX, 0, fromY, toX, 0, fromY, toX, 0, toY, @@ -131,8 +131,8 @@ GL::VertexArray LoadWorldModel(const td::game::World* world) { float fromY = castle.GetTopLeft().GetY(), toY = castle.GetBottomRight().GetY(); positions.insert(positions.end(), { - fromX, 0, fromY, fromX, 0, toY, + fromX, 0, fromY, toX, 0, fromY, toX, 0, toY, @@ -168,13 +168,13 @@ GL::VertexArray LoadWorldModel(const td::game::World* world) { GL::VertexArray LoadTileSelectModel() { std::vector positions = { - 0, 0, 0, - 1, 0, 0, - 0, 0, 1, + 0, .01, 0, + 1, .01, 0, + 0, .01, 1, - 1, 0, 0, - 0, 0, 1, - 1, 0, 1 + 0, .01, 1, + 1, .01, 0, + 1, .01, 1 }; int color = 255 << 24 | 255 << 16 | 255 << 8 | 150;