This commit is contained in:
2026-02-28 02:42:23 +08:00
parent edb25a75c3
commit 8a4058e7d1
14 changed files with 2360 additions and 2309 deletions

3
.clangd Normal file
View File

@@ -0,0 +1,3 @@
CompileFlags:
Add:
--target=x86_64-w64-mingw32

View File

@@ -1,9 +1,12 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.10)
project(3dviewer)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include_directories(.)
set(CMAKE_CXX_STANDARD 23)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include_directories(.)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
@@ -15,6 +18,15 @@ add_executable(
camera.h
)
if(WIN32)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
glfw3
)
elseif(APPLE)
elseif(UNIX)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
@@ -29,3 +41,6 @@ target_link_libraries(
dl
m
)
endif()

View File

@@ -8,8 +8,10 @@
#include <glm/trigonometric.hpp>
#include <iostream>
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include <print>
class GLWidget {
@@ -47,6 +49,12 @@ public:
if (bgVbo_) {
glDeleteBuffers(1, &bgVbo_);
}
if (heatmapVao_) {
glDeleteVertexArrays(1, &heatmapVao_);
}
if (heatmapVbo_) {
glDeleteBuffers(1, &heatmapVbo_);
}
deinit_ = true;
}
@@ -58,7 +66,7 @@ public:
bool initGeometry() {
if (!glfwInit()) {
std::cout << "Failed to initialize GLFW" << std::endl;
std::cout << "Failed to initialize GLFW\n";
return false;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
@@ -69,13 +77,13 @@ public:
#endif
window_.reset(glfwCreateWindow(viewport_.width, viewport_.height, "3dviewer", nullptr, nullptr));
if (!window_) {
std::cout << "Failed to create GLFW window" << std::endl;
std::cout << "Failed to create GLFW window\n";
glfwTerminate();
return false;
}
glfwMakeContextCurrent(window_.get());
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
std::cout << "Failed to initialize GLAD\n";
return false;
}
@@ -282,7 +290,32 @@ private:
bool initHeatmapProgram() {
auto vshader = std::make_unique<LOpenGLShader>(LOpenGLShader::ShaderType::Vertex);
auto fshader = std::make_unique<LOpenGLShader>(LOpenGLShader::ShaderType::Fragment);
if (!vshader->compileShaderFromFile(heatmapVertShaderPath_)) {
std::cout << "Vertex shader compile failed: " << heatmapVertShaderPath_ << "\n" << vshader->Log() << std::endl;
return false;
}
if (!fshader->compileShaderFromFile(heatmapFragShaderPath_)) {
std::cout << "Fragment shader compile failed: " << heatmapFragShaderPath_ << "\n" << fshader->Log() << std::endl;
return false;
}
heatmapProg_ = std::make_unique<LOpenGLProgram>();
if (!heatmapProg_->addShader(std::move(vshader))) {
std::cout << "Failed to attach vertex shader\n";
return false;
}
if (!heatmapProg_->addShader(std::move(fshader))) {
std::cout << "Failed to attach vertex shader\n";
return false;
}
bool ret = panelProg_->Link();
if (!ret) {
std::cout << "Failed to link heatmap program\n";
return false;
}
return true;
}
void drawBg() {
@@ -452,7 +485,7 @@ private:
unsigned int heatmapVbo_ = 0;
ViewPort viewport_{800, 600};
Camera camera_{glm::vec3(0.0f, 0.0f, 2.0f)};
Camera camera_{glm::vec3(0.0F, 0.0F, 2.0F)};
bool firstMouse_ = true;
float lastX_;