mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-10-01 15:46:17 -04:00
Added OS library and simple window support.
This commit is contained in:
parent
611747272e
commit
5db68079fb
@ -3,4 +3,5 @@ project(OpenDiablo2)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
add_subdirectory(OpenDiablo2.Game)
|
||||
add_subdirectory(OpenDiablo2.Game)
|
||||
add_subdirectory(OpenDiablo2.OS)
|
||||
|
@ -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)
|
||||
|
@ -1,9 +0,0 @@
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main() {
|
||||
std::cout
|
||||
<< "Hello, World!"
|
||||
<< std::endl;
|
||||
return 0;
|
||||
}
|
11
OpenDiablo2.Game/src/main.cpp
Normal file
11
OpenDiablo2.Game/src/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include <memory>
|
||||
#include <D2Window.h>
|
||||
|
||||
int
|
||||
main() {
|
||||
auto window = std::make_unique<OpenDiablo2::OS::D2Window>();
|
||||
window->Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
26
OpenDiablo2.OS/CMakeLists.txt
Normal file
26
OpenDiablo2.OS/CMakeLists.txt
Normal 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
|
||||
)
|
||||
|
29
OpenDiablo2.OS/include/D2Window.h
Normal file
29
OpenDiablo2.OS/include/D2Window.h
Normal 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
|
38
OpenDiablo2.OS/src/D2Window.cpp
Normal file
38
OpenDiablo2.OS/src/D2Window.cpp
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user