소스 검색

Base framework.

jcsyshc 2 년 전
커밋
f931d9f93e
3개의 변경된 파일114개의 추가작업 그리고 0개의 파일을 삭제
  1. 37 0
      CMakeLists.txt
  2. 7 0
      src/config.h
  3. 70 0
      src/main.cpp

+ 37 - 0
CMakeLists.txt

@@ -0,0 +1,37 @@
+cmake_minimum_required(VERSION 3.25)
+project(RemoteAR2)
+
+set(CMAKE_CXX_STANDARD 20)
+
+add_executable(RemoteAR2 src/main.cpp)
+
+# OpenGL config
+find_package(OpenGL REQUIRED)
+target_include_directories(${PROJECT_NAME} PRIVATE ${OPENGL_INCLUDE_DIR})
+target_link_libraries(${PROJECT_NAME} OpenGL::GL)
+
+# glfw config
+find_package(glfw3 REQUIRED)
+target_link_libraries(${PROJECT_NAME} glfw)
+
+# glad config
+set(GLAD_DIR /home/tpx/src/glad)
+target_include_directories(${PROJECT_NAME} PRIVATE ${GLAD_DIR}/include)
+target_sources(${PROJECT_NAME} PRIVATE ${GLAD_DIR}/src/gl.c)
+
+# imgui config
+set(IMGUI_DIR /home/tpx/src/imgui-1.89.5)
+set(IMGUI_BACKENDS_DIR ${IMGUI_DIR}/backends)
+target_include_directories(${PROJECT_NAME} PRIVATE ${IMGUI_DIR} ${IMGUI_BACKENDS_DIR})
+target_sources(${PROJECT_NAME} PRIVATE
+        ${IMGUI_DIR}/imgui.cpp
+        ${IMGUI_DIR}/imgui_draw.cpp
+        ${IMGUI_DIR}/imgui_tables.cpp
+        ${IMGUI_DIR}/imgui_widgets.cpp
+        ${IMGUI_DIR}/imgui_demo.cpp
+        ${IMGUI_BACKENDS_DIR}/imgui_impl_glfw.cpp
+        ${IMGUI_BACKENDS_DIR}/imgui_impl_opengl3.cpp)
+
+# spdlog config
+find_package(spdlog REQUIRED)
+target_link_libraries(${PROJECT_NAME} spdlog::spdlog)

+ 7 - 0
src/config.h

@@ -0,0 +1,7 @@
+#ifndef REMOTEAR2_CONFIG_H
+#define REMOTEAR2_CONFIG_H
+
+static constexpr auto main_window_width = 800;
+static constexpr auto main_window_height = 600;
+
+#endif //REMOTEAR2_CONFIG_H

+ 70 - 0
src/main.cpp

@@ -0,0 +1,70 @@
+#include "config.h"
+
+#include <imgui.h>
+#include <imgui_impl_glfw.h>
+#include <imgui_impl_opengl3.h>
+
+#include <glad/gl.h>
+#include <GLFW/glfw3.h>
+
+#include <spdlog/spdlog.h>
+
+#include <cassert>
+
+int main() {
+
+    // setup glfw and main window
+    auto ret = glfwInit();
+    assert(ret == GLFW_TRUE);
+    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
+    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
+    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+    auto main_window = glfwCreateWindow(main_window_width, main_window_height, "RemoteAR", nullptr, nullptr);
+    assert(main_window != nullptr);
+    glfwMakeContextCurrent(main_window);
+    glfwSwapInterval(1);
+
+    // load opengl functions
+    auto version = gladLoadGL(glfwGetProcAddress);
+    assert(version > 0);
+    SPDLOG_INFO("Loaded OpenGL {}.{}", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
+
+    // setup imgui context
+    IMGUI_CHECKVERSION();
+    ImGui::CreateContext();
+    auto io = ImGui::GetIO();
+    io.ConfigFlags != ImGuiConfigFlags_NavEnableKeyboard;
+    ImGui::StyleColorsDark();
+    ImGui_ImplGlfw_InitForOpenGL(main_window, true);
+    ImGui_ImplOpenGL3_Init();
+
+    // main loop
+    while (!glfwWindowShouldClose(main_window)) {
+
+        glfwPollEvents();
+
+        ImGui_ImplOpenGL3_NewFrame();
+        ImGui_ImplGlfw_NewFrame();
+        ImGui::NewFrame();
+
+        ImGui::ShowDemoWindow();
+
+        ImGui::Render();
+        int frame_width, frame_height;
+        glfwGetFramebufferSize(main_window, &frame_width, &frame_height);
+        glViewport(0, 0, frame_width, frame_height);
+        glClear(GL_COLOR_BUFFER_BIT);
+        ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
+        glfwSwapBuffers(main_window);
+    }
+
+    // cleanup
+    ImGui_ImplOpenGL3_Shutdown();
+    ImGui_ImplGlfw_Shutdown();
+    ImGui::DestroyContext();
+
+    glfwDestroyWindow(main_window);
+    glfwTerminate();
+
+    return 0;
+}