|
lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
|
A singleton class that manages the main application loop using GLFW. More...
#include <engine.hpp>
Public Member Functions | |
| 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. | |
| void | run (std::function< void(float)> update_callback) |
| Run the main application loop. | |
| void | free () |
| Free resources and clean up the engine. | |
| bool | is_running () const |
| Check if the engine is still running. | |
| void | shutdown () |
| Shuts the engine down and closes the window. | |
| void | clear (float r, float g, float b, float a=1.0f) |
| Clear the screen. | |
| void | set_vsync (VSyncMode mode) |
| Set VSync mode. | |
| int | get_width () const |
| Retrieves the window's width. | |
| int | get_height () const |
| Retrieves the window's height. | |
| float | get_aspect_ratio () const |
| Returns the aspect ratio of the window (width/height). | |
| void | set_size (int width, int height) |
| Sets the window to a new size. | |
| void | set_title (const std::string &title) |
| Sets the window title to a new string. | |
| void | set_fullscreen (bool fullscreen) |
| Toggles fullscreen mode. | |
| bool | is_fullscreen () const |
| Checks if the window is in fullscreen mode. | |
| void | maximize () |
| Maximizes the window to occupy the entirety of the screen. | |
| void | minimize () |
| Minimizes the window. | |
| void | restore () |
| Restores the window from minimized/maximized state. | |
| bool | is_key_pressed (Key key) const |
| Checks if a key is currently pressed. | |
| bool | is_key_just_pressed (Key key) const |
| Checks if a key was just pressed this frame. | |
| bool | is_key_just_released (Key key) const |
| Checks if a key was just released this frame. | |
| bool | is_mouse_button_pressed (MouseButton button) const |
| Checks if a mouse button is pressed. | |
| double | get_mouse_x () const |
| Retrieves the x position of the mouse in the window. | |
| double | get_mouse_y () const |
| Retrieves the y position of the mouse in the window. | |
| void | get_mouse_delta (double &dx, double &dy) const |
| Retrieves the mouse position change (delta) between the last frame and the current frame. | |
| void | set_mouse_position (double x, double y) |
| Sets the mouse position to a (x,y) coordinate. | |
| void | set_cursor_mode (CursorMode mode) |
| Sets a new cursor mode to the engine. | |
| void | get_scroll_offset (double &xoffs, double &yoffs) const |
| Retrieves the offset of scroll on x and y axes since the last frame. | |
| GLFWwindow * | get_window () const |
| Get the GLFW window associated with the engine. | |
| void | set_resize_callback (std::function< void(int, int)> callback) |
| Sets the callback responsible for window resizing. | |
| float | get_delta_time () const |
| Get the delta time between the current and last frame. | |
| float | get_time () const |
| Retrieves the total time elapsed since the engine's start. | |
| float | get_fps () const |
| Retrieves the current FPS count. | |
Static Public Member Functions | |
| static Engine & | get_instance () |
| Get the singleton instance of the Engine. | |
A singleton class that manages the main application loop using GLFW.
This class provides methods to initialize the engine, run the main loop, and clean up resources. It also tracks the delta time between frames. The engine is designed to be used in applications that require a rendering loop, such as games or graphical simulations.
| void lmgl::core::Engine::clear | ( | float | r, |
| float | g, | ||
| float | b, | ||
| float | a = 1.0f ) |
Clear the screen.
This method can be used to clear the screen before rendering a new frame.
| r | Red component of the clear color (0.0 to 1.0). |
| g | Green component of the clear color (0.0 to 1.0). |
| b | Blue component of the clear color (0.0 to 1.0). |
| a | Alpha component of the clear color (0.0 to 1.0), default is 1.0. |
| void lmgl::core::Engine::free | ( | ) |
Free resources and clean up the engine.
Destroys the GLFW window and terminates GLFW.
| float lmgl::core::Engine::get_aspect_ratio | ( | ) | const |
Returns the aspect ratio of the window (width/height).
|
inline |
Get the delta time between the current and last frame.
This value is useful for frame-independent movement and animations.
@returnDelta time in seconds.
|
inline |
Retrieves the current FPS count.
|
inline |
Retrieves the window's height.
|
static |
| void lmgl::core::Engine::get_mouse_delta | ( | double & | dx, |
| double & | dy ) const |
Retrieves the mouse position change (delta) between the last frame and the current frame.
| dx | return parameter for the mouse position delta on the x axis |
| dy | return parameter for the mouse position delta on the y axis |
|
inline |
Retrieves the x position of the mouse in the window.
|
inline |
Retrieves the y position of the mouse in the window.
| void lmgl::core::Engine::get_scroll_offset | ( | double & | xoffs, |
| double & | yoffs ) const |
Retrieves the offset of scroll on x and y axes since the last frame.
| xoffs | the offset of scroll on the x axis since the last frame |
| yoffs | the offset of scroll on the y axis since the last frame |
|
inline |
Retrieves the total time elapsed since the engine's start.
|
inline |
Retrieves the window's width.
|
inline |
Get the GLFW window associated with the engine.
The returned pointer can be used for further GLFW operations.
| bool lmgl::core::Engine::init | ( | int | w, |
| int | h, | ||
| std::string | title, | ||
| bool | resizable = true, | ||
| bool | vsync = true ) |
Initialize the engine with the specified window dimensions and title.
Initializes GLFW, creates a window, and sets up the necessary context for rendering. Returns true if initialization is successful, false otherwise.
| w | Width of the window. |
| h | Height of the window. |
| title | Title of the window. |
|
inline |
Checks if the window is in fullscreen mode.
| bool lmgl::core::Engine::is_key_just_pressed | ( | Key | key | ) | const |
Checks if a key was just pressed this frame.
| key | the key to check |
| bool lmgl::core::Engine::is_key_just_released | ( | Key | key | ) | const |
Checks if a key was just released this frame.
| key | the key to check |
| bool lmgl::core::Engine::is_key_pressed | ( | Key | key | ) | const |
Checks if a key is currently pressed.
| key | the key to check |
| bool lmgl::core::Engine::is_mouse_button_pressed | ( | MouseButton | button | ) | const |
Checks if a mouse button is pressed.
| button | the mouse button to check |
| bool lmgl::core::Engine::is_running | ( | ) | const |
Check if the engine is still running.
The engine is considered running as long as the window has not been closed.
| void lmgl::core::Engine::run | ( | std::function< void(float)> | update_callback | ) |
Run the main application loop.
The loop continues until the window is closed. The provided update callback is called each frame with the delta time as an argument.
| update_callback | A function to be called each frame with delta time. |
| void lmgl::core::Engine::set_cursor_mode | ( | CursorMode | mode | ) |
Sets a new cursor mode to the engine.
| mode | the new cursor mode to set |
| void lmgl::core::Engine::set_fullscreen | ( | bool | fullscreen | ) |
Toggles fullscreen mode.
Fullscreen mode forces the window to render as fullscreen, overriding system controls.
| fullscreen | the new fullscreen state (true/false) |
| void lmgl::core::Engine::set_mouse_position | ( | double | x, |
| double | y ) |
Sets the mouse position to a (x,y) coordinate.
| x | the new x coordinate component of the mouse position |
| y | the new y coordinate component of the mouse position |
| void lmgl::core::Engine::set_size | ( | int | width, |
| int | height ) |
Sets the window to a new size.
| width | the new window width |
| height | the new window height |
| void lmgl::core::Engine::set_title | ( | const std::string & | title | ) |
Sets the window title to a new string.
| title | the new title to set. |
| void lmgl::core::Engine::set_vsync | ( | VSyncMode | mode | ) |
Set VSync mode.
| mode | The VSync mode to set |