This commit is contained in:
2026-03-02 17:21:14 +08:00
parent db0fd98e4f
commit c59c921997
4 changed files with 106 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
#include "camera.h"
#include <GLFW/glfw3.h>
#include <algorithm>
#include <cstddef>
#include <functional>
#include <glm/ext/matrix_clip_space.hpp>
#include <glm/ext/matrix_transform.hpp>
@@ -249,7 +250,55 @@ private:
const int vertex_count = cols * rows;
std::vector<float> verts;
for (int i = 0; i < rows; ++i) {
const float v = (rows > 1) ? (float)(i) / (float)(rows - 1) : 0.0F; // normailze to 0-1
const float y = (v - 0.5F) * panelHeight_; // -0.5 - 0.5
for (int j = 0; j < cols; ++j) {
const float u = (cols > 1) ? (float)(j) / (float)(cols - 1) : 0.0F;
const float x = (u - 0.5F) * panelWidth_;
verts.push_back(x);
verts.push_back(y);
verts.push_back(0.0F);
verts.push_back(u);
verts.push_back(v);
}
}
std::vector<unsigned int> idx;
idx.reserve((cols - 1) * (rows - 1) * 6);
for (int r = 0; r < rows - 1; ++r) {
for (int c = 0; c < cols - 1; ++c) {
auto i0 = r * cols + c;
auto i1 = r * cols + c + 1;
auto i2 = (r + 1) * cols + c + 1;
auto i3 = (r + 1) * cols + c;
idx.push_back(i0);
idx.push_back(i1);
idx.push_back(i2);
idx.push_back(i0);
idx.push_back(i2);
idx.push_back(i3);
}
}
heatmapIndexCount = int(idx.size());
glGenVertexArrays(1, &heatmapVao_);
glBindVertexArray(heatmapVao_);
glGenBuffers(1, &heatmapVbo_);
glBindBuffer(GL_ARRAY_BUFFER, heatmapVbo_);
glBufferData(GL_ARRAY_BUFFER, verts.size() * sizeof(float), verts.data(), GL_STATIC_DRAW);
glGenBuffers(1, &heatmapIbo_);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, heatmapIbo_);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx.size() * sizeof(unsigned int), idx.data(), GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(0));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glBindVertexArray(0);
}
bool initBgProgram() {
@@ -509,6 +558,7 @@ private:
unsigned int heatmapVao_ = 0;
unsigned int heatmapVbo_ = 0;
unsigned int heatmapIbo_ = 0;
int heatmapIndexCount = 0;
ViewPort viewport_{800, 600};
Camera camera_{glm::vec3(0.0F, 0.0F, 2.0F)};