17#include <GLFW/glfw3.h>
122enum class InputState { Released = 0, Pressed = 1, Repeat = 2 };
176 bool init(
int w,
int h, std::string title,
bool resizable =
true,
bool vsync =
true);
186 void run(std::function<
void(
float)> update_callback);
219 void clear(
float r,
float g,
float b,
float a = 1.0f);
255 void set_size(
int width,
int height);
262 void set_title(
const std::string &title);
385 inline void set_resize_callback(std::function<
void(
int,
int)> callback) { m_resize_callback = callback; };
408 inline float get_fps()
const {
return m_fps; };
432 static void fb_size_callback(GLFWwindow *window,
int w,
int h);
446 static void key_callback(GLFWwindow *window,
int key,
int scancode,
int action,
int mods);
459 static void mouse_button_callback(GLFWwindow *window,
int button,
int action,
int mods);
470 static void cursor_position_callback(GLFWwindow *window,
double xpos,
double ypos);
481 static void scroll_callback(GLFWwindow *window,
double xoffs,
double yoffs);
486 void update_input_state();
489 GLFWwindow *m_window =
nullptr;
498 bool m_fullscreen =
false;
501 float m_delta_time = 0.0f;
504 float m_last_frame_time = 0.0f;
513 int m_frame_count = 0;
516 float m_fps_timer = 0.0f;
519 bool m_key_states[512] = {
false};
522 bool m_key_just_pressed[512] = {
false};
525 bool m_key_just_released[512] = {
false};
528 bool m_mouse_button_states[8] = {
false};
531 double m_mouse_x = 0.0;
534 double m_mouse_y = 0.0;
537 double m_last_mouse_x = 0.0;
540 double m_last_mouse_y = 0.0;
543 double m_scroll_x = 0.0;
546 double m_scroll_y = 0.0;
549 std::function<void(
int,
int)> m_resize_callback;
A singleton class that manages the main application loop using GLFW.
Definition engine.hpp:153
int get_width() const
Retrieves the window's width.
Definition engine.hpp:233
void set_title(const std::string &title)
Sets the window title to a new string.
Definition engine.cpp:109
bool is_running() const
Check if the engine is still running.
Definition engine.cpp:90
void get_scroll_offset(double &xoffs, double &yoffs) const
Retrieves the offset of scroll on x and y axes since the last frame.
Definition engine.cpp:196
double get_mouse_x() const
Retrieves the x position of the mouse in the window.
Definition engine.hpp:333
GLFWwindow * get_window() const
Get the GLFW window associated with the engine.
Definition engine.hpp:380
float get_time() const
Retrieves the total time elapsed since the engine's start.
Definition engine.hpp:401
static Engine & get_instance()
Get the singleton instance of the Engine.
Definition engine.cpp:10
bool is_key_pressed(Key key) const
Checks if a key is currently pressed.
Definition engine.cpp:149
void get_mouse_delta(double &dx, double &dy) const
Retrieves the mouse position change (delta) between the last frame and the current frame.
Definition engine.cpp:169
bool is_key_just_released(Key key) const
Checks if a key was just released this frame.
Definition engine.cpp:159
void maximize()
Maximizes the window to occupy the entirety of the screen.
Definition engine.cpp:129
bool init(int w, int h, std::string title, bool resizable=true, bool vsync=true)
Initialize the engine with the specified window dimensions and title.
Definition engine.cpp:15
void set_size(int width, int height)
Sets the window to a new size.
Definition engine.cpp:101
void minimize()
Minimizes the window.
Definition engine.cpp:135
void set_vsync(VSyncMode mode)
Set VSync mode.
Definition engine.cpp:147
void set_mouse_position(double x, double y)
Sets the mouse position to a (x,y) coordinate.
Definition engine.cpp:174
void free()
Free resources and clean up the engine.
Definition engine.cpp:77
float get_fps() const
Retrieves the current FPS count.
Definition engine.hpp:408
void set_cursor_mode(CursorMode mode)
Sets a new cursor mode to the engine.
Definition engine.cpp:180
void set_fullscreen(bool fullscreen)
Toggles fullscreen mode.
Definition engine.cpp:115
bool is_mouse_button_pressed(MouseButton button) const
Checks if a mouse button is pressed.
Definition engine.cpp:164
void shutdown()
Shuts the engine down and closes the window.
Definition engine.cpp:92
void run(std::function< void(float)> update_callback)
Run the main application loop.
Definition engine.cpp:53
int get_height() const
Retrieves the window's height.
Definition engine.hpp:240
void clear(float r, float g, float b, float a=1.0f)
Clear the screen.
Definition engine.cpp:85
void restore()
Restores the window from minimized/maximized state.
Definition engine.cpp:141
void set_resize_callback(std::function< void(int, int)> callback)
Sets the callback responsible for window resizing.
Definition engine.hpp:385
double get_mouse_y() const
Retrieves the y position of the mouse in the window.
Definition engine.hpp:340
float get_aspect_ratio() const
Returns the aspect ratio of the window (width/height).
Definition engine.cpp:98
bool is_key_just_pressed(Key key) const
Checks if a key was just pressed this frame.
Definition engine.cpp:154
float get_delta_time() const
Get the delta time between the current and last frame.
Definition engine.hpp:394
bool is_fullscreen() const
Checks if the window is in fullscreen mode.
Definition engine.hpp:279
InputState
Key/button states.
Definition engine.hpp:122
Key
Input key codes.
Definition engine.hpp:43
VSyncMode
VSync mode.
Definition engine.hpp:136
@ Adaptive
Adaptive VSync - Only when FPS exceeds refresh rate.
Definition engine.hpp:139
@ On
Standard VSync - Locks to monitor refresh rate.
Definition engine.hpp:138
@ Off
Disabled VSync - unlimited FPS.
Definition engine.hpp:137
MouseButton
Mouse button codes.
Definition engine.hpp:117
CursorMode
Cursor mode.
Definition engine.hpp:127
@ Hidden
Cursor is invisible but can still move freely.
Definition engine.hpp:129
@ Normal
Cursor is visible and behaves normally.
Definition engine.hpp:128
@ Disabled
Cursor is locked to window center (FPS mode)
Definition engine.hpp:130
Core components of the LMGL project.
Forward declarations for Assimp Material structure.
Definition model_loader.cpp:12