Raftel Engine
 
Loading...
Searching...
No Matches
window.hpp
Go to the documentation of this file.
1
16
17#ifndef __WINDOW_H__
18#define __WINDOW_H__ 1
19
20#pragma once
21
22#include <GL/glew.h>
23#include <GLFW/glfw3.h>
24#include <optional>
25
26#include <memory>
27#include <raftel/input.hpp>
28#include <raftel/global_macros.hpp>
29#include <glm/glm.hpp>
30
31namespace Raftel {
32 constexpr float SCREEN_WIDTH = 640.0f;
33 constexpr float SCREEN_HEIGHT = 480.0f;
34
43 public:
48 static std::unique_ptr<WindowSystem> make();
49
53 ~WindowSystem() noexcept;
54 WindowSystem& operator=(WindowSystem&) {}
61 WindowSystem(WindowSystem&& other) noexcept;
62
67
68 private:
69 bool destroy_;
70
71 // Delete copy constructor and assignment operator to prevent copying
72 WindowSystem(const WindowSystem&) = delete;
73 WindowSystem& operator=(const WindowSystem&) = delete;
74 };
75
83 class Window
84 {
85 public:
95 static std::unique_ptr<Window> make(const char* title, WindowSystem& ws, int width = 0, int height = 0, bool fullscreen = false);
100 NO_COPYABLE_OR_MOVABLE(Window)
105
111 bool ShouldClose(bool allowEscapeKey = true);
112
116 void clear();
117
122
127 glm::ivec2 getScreenSize();
132 void toggleFullscreen(GLFWwindow* window);
138 void onResize(int newWidth, int newHeight);
139
140 std::unique_ptr<Input> input;
141 GLFWwindow* window_;
142
147 Window(GLFWwindow* w);
148
149 bool isFullscreen = false;
150 private:
151 bool wasMaximized = false;
152 int lastWidth, lastHeight;
153 int lastPosX, lastPosY;
154
155 int width, height;
156 const char* name_;
157 };
158} // namespace Raftel
159
160#endif // !__WINDOW_HPP__
Manages keyboard and mouse input.
Definition input.hpp:17
~Window()
Destructor that destroys the GLFW window and releases associated resources.
void toggleFullscreen(GLFWwindow *window)
Toggles between fullscreen and windowed modes.
void MakeContextCurrent()
Makes the window context current for OpenGL operations.
GLFWwindow * window_
The GLFW window instance.
Definition window.hpp:141
void swapBuffers()
Swaps the front and back buffers, displaying the rendered content.
std::unique_ptr< Input > input
Input handler associated with the window.
Definition window.hpp:140
static std::unique_ptr< Window > make(const char *title, WindowSystem &ws, int width=0, int height=0, bool fullscreen=false)
Creates a new window with the specified properties.
bool ShouldClose(bool allowEscapeKey=true)
Checks if the window should close, optionally checking for the Escape key.
void clear()
Clears the window's buffer (color and depth).
void onResize(int newWidth, int newHeight)
Handles window resize events, adjusting the OpenGL viewport accordingly.
glm::ivec2 getScreenSize()
Gets the current size of the window in screen coordinates.
bool isFullscreen
Whether the window is in fullscreen mode.
Definition window.hpp:149
Window(GLFWwindow *w)
Private constructor used by the make method to initialize the window.
Manages the initialization and termination of the GLFW window system.
Definition window.hpp:42
static std::unique_ptr< WindowSystem > make()
Creates and initializes the WindowSystem.
WindowSystem()
Default constructor for WindowSystem.
WindowSystem(WindowSystem &&other) noexcept
Move constructor for WindowSystem.
~WindowSystem() noexcept
Destructor that terminates the GLFW library if necessary.
constexpr float SCREEN_HEIGHT
Default height of the screen in pixels.
Definition window.hpp:33
constexpr float SCREEN_WIDTH
Default width of the screen in pixels.
Definition window.hpp:32