update
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
project(3dviewer)
|
project(3dviewer)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
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(glfw3 REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
@@ -15,7 +18,16 @@ add_executable(
|
|||||||
camera.h
|
camera.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(
|
if(WIN32)
|
||||||
|
target_link_libraries(
|
||||||
|
${PROJECT_NAME}
|
||||||
|
PRIVATE
|
||||||
|
glfw3
|
||||||
|
)
|
||||||
|
elseif(APPLE)
|
||||||
|
|
||||||
|
elseif(UNIX)
|
||||||
|
target_link_libraries(
|
||||||
${PROJECT_NAME}
|
${PROJECT_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
glfw3
|
glfw3
|
||||||
@@ -28,4 +40,7 @@ target_link_libraries(
|
|||||||
pthread
|
pthread
|
||||||
dl
|
dl
|
||||||
m
|
m
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
41
main.cpp
41
main.cpp
@@ -8,8 +8,10 @@
|
|||||||
#include <glm/trigonometric.hpp>
|
#include <glm/trigonometric.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <print>
|
||||||
|
|
||||||
|
|
||||||
class GLWidget {
|
class GLWidget {
|
||||||
@@ -47,6 +49,12 @@ public:
|
|||||||
if (bgVbo_) {
|
if (bgVbo_) {
|
||||||
glDeleteBuffers(1, &bgVbo_);
|
glDeleteBuffers(1, &bgVbo_);
|
||||||
}
|
}
|
||||||
|
if (heatmapVao_) {
|
||||||
|
glDeleteVertexArrays(1, &heatmapVao_);
|
||||||
|
}
|
||||||
|
if (heatmapVbo_) {
|
||||||
|
glDeleteBuffers(1, &heatmapVbo_);
|
||||||
|
}
|
||||||
deinit_ = true;
|
deinit_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +66,7 @@ public:
|
|||||||
|
|
||||||
bool initGeometry() {
|
bool initGeometry() {
|
||||||
if (!glfwInit()) {
|
if (!glfwInit()) {
|
||||||
std::cout << "Failed to initialize GLFW" << std::endl;
|
std::cout << "Failed to initialize GLFW\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
@@ -69,13 +77,13 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
window_.reset(glfwCreateWindow(viewport_.width, viewport_.height, "3dviewer", nullptr, nullptr));
|
window_.reset(glfwCreateWindow(viewport_.width, viewport_.height, "3dviewer", nullptr, nullptr));
|
||||||
if (!window_) {
|
if (!window_) {
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window\n";
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
glfwMakeContextCurrent(window_.get());
|
glfwMakeContextCurrent(window_.get());
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
std::cout << "Failed to initialize GLAD" << std::endl;
|
std::cout << "Failed to initialize GLAD\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +290,32 @@ private:
|
|||||||
bool initHeatmapProgram() {
|
bool initHeatmapProgram() {
|
||||||
auto vshader = std::make_unique<LOpenGLShader>(LOpenGLShader::ShaderType::Vertex);
|
auto vshader = std::make_unique<LOpenGLShader>(LOpenGLShader::ShaderType::Vertex);
|
||||||
auto fshader = std::make_unique<LOpenGLShader>(LOpenGLShader::ShaderType::Fragment);
|
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() {
|
void drawBg() {
|
||||||
@@ -452,7 +485,7 @@ private:
|
|||||||
unsigned int heatmapVbo_ = 0;
|
unsigned int heatmapVbo_ = 0;
|
||||||
|
|
||||||
ViewPort viewport_{800, 600};
|
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;
|
bool firstMouse_ = true;
|
||||||
float lastX_;
|
float lastX_;
|
||||||
|
|||||||
Reference in New Issue
Block a user