mirror of
https://git.allpurposem.at/mat/WiggleWobble.git
synced 2025-12-23 13:01:28 +01:00
feat: calculate correct (probably) UVs
This commit is contained in:
parent
af189dc9b0
commit
168c43269e
29
src/main.cpp
29
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<float, g_SUBDIVS * g_SUBDIVS * 3 * 2> UVs;
|
||||
const unsigned int vertsPerRow = g_SUBDIVS + 1;
|
||||
std::vector<float> 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));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user