직렬화 함수 작성 끝

This commit is contained in:
2025-06-09 03:47:48 +09:00
parent 5ba62b5312
commit 50c9bd68fc
47 changed files with 324 additions and 201 deletions

View File

@@ -0,0 +1,21 @@
#include "glfw/glfw_initialization.h"
#include <GLFW/glfw3.h>
#include <cstdlib>
#include "precomp.h"
namespace veng {
void glfw_error_callback(std::int32_t error_code, gsl::czstring message) {
spdlog::error("Glfw Validation: {}", message);
}
GlfwInitialization::GlfwInitialization() {
glfwSetErrorCallback(glfw_error_callback);
if (glfwInit() != GLFW_TRUE) std::exit(EXIT_FAILURE);
}
GlfwInitialization::~GlfwInitialization() { glfwTerminate(); }
} // namespace veng

View File

@@ -0,0 +1,34 @@
#include <GLFW/glfw3.h>
#include "glfw/glfw_monitor.h"
#include "precomp.h"
namespace veng {
gsl::span<GLFWmonitor *> GetMonitors() {
std::int32_t monitor_count = 0;
GLFWmonitor **monitor_pointers = glfwGetMonitors(&monitor_count);
return gsl::span<GLFWmonitor *>(monitor_pointers, monitor_count);
}
glm::ivec2 GetMonitorPosition(gsl::not_null<GLFWmonitor *> monitor) {
glm::ivec2 monitor_position;
glfwGetMonitorPos(monitor, &monitor_position.x, &monitor_position.y);
return monitor_position;
}
glm::ivec2 GetMonitorWorkAreaSize(gsl::not_null<GLFWmonitor *> monitor) {
glm::ivec2 monitor_size;
glfwGetMonitorWorkarea(monitor, nullptr, nullptr, &monitor_size.x,
&monitor_size.y);
return monitor_size;
}
void MoveWindowToMonitor(gsl::not_null<GLFWwindow *> window,
gsl::not_null<GLFWmonitor *> monitor) {
glm::ivec2 window_size;
glfwGetWindowSize(window, &window_size.x, &window_size.y);
const glm::ivec2 window_new_position = GetMonitorPosition(monitor) +
(GetMonitorWorkAreaSize(monitor) / 2) -
(window_size / 2);
glfwSetWindowPos(window, window_new_position.x, window_new_position.y);
}
} // namespace veng

View File

@@ -0,0 +1,50 @@
#include "glfw/glfw_window.h"
#include <GLFW/glfw3.h>
#include "glfw/glfw_monitor.h"
#include "precomp.h"
namespace veng {
Window::Window(gsl::czstring name, glm::ivec2 size) {
// glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
window_ = glfwCreateWindow(size.x, size.y, name, nullptr, nullptr);
if (window_ == nullptr) std::exit(EXIT_FAILURE);
}
Window::~Window() { glfwDestroyWindow(window_); }
glm::ivec2 Window::GetWindowSize() const {
glm::ivec2 window_size;
glfwGetWindowSize(window_, &window_size.x, &window_size.y);
return window_size;
}
glm::ivec2 Window::GetFramebufferSize() const {
glm::ivec2 size;
glfwGetFramebufferSize(window_, &size.x, &size.y);
return size;
}
bool Window::ShouldClose() const { return glfwWindowShouldClose(window_); }
GLFWwindow* Window::GetHandle() const { return window_; }
GLFWkeyfun Window::SetKeyCallback(GLFWkeyfun key_callback) {
return glfwSetKeyCallback(window_, key_callback);
}
bool Window::TryMoveToMonitor(std::uint16_t monitor_number) {
gsl::span<GLFWmonitor*> monitors = veng::GetMonitors();
if (monitor_number < monitors.size()) {
veng::MoveWindowToMonitor(window_, monitors[monitor_number]);
return true;
}
return false;
}
} // namespace veng