Brenta Engine 1.1
Loading...
Searching...
No Matches
screen.hpp
1/*
2 * MIT License
3 *
4 * Copyright (c) 2024 Giovanni Santini
5
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 */
26
27#pragma once
28
29// clang-format off
30// The order of these includes is important
31#include <glad/glad.h>
32#include <GLFW/glfw3.h> /* OpenGL windowing library */
33// clang-format on
34
35namespace brenta
36{
37
47class screen
48{
49 public:
53 static int WIDTH;
57 static int HEIGHT;
61 static GLFWwindow *window;
62
63 screen() = delete;
78 static void init(int SCR_WIDTH, int SCR_HEIGHT,
79 bool is_mouse_captured = false,
80 const char *title = "OpenGL", bool msaa = false,
81 bool vsync = false);
82
83 /* Getters */
84
89 static int get_width();
93 static int get_height();
98 static bool is_window_closed();
104 static bool is_key_pressed(int key);
109 static float get_time();
114 static GLFWwindow *get_window();
119 static GLFWglproc get_proc_address();
120
121 /* Setters */
122
127 static void set_mouse_callback(GLFWcursorposfun callback);
132 static void set_size_callback(GLFWframebuffersizefun callback);
137 static void set_mouse_pos_callback(GLFWcursorposfun callback);
142 static void set_key_callback(GLFWkeyfun callback);
147 static void set_mouse_capture(bool is_captured);
151 static void set_close();
152
153 /* Utils */
154
160 static void swap_buffers();
164 static void poll_events();
168 static void terminate();
169
170 private:
171 static void set_context_version(int major, int minor);
172 static void use_core_profile();
173 static void set_hints_apple();
174 static void create_window(int SCR_WIDTH, int SCR_HEIGHT, const char *title);
175 static void make_context_current();
176 static void framebuffer_size_callback(GLFWwindow *window, int width,
177 int height);
178};
179
180} // namespace brenta
Screen subsystem.
Definition screen.hpp:48
static int WIDTH
Width of the window.
Definition screen.hpp:53
static void poll_events()
Poll all pending events.
Definition screen.cpp:159
static void set_key_callback(GLFWkeyfun callback)
Set the key callback.
Definition screen.cpp:172
static GLFWwindow * get_window()
Get the window.
Definition screen.cpp:95
static void terminate()
Terminate the window.
Definition screen.cpp:146
static void set_close()
Set the window close flag.
Definition screen.cpp:141
static GLFWglproc get_proc_address()
Get the OpenGL function pointer.
Definition screen.cpp:100
static void init(int SCR_WIDTH, int SCR_HEIGHT, bool is_mouse_captured=false, const char *title="OpenGL", bool msaa=false, bool vsync=false)
Initialize the window.
Definition screen.cpp:42
static void set_mouse_capture(bool is_captured)
Set the mouse capture.
Definition screen.cpp:127
static void set_mouse_pos_callback(GLFWcursorposfun callback)
Set the mouse position callback.
Definition screen.cpp:177
static int get_width()
Get the width of the window.
Definition screen.cpp:105
static GLFWwindow * window
Pointer to the window.
Definition screen.hpp:61
static void set_mouse_callback(GLFWcursorposfun callback)
Set the mouse callback.
Definition screen.cpp:115
static int HEIGHT
Height of the window.
Definition screen.hpp:57
static void set_size_callback(GLFWframebuffersizefun callback)
Set the key callback.
Definition screen.cpp:120
static float get_time()
Get the time.
Definition screen.cpp:90
static bool is_window_closed()
Check if the window is closed.
Definition screen.cpp:80
static bool is_key_pressed(int key)
Check if a key is pressed.
Definition screen.cpp:85
static int get_height()
Get the height of the window.
Definition screen.cpp:110
static void swap_buffers()
Swap the front and back buffers.
Definition screen.cpp:154