A Window from which a RenderContext can be obtained.
This is the first object you need in order to do anything else. The window is responsible for polling events of all kinds, containing all window properties (as size and title), handling the OpenGL function and some more things.
After creating an instance of Window you should call setVersionHint() to request a specific OpenGL version. If it isn't called, open() will fail in most cases.
Inherits SingleBase.
Public Types | |
using | EventCallback = std::function< EventResult(InputEvent)> |
Functor type for handling InputEvents. | |
using | EventCallbackIndex = std::vector< EventCallback >::size_type |
Type for accessing a specific EventCallback. | |
using | WindowCallback = std::function< EventResult(WindowEvent)> |
Functor type for handling WindowEvents. | |
using | WindowCallbackIndex = std::vector< WindowCallback >::size_type |
Type for accessing a specific WindowCallback. | |
Public Member Functions | |
Window (std::string title="Lumina Application", Vec2i size=Vec2i(600, 400)) | |
Creates a new Window but does not open it. More... | |
void | setVersionHint (int major, int minor=0) |
Sets a hint which OpenGL version to use to create the context. More... | |
void | setVSync (bool enable) |
Disables or enables VSync If VSync is enabled RenderContext::swapBuffers will be synchronized with the screen refresh rate. More... | |
void | setTitle (std::string title) |
Changes the title of the window. | |
void | resize (Vec2i size) |
Resizes the window. | |
void | setCursorMode (CursorMode mode) |
Sets the mode of the mouse cursor. | |
Vec2i | getSize () |
Returns the current size of the window. | |
RenderContext & | getRenderContext () |
Returns the OpenGL context for this window. | |
void | open () |
Opens the window. More... | |
void | close () |
Closes window and free resources. | |
void | pollEvents () |
Check for new events. | |
void | update () |
check for events and window status. More... | |
bool | isValid () |
Returns if the window is valid. More... | |
EventCallbackIndex | addEventCallback (EventCallback &&callback) |
Add a callback to process InputEvents. More... | |
void | removeEventCallback (EventCallbackIndex index) |
Removes an InputEvent callback with the index previously returned by addEventCallback. More... | |
WindowCallbackIndex | addWindowCallback (WindowCallback &&callback) |
Add a callback to process WindowEvents. More... | |
void | removeWindowCallback (WindowCallbackIndex index) |
Removes an WindowEvent callback with the index previously returned by addWindowCallback. More... | |
![]() | |
void | setServiceContext (config::ServiceContext cnt) |
template<typename Ex , LogLevel LL, typename... Ts> | |
Error Notice Debug void | logAndThrow (Ts...args) |
Additional Inherited Members | |
![]() | |
template<typename... Ts> | |
void | logCritical (Ts...args) |
template<typename... Ts> | |
void | logError (Ts...args) |
template<typename... Ts> | |
void | logWarning (Ts...args) |
template<typename... Ts> | |
void | logNotice (Ts...args) |
template<typename... Ts> | |
void | log (Ts...args) |
template<typename... Ts> | |
void | logDebug (Ts...args) |
template<typename Ex , LogLevel LL = LogLevel::Error, typename... Ts> | |
void | logAndThrow (Ts...args) |
Creates a new Window but does not open it.
title | Title of the window (can be set via setTitle()) |
size | Size of the window (can be set via resize()) |
Window::EventCallbackIndex addEventCallback | ( | EventCallback && | callback | ) |
Add a callback to process InputEvents.
Window::WindowCallbackIndex addWindowCallback | ( | WindowCallback && | callback | ) |
Add a callback to process WindowEvents.
bool isValid | ( | ) |
Returns if the window is valid.
The window can become invalid when the X Button is pressed or for some other reasons. You should always check if the window is still valid. In case this method returns false you should close the window. If you don't close it and update() is called twice after that, the window will close itself.
void open | ( | ) |
Opens the window.
void removeEventCallback | ( | Window::EventCallbackIndex | index | ) |
Removes an InputEvent callback with the index previously returned by addEventCallback.
void removeWindowCallback | ( | WindowCallbackIndex | index | ) |
Removes an WindowEvent callback with the index previously returned by addWindowCallback.
void setVersionHint | ( | int | major, |
int | minor = 0 |
||
) |
Sets a hint which OpenGL version to use to create the context.
The underlying implementation might ignore the hint. If this is the case a warning is logged.
major | The major version digit |
minor | The minor version digit |
void setVSync | ( | bool | enable | ) |
Disables or enables VSync If VSync is enabled RenderContext::swapBuffers will be synchronized with the screen refresh rate.
enable | True to enable VSync |
void update | ( | ) |
check for events and window status.
This method should be called every frame to ensure the window behaves properly.