Rendering Engine 0.2.17
Modular Graphics Rendering Engine | v0.2.17
Loading...
Searching...
No Matches
standalone_window_system.cpp
Go to the documentation of this file.
2#include <GLFW/glfw3.h>
3#include <limits>
4#include <stdexcept>
5#include "i_application.hpp"
6
7namespace rendering_engine
8{
10 :
11 mApp(app),
12 mWindow{nullptr},
13 mFramebufferResized(false)
14{
15}
16
17void StandaloneDesktopWindow::CreateAppWindow(unsigned int width, unsigned int height, const std::string& title)
18{
19 glfwInit();
20 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
21 glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
22
24 {
25 const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
26 mFullScreenRes.width = static_cast<unsigned int>(mode->width);
27 mFullScreenRes.height = static_cast<unsigned int>(mode->height);
28 mWindow = glfwCreateWindow(mode->width,
29 mode->height,
30 title.c_str(),
31 glfwGetPrimaryMonitor(), nullptr);
32 }
33 else
34 {
35 if (width > static_cast<unsigned int>(std::numeric_limits<int>::max()) ||
36 height > static_cast<unsigned int>(std::numeric_limits<int>::max()))
37 {
38 throw std::out_of_range("Window dimensions exceed GLFW supported range.");
39 }
40
41 mWindow = glfwCreateWindow(
42 static_cast<int>(width),
43 static_cast<int>(height),
44 title.c_str(),
45 nullptr,
46 nullptr);
47 }
48
49 glfwSetWindowUserPointer(mWindow, this);
50 glfwSetFramebufferSizeCallback(mWindow, FramebufferResizeCallback);
51}
52
54{
55 glfwPollEvents();
56}
57
59{
60 return glfwWindowShouldClose(mWindow);
61}
62
64{
65 return static_cast<void*>(mWindow);
66}
67
69{
70 glfwDestroyWindow(mWindow);
71 glfwTerminate();
72}
73
78
79void StandaloneDesktopWindow::FramebufferResizeCallback(GLFWwindow* window, int width, int height)
80{
81 static_cast<void>(width);
82 static_cast<void>(height);
83
84 auto app = reinterpret_cast<StandaloneDesktopWindow*>(glfwGetWindowUserPointer(window));
85 app->mFramebufferResized = true;
86}
87
92
93
94}
Defines a generic application interface for rendering-based programs.
virtual ScreenSettings GetScreenSettings() const =0
Retrieves the current screen or window settings.
Desktop implementation of the IWindowSystem interface using GLFW.
bool ShouldClose() const override
Checks whether the user has requested to close the window.
StandaloneDesktopWindow(IApplication &app)
Constructs a desktop window system instance.
void CreateAppWindow(unsigned int width, unsigned int height, const std::string &title) override
Creates the main application window.
const IApplication & GetApplication() override
Retrieves a reference to the owning application instance.
void PollEvents() override
Polls and processes OS-level window events (input, resize, close, etc.).
WindowResolution GetFullScreenResolution() const override
Queries the resolution of the full-screen display mode.
void Shutdown() override
Performs cleanup and releases window-related resources.
static void FramebufferResizeCallback(GLFWwindow *window, int width, int height)
GLFW framebuffer resize callback.
void * GetNativeHandle() const override
Returns a pointer to the underlying native window handle.
bool isFullScreen
Whether the application runs in fullscreen mode.
Represents the pixel resolution of a window or display.
unsigned int height
Window or screen height in pixels.
unsigned int width
Window or screen width in pixels.