All Classes Files Functions Variables Typedefs Pages
Public Types | Public Member Functions | List of all members
Window Class Reference

Description

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.
 
RenderContextgetRenderContext ()
 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...
 
- Public Member Functions inherited from SingleBase
void setServiceContext (config::ServiceContext cnt)
 
template<typename Ex , LogLevel LL, typename... Ts>
Error Notice Debug void logAndThrow (Ts...args)
 

Additional Inherited Members

- Protected Member Functions inherited from SingleBase
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)
 

Constructor & Destructor Documentation

Window ( std::string  title = "Lumina Application",
Vec2i  size = Vec2i(600, 400) 
)

Creates a new Window but does not open it.

Parameters
titleTitle of the window (can be set via setTitle())
sizeSize of the window (can be set via resize())

Member Function Documentation

Window::EventCallbackIndex addEventCallback ( EventCallback &&  callback)

Add a callback to process InputEvents.

Returns
A callback index. It's neccessary for deleting the callback later on.
Window::WindowCallbackIndex addWindowCallback ( WindowCallback &&  callback)

Add a callback to process WindowEvents.

Returns
A callback index. It's neccessary for deleting the callback later on.
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.

Note
Currently "open window" implies "creating render context" because we use GLFW
void removeEventCallback ( Window::EventCallbackIndex  index)

Removes an InputEvent callback with the index previously returned by addEventCallback.

Note
This method should not be called regularly.
void removeWindowCallback ( WindowCallbackIndex  index)

Removes an WindowEvent callback with the index previously returned by addWindowCallback.

Note
This method should not be called regularly.
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.

Note
This function must be called before open()!
Parameters
majorThe major version digit
minorThe 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.

Parameters
enableTrue to enable VSync
void update ( )

check for events and window status.

This method should be called every frame to ensure the window behaves properly.