From bcecdc9b60455f563b9cd7baa93e7ac45c2ae290 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 16 Nov 2023 21:32:55 +0300 Subject: [PATCH] GLM-related Shader.uniformNf overloads --- src/frontend/world_render.cpp | 12 ++++++++---- src/graphics/Shader.cpp | 9 +++++++++ src/graphics/Shader.h | 2 ++ src/voxels/ChunksController.cpp | 4 +++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/frontend/world_render.cpp b/src/frontend/world_render.cpp index 29ac9fba..3ccd2b42 100644 --- a/src/frontend/world_render.cpp +++ b/src/frontend/world_render.cpp @@ -85,10 +85,10 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float shader->uniformMatrix("u_view", camera->getView()); shader->uniform1f("u_gamma", 1.6f); shader->uniform3f("u_skyLightColor", 1.1f,1.1f,1.1f); - shader->uniform3f("u_fogColor", skyColor.r,skyColor.g,skyColor.b); + shader->uniform3f("u_fogColor", skyColor); shader->uniform1f("u_fogFactor", fogFactor); shader->uniform1f("u_fogCurve", fogCurve); - shader->uniform3f("u_cameraPos", camera->position.x,camera->position.y,camera->position.z); + shader->uniform3f("u_cameraPos", camera->position); Block* cblock = Block::blocks[level->player->choosenBlock]; float multiplier = 0.2f; @@ -146,8 +146,12 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float float length = 40.f; linesShader->use(); - glm::mat4 model(glm::translate(glm::mat4(1.f), vec3(Window::width >> 1, -static_cast(Window::height) >> 1, 0.f))); - linesShader->uniformMatrix("u_projview", glm::ortho(0.f, static_cast(Window::width), -static_cast(Window::height), 0.f, -length, length) * model * glm::inverse(camera->rotation)); + vec3 tsl = vec3(Window::width/2, -((int)Window::height)/2, 0.f); + glm::mat4 model(glm::translate(glm::mat4(1.f), tsl)); + linesShader->uniformMatrix("u_projview", glm::ortho( + 0.f, (float)Window::width, + -(float)Window::height, 0.f, + -length, length) * model * glm::inverse(camera->rotation)); glDisable(GL_DEPTH_TEST); diff --git a/src/graphics/Shader.cpp b/src/graphics/Shader.cpp index fbfc17bd..7d28344d 100644 --- a/src/graphics/Shader.cpp +++ b/src/graphics/Shader.cpp @@ -41,11 +41,20 @@ void Shader::uniform2f(std::string name, float x, float y){ glUniform2f(transformLoc, x, y); } +void Shader::uniform2f(std::string name, glm::vec2 xy){ + GLuint transformLoc = glGetUniformLocation(id, name.c_str()); + glUniform2f(transformLoc, xy.x, xy.y); +} + void Shader::uniform3f(std::string name, float x, float y, float z){ GLuint transformLoc = glGetUniformLocation(id, name.c_str()); glUniform3f(transformLoc, x,y,z); } +void Shader::uniform3f(std::string name, glm::vec3 xyz){ + GLuint transformLoc = glGetUniformLocation(id, name.c_str()); + glUniform3f(transformLoc, xyz.x, xyz.y, xyz.z); +} Shader* load_shader(std::string vertexFile, std::string fragmentFile) { diff --git a/src/graphics/Shader.h b/src/graphics/Shader.h index 9507d348..c91dea5a 100644 --- a/src/graphics/Shader.h +++ b/src/graphics/Shader.h @@ -16,7 +16,9 @@ public: void uniform1i(std::string name, int x); void uniform1f(std::string name, float x); void uniform2f(std::string name, float x, float y); + void uniform2f(std::string name, glm::vec2 xy); void uniform3f(std::string name, float x, float y, float z); + void uniform3f(std::string name, glm::vec3 xyz); }; extern Shader* load_shader(std::string vertexFile, std::string fragmentFile); diff --git a/src/voxels/ChunksController.cpp b/src/voxels/ChunksController.cpp index deb7de7f..78ec6f16 100644 --- a/src/voxels/ChunksController.cpp +++ b/src/voxels/ChunksController.cpp @@ -108,7 +108,9 @@ bool ChunksController::loadVisible(){ for (size_t i = 0; i < CHUNK_VOL; i++) { blockid_t id = chunk->voxels[i].id; if (Block::blocks[id] == nullptr) { - std::cout << "corruped block detected at " << i << " of chunk " << chunk->x << "x" << chunk->z << " -> " << (int)id << std::endl; + std::cout << "corruped block detected at " << i << " of chunk "; + std::cout << chunk->x << "x" << chunk->z; + std::cout << " -> " << (int)id << std::endl; chunk->voxels[i].id = 11; } }