From a7b4671517d80bd37d8c592dfb0480d6d3bd2b56 Mon Sep 17 00:00:00 2001 From: EmaMaker Date: Tue, 18 Jul 2023 20:03:59 +0200 Subject: [PATCH] toggle wireframe with F --- include/globals.hpp | 1 + src/main.cpp | 8 ++++++++ src/renderer.cpp | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/globals.hpp b/include/globals.hpp index 8ce0f07..470e729 100644 --- a/include/globals.hpp +++ b/include/globals.hpp @@ -14,6 +14,7 @@ extr Camera theCamera; constexpr int chunks_volume = static_cast(1.333333333333*M_PI*(RENDER_DISTANCE*RENDER_DISTANCE*RENDER_DISTANCE)); +extr bool wireframe; extr uint32_t MORTON_XYZ_ENCODE[CHUNK_SIZE][CHUNK_SIZE][CHUNK_SIZE]; extr uint32_t MORTON_XYZ_DECODE[CHUNK_VOLUME][3]; diff --git a/src/main.cpp b/src/main.cpp index 90afc63..fdb4efa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ int frames = 0; float lastBlockPick=0.0; bool blockpick = false; +bool canChangeWireframe = true; int main() { @@ -62,6 +63,7 @@ int main() std::cout << "Using GPU: " << glGetString(GL_VENDOR) << " " << glGetString(GL_RENDERER) << "\n"; SpaceFilling::initLUT(); + wireframe = false; renderer::init(); std::thread chunkmanager_thread = chunkmanager::init(); @@ -140,6 +142,12 @@ void processInput(GLFWwindow *window) lastBlockPick=glfwGetTime(); } + if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS && canChangeWireframe){ + wireframe = !wireframe; + canChangeWireframe = false; + } + if (glfwGetKey(window, GLFW_KEY_F) == GLFW_RELEASE) canChangeWireframe = true; + // Reset blockpicking if enough time has passed if(glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1) == GLFW_RELEASE && glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_2) == GLFW_RELEASE) blockpick = false; diff --git a/src/renderer.cpp b/src/renderer.cpp index 290bbe3..7fb41a5 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -61,6 +61,9 @@ namespace renderer{ chunkmesher::getMeshDataQueue().push(m); } + if(wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + for(auto& c : chunks_torender){ float dist = glm::distance(c->getPosition(), cameraChunkPos); if(dist <= static_cast(RENDER_DISTANCE)){ @@ -95,7 +98,6 @@ namespace renderer{ { if(c->numTriangles > 0) { - // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // wireframe mode theShader->setMat4("model", model); theShader->setMat4("view", theCamera.getView()); theShader->setMat4("projection", theCamera.getProjection());