Brenta Engine 1.2
Loading...
Searching...
No Matches
window.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8// clang-format off
9// The order of these includes is important
10#include <glad/glad.h>
11#include <GLFW/glfw3.h>
12// clang-format on
13
14#include <brenta/subsystem.hpp>
15#include <string>
16
17namespace brenta
18{
19
28class window : public subsystem
29{
30public:
31
32 struct config;
33 class builder;
34
35 static const std::string subsystem_name;
36 static const window::config default_config;
37 static window::config init_config;
38
39 // Subsystem interface
40 std::expected<void, subsystem::error> initialize() override;
41 std::expected<void, subsystem::error> terminate() override;
42 std::string name() override;
43 bool is_initialized() override;
44
45 // Constructors destructors
46 window() = default;
47 ~window() = default;
48
49 // Member functions
50
54 static brenta::window &instance();
55
56 //
57 // Getters
58 //
59
60 static int get_width();
61 static int get_height();
62 static bool should_close();
63 static bool is_key_pressed(int key);
64 static float get_time();
65 static GLFWwindow *get_window();
70 static GLFWglproc get_proc_address();
71
72 //
73 // Setters
74 //
75
76 static void set_mouse_callback(GLFWcursorposfun callback);
77 static void set_size_callback(GLFWframebuffersizefun callback);
78 static void set_mouse_pos_callback(GLFWcursorposfun callback);
79 static void set_key_callback(GLFWkeyfun callback);
80 static void set_mouse_capture(bool is_captured);
81 static void set_width_height(int width, int height);
82 static void close();
83
84 //
85 // Utils
86 //
87
93 static void swap_buffers();
97 static void poll_events();
98
99private:
100
101 static int width;
102 static int height;
103 static GLFWwindow *window_backend;
104 static std::string title;
105 static bool initialized;
106
107 static void set_context_version(int major, int minor);
108 static void use_core_profile();
109 static void set_hints_apple();
110 static void create_window(int width, int height, std::string title);
111 static void make_context_current();
112 static void framebuffer_size_callback(GLFWwindow *window_backend, int width,
113 int height);
114};
115
117{
118public:
119 int width;
120 int height;
121 std::string title;
122 bool capture_mouse;
123 bool msaa;
124 bool vsync;
125 bool debug;
126};
127
129{
130private:
131
132 window::config conf = window::default_config;
133
134public:
135
136 builder() = default;
137 ~builder() = default;
138
139 builder &width(int width);
140 builder &height(int height);
141 builder &title(const std::string &title);
142 builder &capture_mouse();
143 builder &msaa();
144 builder &vsync();
145 builder &debug(); // opengl debug errors, set this during development
146
147 subsystem &build() override;
148};
149
150} // namespace brenta
Builder interface.
Definition subsystem.hpp:49
Subsystem interface.
Definition subsystem.hpp:22
Window subsystem.
Definition window.hpp:29
std::string name() override
Returns the name of the sybsystem.
Definition window.cpp:105
static void poll_events()
Poll all pending events.
Definition window.cpp:203
static brenta::window & instance()
Get a static instance of the window.
Definition window.cpp:119
bool is_initialized() override
Returns true if the subsystem is initialized.
Definition window.cpp:110
static void swap_buffers()
Swap the front and back buffers.
Definition window.cpp:198
static GLFWglproc get_proc_address()
Get the OpenGL function pointer.
Definition window.cpp:152