mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 03:52:48 -05:00
Initial Commit
Basic window with OpenGL, glad, GLFW, ImGui, and Eigen. Dependencies are populated with FetchContent, not submodules.
This commit is contained in:
48
.gitignore
vendored
Normal file
48
.gitignore
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
# C/C++
|
||||
*.d
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
*.gch
|
||||
*.pch
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
*.mod
|
||||
*.smod
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
# CMake
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
# JetBrains
|
||||
.idea/
|
||||
cmake-build-*/
|
||||
*.iws
|
||||
out/
|
||||
.idea_modules/
|
||||
atlassian-ide-plugin.xml
|
||||
.idea/replstate.xml
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
.idea/httpRequests
|
||||
.idea/caches/build_file_checksums.ser
|
||||
14
CMakeLists.txt
Normal file
14
CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(toddcox-visualize)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
include(External/glfw.cmake)
|
||||
include(External/imgui.cmake)
|
||||
include(External/eigen.cmake)
|
||||
include(External/glad.cmake)
|
||||
|
||||
add_executable(vis main.cpp)
|
||||
target_link_libraries(vis glfw glad imgui eigen)
|
||||
9
External/eigen.cmake
vendored
Normal file
9
External/eigen.cmake
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
FetchContent_Declare(
|
||||
eigen
|
||||
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
|
||||
GIT_TAG 3.4
|
||||
)
|
||||
set(EIGEN_BUILD_DOC OFF CACHE INTERNAL "")
|
||||
set(BUILD_TESTING OFF CACHE INTERNAL "")
|
||||
set(EIGEN_BUILD_PKGCONFIG OFF CACHE INTERNAL "")
|
||||
FetchContent_MakeAvailable(eigen)
|
||||
9
External/glad.cmake
vendored
Normal file
9
External/glad.cmake
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
FetchContent_Declare(
|
||||
glad
|
||||
GIT_REPOSITORY https://github.com/Dav1dde/glad.git
|
||||
GIT_TAG v0.1.36
|
||||
)
|
||||
set(GLAD_PROFILE "core" CACHE INTERNAL "OpenGL profile")
|
||||
set(GLAD_API "gl=4.6" CACHE INTERNAL "API type/version pairs, like \"gl=3.2,gles=\", no version means latest")
|
||||
set(GLAD_GENERATOR "c" CACHE INTERNAL "Language to generate the binding for")
|
||||
FetchContent_MakeAvailable(glad)
|
||||
10
External/glfw.cmake
vendored
Normal file
10
External/glfw.cmake
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
FetchContent_Declare(
|
||||
glfw
|
||||
GIT_REPOSITORY https://github.com/glfw/glfw.git
|
||||
GIT_TAG 3.3.6
|
||||
)
|
||||
set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "")
|
||||
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "")
|
||||
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "")
|
||||
set(GLFW_INSTALL OFF CACHE INTERNAL "")
|
||||
FetchContent_MakeAvailable(glfw)
|
||||
22
External/imgui.cmake
vendored
Normal file
22
External/imgui.cmake
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
FetchContent_Declare(
|
||||
imgui
|
||||
GIT_REPOSITORY https://github.com/ocornut/imgui
|
||||
GIT_TAG v1.86
|
||||
)
|
||||
FetchContent_MakeAvailable(imgui)
|
||||
|
||||
add_library(
|
||||
imgui
|
||||
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
|
||||
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.h
|
||||
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
|
||||
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.h
|
||||
${imgui_SOURCE_DIR}/imgui.cpp
|
||||
${imgui_SOURCE_DIR}/imgui.h
|
||||
${imgui_SOURCE_DIR}/imgui_demo.cpp
|
||||
${imgui_SOURCE_DIR}/imgui_draw.cpp
|
||||
${imgui_SOURCE_DIR}/imgui_tables.cpp
|
||||
${imgui_SOURCE_DIR}/imgui_widgets.cpp
|
||||
)
|
||||
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})
|
||||
target_link_libraries(imgui PRIVATE glfw)
|
||||
123
main.cpp
Normal file
123
main.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <imgui.h>
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <iostream>
|
||||
|
||||
void show_overlay() {
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_None
|
||||
| ImGuiWindowFlags_NoDecoration
|
||||
| ImGuiWindowFlags_AlwaysAutoResize
|
||||
| ImGuiWindowFlags_NoSavedSettings
|
||||
| ImGuiWindowFlags_NoFocusOnAppearing
|
||||
| ImGuiWindowFlags_NoNav
|
||||
| ImGuiWindowFlags_NoMove;
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
const auto PAD = style.DisplaySafeAreaPadding;
|
||||
const auto *viewport = ImGui::GetMainViewport();
|
||||
const auto work_pos = viewport->WorkPos;
|
||||
const auto work_size = viewport->WorkSize;
|
||||
const auto window_pos = ImVec2(
|
||||
work_pos.x + PAD.x,
|
||||
work_pos.y + PAD.y
|
||||
);
|
||||
const auto window_pos_pivot = ImVec2(
|
||||
0.0f,
|
||||
0.0f
|
||||
);
|
||||
ImGui::SetNextWindowPos(
|
||||
window_pos,
|
||||
ImGuiCond_Always,
|
||||
window_pos_pivot
|
||||
);
|
||||
ImGui::SetNextWindowBgAlpha(0.35f * style.Alpha);
|
||||
if (ImGui::Begin("Graphics Information", nullptr, window_flags)) {
|
||||
ImGui::BeginTable("graphics", 2, ImGuiTableFlags_BordersInnerV);
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("GL Vendor");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", glGetString(GL_VENDOR));
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("GL Renderer");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", glGetString(GL_RENDERER));
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("GL Version");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", glGetString(GL_VERSION));
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("GLSL Version");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
ImGui::EndTable();
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (!glfwInit()) {
|
||||
std::cerr << "GLFW :: failed initialization" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
const char *glsl_version = "#version 130";
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
auto *window = glfwCreateWindow(1280, 720, "Hello OpenGL", nullptr, nullptr);
|
||||
if (!window) {
|
||||
std::cerr << "GLFW :: failed to create window" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init(glsl_version);
|
||||
|
||||
io.Fonts->AddFontDefault();
|
||||
|
||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
show_overlay();
|
||||
ImGui::Render();
|
||||
|
||||
int display_w, display_h;
|
||||
glfwGetFramebufferSize(window, &display_w, &display_h);
|
||||
glViewport(0, 0, display_w, display_h);
|
||||
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w,
|
||||
clear_color.w);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
Reference in New Issue
Block a user