a window
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
build/
|
||||||
|
out/
|
||||||
|
.vs/
|
||||||
|
*~
|
||||||
+16
-1
@@ -16,6 +16,11 @@ include(cmake/libCZI.cmake)
|
|||||||
find_package(OpenCV REQUIRED)
|
find_package(OpenCV REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
|
message(STATUS "IMGUI:\t" ${imgui_DIR})
|
||||||
|
message(STATUS "GLFW:\t" ${glfw_DIR})
|
||||||
|
message(STATUS "PFD:\t\t" ${pfd_DIR})
|
||||||
|
message(STATUS "SPDLOG:\t" ${spdlog_DIR})
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
set(CMAKE_CXX_FLAGS "/std:c++20 /Zi /EHsc")
|
set(CMAKE_CXX_FLAGS "/std:c++20 /Zi /EHsc")
|
||||||
endif()
|
endif()
|
||||||
@@ -33,7 +38,16 @@ add_subdirectory(${pfd_DIR})
|
|||||||
add_subdirectory(${spdlog_DIR})
|
add_subdirectory(${spdlog_DIR})
|
||||||
add_subdirectory(${glfw_DIR})
|
add_subdirectory(${glfw_DIR})
|
||||||
|
|
||||||
set(SRC src/main.cpp)
|
set(SRC
|
||||||
|
src/AppGLFW.cpp
|
||||||
|
src/main.cpp
|
||||||
|
${imgui_DIR}/imgui.cpp
|
||||||
|
${imgui_DIR}/imgui_demo.cpp
|
||||||
|
${imgui_DIR}/imgui_draw.cpp
|
||||||
|
${imgui_DIR}/imgui_tables.cpp
|
||||||
|
${imgui_DIR}/imgui_widgets.cpp
|
||||||
|
${imgui_DIR}/backends/imgui_impl_opengl3.cpp
|
||||||
|
${imgui_DIR}/backends/imgui_impl_glfw.cpp)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${SRC})
|
add_executable(${PROJECT_NAME} ${SRC})
|
||||||
|
|
||||||
@@ -41,6 +55,7 @@ target_link_libraries(${PROJECT_NAME}
|
|||||||
LINK_PUBLIC ${OpenCV_LIBS})
|
LINK_PUBLIC ${OpenCV_LIBS})
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
PUBLIC ${PROJECT_SOURCE_DIR}/src
|
||||||
PUBLIC ${OpenCV_INCLUDE_DIRS}
|
PUBLIC ${OpenCV_INCLUDE_DIRS}
|
||||||
PUBLIC ${imgui_DIR}
|
PUBLIC ${imgui_DIR}
|
||||||
PUBLIC ${imgui_DIR}/backends
|
PUBLIC ${imgui_DIR}/backends
|
||||||
|
|||||||
+138
@@ -0,0 +1,138 @@
|
|||||||
|
#include "AppGLFW.hpp"
|
||||||
|
|
||||||
|
#include "portable-file-dialogs.h"
|
||||||
|
|
||||||
|
ui::AppGLFW::AppGLFW()
|
||||||
|
{
|
||||||
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
|
if (!glfwInit())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decide GL+GLSL versions
|
||||||
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||||
|
// GL ES 2.0 + GLSL 100
|
||||||
|
const char* glsl_version = "#version 100";
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||||
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
// GL 3.2 + GLSL 150
|
||||||
|
const char* glsl_version = "#version 150";
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||||
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
|
||||||
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
|
||||||
|
#else
|
||||||
|
// GL 3.0 + GLSL 130
|
||||||
|
#ifdef __linux__
|
||||||
|
const char* glsl_version = "#version 130";
|
||||||
|
#else
|
||||||
|
const char* glsl_version = reinterpret_cast<const char*>("#version 130");
|
||||||
|
#endif
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||||
|
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+
|
||||||
|
// only glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// int count;
|
||||||
|
// GLFWmonitor** monitors = glfwGetMonitors(&count); // at [0] is always the
|
||||||
|
// main monitor GLFWmonitor* monitor = monitors[1];
|
||||||
|
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||||
|
int xpos, ypos, width, height;
|
||||||
|
glfwGetMonitorWorkarea(monitor, &xpos, &ypos, &width, &height);
|
||||||
|
|
||||||
|
// lg::Logger::Info("screen width " + std::to_string(width) +
|
||||||
|
// " screen heigth " + std::to_string(height));
|
||||||
|
|
||||||
|
// Create window with graphics context
|
||||||
|
window = glfwCreateWindow(1200, 800, "pixelarium", nullptr, nullptr);
|
||||||
|
if (window == nullptr)
|
||||||
|
{
|
||||||
|
// lg::Logger::Error("no window");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
glfwSwapInterval(1); // Enable vsync
|
||||||
|
|
||||||
|
// Setup Dear ImGui context
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
(void)io;
|
||||||
|
io.ConfigFlags |=
|
||||||
|
ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||||
|
io.ConfigFlags |=
|
||||||
|
ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
||||||
|
io.ConfigFlags |=
|
||||||
|
ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform
|
||||||
|
// Windows
|
||||||
|
// io.ConfigViewportsNoAutoMerge = true;
|
||||||
|
// io.ConfigViewportsNoTaskBarIcon = true;
|
||||||
|
|
||||||
|
// Setup Dear ImGui style
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
#ifdef __linux__
|
||||||
|
dejavu_serif = io.Fonts->AddFontFromFileTTF(
|
||||||
|
"/usr/share/fonts/dejavu-serif-fonts/DejaVuSerif.ttf", 26.0);
|
||||||
|
IM_ASSERT(dejavu_serif != nullptr);
|
||||||
|
#endif
|
||||||
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
|
|
||||||
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
|
{
|
||||||
|
style.WindowRounding = 0.0f;
|
||||||
|
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup Platform/Renderer backends
|
||||||
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
|
ImGui_ImplOpenGL3_Init(glsl_version);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ui::AppGLFW::Run()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
(void)io;
|
||||||
|
while (!glfwWindowShouldClose(this->window))
|
||||||
|
{
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
|
// Start the Dear ImGui frame
|
||||||
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
ImGui_ImplGlfw_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
// ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
||||||
|
|
||||||
|
// Rendering
|
||||||
|
ImGui::Render();
|
||||||
|
int display_w, display_h;
|
||||||
|
glfwGetFramebufferSize(this->window, &display_w, &display_h);
|
||||||
|
glViewport(0, 0, display_w, display_h);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
|
{
|
||||||
|
GLFWwindow* backup_current_context = glfwGetCurrentContext();
|
||||||
|
ImGui::UpdatePlatformWindows();
|
||||||
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
|
glfwMakeContextCurrent(backup_current_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwSwapBuffers(this->window);
|
||||||
|
}
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
glfwDestroyWindow(this->window);
|
||||||
|
glfwTerminate();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_glfw.h"
|
||||||
|
#include "imgui_impl_opengl3.h"
|
||||||
|
|
||||||
|
namespace ui
|
||||||
|
{
|
||||||
|
enum LogLevelSelection
|
||||||
|
{
|
||||||
|
Debug = 0,
|
||||||
|
Info = 1,
|
||||||
|
Warning = 2,
|
||||||
|
Error = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
class AppGLFW
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppGLFW();
|
||||||
|
int Run();
|
||||||
|
|
||||||
|
private:
|
||||||
|
LogLevelSelection log_level_ = static_cast<LogLevelSelection>(0);
|
||||||
|
GLFWwindow* window = nullptr;
|
||||||
|
ImGuiWindowFlags window_flags = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void glfw_error_callback(int error, const char* description)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
|
||||||
|
}
|
||||||
|
} // namespace ui
|
||||||
+5
-1
@@ -1,7 +1,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "AppGLFW.hpp"
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
std::cout << "ok\n";
|
std::cout << "ok\n";
|
||||||
return 0;
|
auto app = ui::AppGLFW();
|
||||||
|
|
||||||
|
return app.Run();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user