From 5db68079fba5bf76ebeb1c19b6861869482ac710 Mon Sep 17 00:00:00 2001 From: Tim Sarbin Date: Wed, 20 Feb 2019 15:37:10 -0500 Subject: [PATCH] Added OS library and simple window support. --- CMakeLists.txt | 3 ++- OpenDiablo2.Game/CMakeLists.txt | 5 ++-- OpenDiablo2.Game/main.cpp | 9 -------- OpenDiablo2.Game/src/main.cpp | 11 +++++++++ OpenDiablo2.OS/CMakeLists.txt | 26 +++++++++++++++++++++ OpenDiablo2.OS/include/D2Window.h | 29 +++++++++++++++++++++++ OpenDiablo2.OS/src/D2Window.cpp | 38 +++++++++++++++++++++++++++++++ 7 files changed, 109 insertions(+), 12 deletions(-) delete mode 100644 OpenDiablo2.Game/main.cpp create mode 100644 OpenDiablo2.Game/src/main.cpp create mode 100644 OpenDiablo2.OS/CMakeLists.txt create mode 100644 OpenDiablo2.OS/include/D2Window.h create mode 100644 OpenDiablo2.OS/src/D2Window.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 638f9572..8cca703e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,4 +3,5 @@ project(OpenDiablo2) set(CMAKE_CXX_STANDARD 17) -add_subdirectory(OpenDiablo2.Game) \ No newline at end of file +add_subdirectory(OpenDiablo2.Game) +add_subdirectory(OpenDiablo2.OS) diff --git a/OpenDiablo2.Game/CMakeLists.txt b/OpenDiablo2.Game/CMakeLists.txt index 5bef6425..e0da1d6f 100644 --- a/OpenDiablo2.Game/CMakeLists.txt +++ b/OpenDiablo2.Game/CMakeLists.txt @@ -1,3 +1,4 @@ +add_executable(OpenDiablo2 src/main.cpp) - -add_executable(OpenDiablo2 main.cpp) \ No newline at end of file +include_directories(OpenDiablo2 ../OpenDiablo2.OS/include) +target_link_libraries(OpenDiablo2 OpenDiablo2.OS) diff --git a/OpenDiablo2.Game/main.cpp b/OpenDiablo2.Game/main.cpp deleted file mode 100644 index 68d220f1..00000000 --- a/OpenDiablo2.Game/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int -main() { - std::cout - << "Hello, World!" - << std::endl; - return 0; -} \ No newline at end of file diff --git a/OpenDiablo2.Game/src/main.cpp b/OpenDiablo2.Game/src/main.cpp new file mode 100644 index 00000000..32f3e8e2 --- /dev/null +++ b/OpenDiablo2.Game/src/main.cpp @@ -0,0 +1,11 @@ +#include +#include + +int +main() { + auto window = std::make_unique(); + window->Run(); + return 0; +} + + diff --git a/OpenDiablo2.OS/CMakeLists.txt b/OpenDiablo2.OS/CMakeLists.txt new file mode 100644 index 00000000..3f2d10c1 --- /dev/null +++ b/OpenDiablo2.OS/CMakeLists.txt @@ -0,0 +1,26 @@ +project(libOpenDiablo2.OS VERSION 0.1 LANGUAGES CXX) + +set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) +set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) +add_subdirectory(../3rdparty/glfw build) + +include_directories( + include + ../3rdparty/glfw/include +) + +add_library(OpenDiablo2.OS + src/D2Window.cpp +) + +target_link_libraries(OpenDiablo2.OS + glfw +) + +target_include_directories(OpenDiablo2.OS PUBLIC + $ + $ + PRIVATE src +) + diff --git a/OpenDiablo2.OS/include/D2Window.h b/OpenDiablo2.OS/include/D2Window.h new file mode 100644 index 00000000..5871d87d --- /dev/null +++ b/OpenDiablo2.OS/include/D2Window.h @@ -0,0 +1,29 @@ +#ifndef OPENDIABLO2_WINDOW_H +#define OPENDIABLO2_WINDOW_H + +#include + + +class GLFWwindow; + +namespace OpenDiablo2 { namespace OS { + +class D2Window { +public: + D2Window(); + void Run(); +private: + GLFWwindow* glfwWindow; + + void + InitializeWindow(); + + void + FinalizeWindow(); +}; + +typedef std::unique_ptr D2WindowPtr; + +}} + +#endif //OPENDIABLO2_WINDOW_H diff --git a/OpenDiablo2.OS/src/D2Window.cpp b/OpenDiablo2.OS/src/D2Window.cpp new file mode 100644 index 00000000..5039d5f4 --- /dev/null +++ b/OpenDiablo2.OS/src/D2Window.cpp @@ -0,0 +1,38 @@ +#include +#define GLFW_INCLUDE_NONE +#include + +namespace OpenDiablo2 { + namespace OS { + + D2Window::D2Window() { + + } + + void + D2Window::Run() { + InitializeWindow(); + while (!glfwWindowShouldClose(glfwWindow)) { + glfwPollEvents(); + } + FinalizeWindow(); + } + + void + D2Window::InitializeWindow() { + if (!glfwInit()) { + throw std::runtime_error( + "GLFW could not initialize the host window."); + } + + glfwWindowHint(GLFW_RESIZABLE, 0); + glfwWindow = glfwCreateWindow(800, 600, "OpenDiablo 2", NULL, NULL); + } + + void + D2Window::FinalizeWindow() { + glfwDestroyWindow(glfwWindow); + glfwTerminate(); + } + } +}