From 2140653c001a2ac415fb717d48ca2b55ff2aa037 Mon Sep 17 00:00:00 2001 From: Levent Kaya Date: Thu, 6 Nov 2025 01:53:21 +0300 Subject: [feature] basic demo screen --- src/CMakeLists.txt | 75 +++++++++++++++++++++++++++++++++-- src/main.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 184 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 34791b0..9875cd7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,72 @@ -add_library(libboltdbg INTERFACE) -target_include_directories(libboltdbg INTERFACE ${CMAKE_SOURCE_DIR}/include) +# src/CMakeLists.txt +cmake_minimum_required(VERSION 3.15) # local guard if included standalone -add_executable(boltdbg main.cpp) -target_link_libraries(boltdbg PRIVATE libboltdbg) +# Collect core sources (placeholder + real sources later) +set(BOLTDBG_CORE_SOURCES + dummy.cpp # placeholder; replace/add real core sources here + # src/core/debugger.cpp + # src/core/process.cpp +) + +# Application executable +add_executable(boltdbg + main.cpp + ${BOLTDBG_CORE_SOURCES} +) + +# Public include dirs (so main and core can include project headers) +target_include_directories(boltdbg PRIVATE ${CMAKE_SOURCE_DIR}/include) + +# Ensure imgui include dirs available for includes like "imgui.h" and "backends/..." +target_include_directories(boltdbg PRIVATE + ${CMAKE_SOURCE_DIR}/external/imgui + ${CMAKE_SOURCE_DIR}/external/imgui/backends +) + +# Link imgui (various targets depending on provider) +if (TARGET imgui) + target_link_libraries(boltdbg PRIVATE imgui) +elseif (TARGET imgui::imgui) + target_link_libraries(boltdbg PRIVATE imgui::imgui) +endif() + +# GLFW linking: prefer config target then vendor +if (TARGET GLFW::GLFW) + target_link_libraries(boltdbg PRIVATE GLFW::GLFW) +elseif (TARGET glfw) + target_link_libraries(boltdbg PRIVATE glfw) +endif() + +# glad (loader) +if (TARGET glad::glad) + target_link_libraries(boltdbg PRIVATE glad::glad) +elseif (TARGET glad) + target_link_libraries(boltdbg PRIVATE glad) +endif() + +# spdlog +if (TARGET spdlog::spdlog) + target_link_libraries(boltdbg PRIVATE spdlog::spdlog) +elseif (TARGET spdlog) + target_link_libraries(boltdbg PRIVATE spdlog) +endif() + +# Platform OpenGL libs +if (APPLE) + find_library(COCOA_FRAMEWORK Cocoa REQUIRED) + find_library(IOKIT_FRAMEWORK IOKit REQUIRED) + find_library(COREVIDEO_FRAMEWORK CoreVideo REQUIRED) + find_library(OPENGL_FRAMEWORK OpenGL REQUIRED) + target_link_libraries(boltdbg PRIVATE ${COCOA_FRAMEWORK} ${IOKIT_FRAMEWORK} ${COREVIDEO_FRAMEWORK} ${OPENGL_FRAMEWORK}) +elseif (WIN32) + target_link_libraries(boltdbg PRIVATE opengl32) +else() + find_package(OpenGL REQUIRED) + target_link_libraries(boltdbg PRIVATE OpenGL::GL dl pthread) +endif() + +# Optional: apply project warning settings if you created compiler_warnings.cmake +if (EXISTS "${CMAKE_SOURCE_DIR}/cmake/compiler_warnings.cmake") + include(${CMAKE_SOURCE_DIR}/cmake/compiler_warnings.cmake) + set_project_warnings(boltdbg) +endif() diff --git a/src/main.cpp b/src/main.cpp index 7bd7cfb..0a23004 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,118 @@ +// src/main.cpp #include +// spdlog +#include + +// Prevent GLFW from including OpenGL headers (so glad can provide them) +#define GLFW_INCLUDE_NONE +#include + +// GL loader (glad) - include after GLFW_INCLUDE_NONE so glad can provide GL headers +#if __has_include("glad/glad.h") +#include +#define HAVE_GLAD 1 +#else +#define HAVE_GLAD 0 +#endif + +// Now include ImGui and its backends (they expect glfw + GL loader to be present) +#include "imgui.h" +#include "backends/imgui_impl_glfw.h" +#include "backends/imgui_impl_opengl3.h" + int main(int argc, char** argv) { - std::cout << "BoltDBG (bootstrap) v0.1.0\n"; + // init logger + try { + spdlog::set_level(spdlog::level::info); + spdlog::info("BoltDBG demo starting (spdlog initialized)."); + } catch (const std::exception &e) { + std::cerr << "spdlog init failed: " << e.what() << std::endl; + } + + if (!glfwInit()) { + spdlog::error("Failed to initialize GLFW"); + return 1; + } + + // GL settings (3.3 core as example) + const char* glsl_version = "#version 330"; + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); +#if __APPLE__ + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); +#endif + + GLFWwindow* window = glfwCreateWindow(1280, 720, "BoltDBG - ImGui + spdlog demo", NULL, NULL); + if (!window) { + spdlog::error("Failed to create GLFW window"); + glfwTerminate(); + return 1; + } + glfwMakeContextCurrent(window); + glfwSwapInterval(1); + +#if HAVE_GLAD + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { + spdlog::error("Failed to initialize GLAD"); + return 1; + } +#else + spdlog::warn("GLAD not detected at compile-time. If you experience GL symbol errors, add glad."); +#endif + + // ImGui init + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO &io = ImGui::GetIO(); (void)io; + ImGui::StyleColorsDark(); + + ImGui_ImplGlfw_InitForOpenGL(window, true); + ImGui_ImplOpenGL3_Init(glsl_version); + + spdlog::info("Entering main loop."); + + bool show_demo = false; + int click_count = 0; + + while (!glfwWindowShouldClose(window)) { + glfwPollEvents(); + + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + + ImGui::Begin("BoltDBG - Demo"); + ImGui::Text("Hello from BoltDBG demo!"); + if (ImGui::Button("Log info with spdlog")) { + click_count++; + spdlog::info("Button clicked {} times", click_count); + } + ImGui::Text("Click count: %d", click_count); + ImGui::End(); + + if (show_demo) ImGui::ShowDemoWindow(&show_demo); + + ImGui::Render(); + int display_w, display_h; + glfwGetFramebufferSize(window, &display_w, &display_h); + glViewport(0, 0, display_w, display_h); + glClearColor(0.1f, 0.12f, 0.14f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + + glfwSwapBuffers(window); + } + + // cleanup + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + + glfwDestroyWindow(window); + glfwTerminate(); + + spdlog::info("BoltDBG demo exiting."); return 0; } -- cgit v1.2.3