1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-09 09:20:44 +00:00

Added OS library and simple window support.

This commit is contained in:
Tim Sarbin 2019-02-20 15:37:10 -05:00
parent 611747272e
commit 5db68079fb
7 changed files with 109 additions and 12 deletions

View File

@ -3,4 +3,5 @@ project(OpenDiablo2)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(OpenDiablo2.Game)
add_subdirectory(OpenDiablo2.Game)
add_subdirectory(OpenDiablo2.OS)

View File

@ -1,3 +1,4 @@
add_executable(OpenDiablo2 src/main.cpp)
add_executable(OpenDiablo2 main.cpp)
include_directories(OpenDiablo2 ../OpenDiablo2.OS/include)
target_link_libraries(OpenDiablo2 OpenDiablo2.OS)

View File

@ -1,9 +0,0 @@
#include <iostream>
int
main() {
std::cout
<< "Hello, World!"
<< std::endl;
return 0;
}

View File

@ -0,0 +1,11 @@
#include <memory>
#include <D2Window.h>
int
main() {
auto window = std::make_unique<OpenDiablo2::OS::D2Window>();
window->Run();
return 0;
}

View File

@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE src
)

View File

@ -0,0 +1,29 @@
#ifndef OPENDIABLO2_WINDOW_H
#define OPENDIABLO2_WINDOW_H
#include <memory>
class GLFWwindow;
namespace OpenDiablo2 { namespace OS {
class D2Window {
public:
D2Window();
void Run();
private:
GLFWwindow* glfwWindow;
void
InitializeWindow();
void
FinalizeWindow();
};
typedef std::unique_ptr<D2Window> D2WindowPtr;
}}
#endif //OPENDIABLO2_WINDOW_H

View File

@ -0,0 +1,38 @@
#include <D2Window.h>
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
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();
}
}
}