Brenta Engine 1.0
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 isMouseCaptured = false, const char *title = "OpenGL",
80 bool msaa = false, bool vsync = false);
81
82 /* Getters */
83
88 static int GetWidth();
92 static int GetHeight();
97 static bool isWindowClosed();
103 static bool isKeyPressed(int key);
108 static float GetTime();
113 static GLFWwindow *GetWindow();
118 static GLFWglproc GetProcAddress();
119
120 /* Setters */
121
126 static void SetMouseCallback(GLFWcursorposfun callback);
131 static void SetSizeCallback(GLFWframebuffersizefun callback);
136 static void SetMousePosCallback(GLFWcursorposfun callback);
141 static void SetKeyCallback(GLFWkeyfun callback);
146 static void SetMouseCapture(bool isCaptured);
150 static void SetClose();
151
152 /* Utils */
153
159 static void SwapBuffers();
163 static void PollEvents();
167 static void Terminate();
168
169 private:
170 static void SetContextVersion(int major, int minor);
171 static void UseCoreProfile();
172 static void SetHintsApple();
173 static void CreateWindow(int SCR_WIDTH, int SCR_HEIGHT, const char *title);
174 static void MakeContextCurrent();
175 static void Framebuffer_size_callback(GLFWwindow *window, int width,
176 int height);
177};
178
179} // namespace Brenta
Screen subsystem.
Definition screen.hpp:48
static void SetClose()
Set the window close flag.
Definition screen.cpp:142
static int GetHeight()
Get the height of the window.
Definition screen.cpp:110
static GLFWglproc GetProcAddress()
Get the OpenGL function pointer.
Definition screen.cpp:100
static void SetMouseCapture(bool isCaptured)
Set the mouse capture.
Definition screen.cpp:127
static int HEIGHT
Height of the window.
Definition screen.hpp:57
static void SetMousePosCallback(GLFWcursorposfun callback)
Set the mouse position callback.
Definition screen.cpp:176
static void SetMouseCallback(GLFWcursorposfun callback)
Set the mouse callback.
Definition screen.cpp:115
static int GetWidth()
Get the width of the window.
Definition screen.cpp:105
static bool isWindowClosed()
Check if the window is closed.
Definition screen.cpp:80
static void PollEvents()
Poll all pending events.
Definition screen.cpp:158
static GLFWwindow * GetWindow()
Get the window.
Definition screen.cpp:95
static GLFWwindow * window
Pointer to the window.
Definition screen.hpp:61
static float GetTime()
Get the time.
Definition screen.cpp:90
static void SetSizeCallback(GLFWframebuffersizefun callback)
Set the key callback.
Definition screen.cpp:120
static void Init(int SCR_WIDTH, int SCR_HEIGHT, bool isMouseCaptured=false, const char *title="OpenGL", bool msaa=false, bool vsync=false)
Initialize the window.
Definition screen.cpp:42
static void Terminate()
Terminate the window.
Definition screen.cpp:147
static bool isKeyPressed(int key)
Check if a key is pressed.
Definition screen.cpp:85
static void SetKeyCallback(GLFWkeyfun callback)
Set the key callback.
Definition screen.cpp:171
static void SwapBuffers()
Swap the front and back buffers.
Definition screen.cpp:153
static int WIDTH
Width of the window.
Definition screen.hpp:53