From 168c43269ee3582a414e2f403a67d4acca2048ba Mon Sep 17 00:00:00 2001 From: Matias Date: Mon, 14 Jul 2025 20:18:35 +0200 Subject: [PATCH] feat: calculate correct (probably) UVs --- src/main.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 71f25e8..52369fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -97,9 +97,8 @@ class CRenderWobblyWindowPassElement final: public IPassElement { g_pHyprOpenGL->useProgram(g_shader->program); g_shader->setUniformMatrix3fv(SHADER_PROJ, 1, GL_TRUE, glMatrix.getMatrix()); - // g_shader->setUniformFloat4(SHADER_COLOR, 1.f, 255.f, 1.f, 255.f); - g_shader->setUniformInt(SHADER_TEX, 0); + GLCALL(glBindVertexArray(g_VAO)); GLCALL(glBindBuffer(GL_ARRAY_BUFFER, g_VBO)); @@ -108,22 +107,24 @@ class CRenderWobblyWindowPassElement final: public IPassElement { Vector2D {windowBox.x + windowBox.width, windowBox.y + windowBox.height} / pWindowFB->m_size; - std::array UVs; + const unsigned int vertsPerRow = g_SUBDIVS + 1; + std::vector UVs; + UVs.reserve(vertsPerRow * vertsPerRow * 2); - const auto step = (UVBottomRight - UVTopLeft) / (g_SUBDIVS - 1); + const auto step = (UVBottomRight - UVTopLeft) / (g_SUBDIVS); - std::generate(UVs.begin(), UVs.end(), [UVTopLeft, step, index = 0]() mutable { - int x = index % g_SUBDIVS; - int y = index / g_SUBDIVS; - - const float u = UVTopLeft.x + x * step.x; + for (unsigned int y = 0; y < vertsPerRow; ++y) { const float v = UVTopLeft.y + y * step.y; - index++; - return (index % 2 == 0) ? v : u; - }); + for (unsigned int x = 0; x < vertsPerRow; ++x) { + const float u = UVTopLeft.x + x * step.x; - glBindBuffer(GL_ARRAY_BUFFER, g_VBO_UVs); - glBufferSubData(GL_ARRAY_BUFFER, 0, UVs.size(), UVs.data()); + UVs.push_back(u); + UVs.push_back(v); + } + } + + GLCALL(glBindBuffer(GL_ARRAY_BUFFER, g_VBO_UVs)); + GLCALL(glBufferSubData(GL_ARRAY_BUFFER, 0, UVs.size() * sizeof(float), UVs.data())); GLCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_EBO)); GLCALL(glDrawElements(GL_TRIANGLE_STRIP, g_indexCount, GL_UNSIGNED_INT, 0));