Magnum::Platform::GlfwApplication class

GLFW application.

Application using the GLFW toolkit. Supports keyboard and mouse handling with support for changing cursor and mouse tracking and warping. Available on all platforms where GLFW is ported.

Bootstrap application

Fully contained base application using GlfwApplication along with CMake setup is available in base-glfw branch of Magnum Bootstrap repository, download it as tar.gz or zip file. After extracting the downloaded archive you can build and run the application with these four commands:

mkdir build && cd build
cmake ..
cmake --build .
./src/MyApplication # or ./src/Debug/MyApplication

See Usage with CMake for more information.

General usage

This application library depends on GLFW 3.2 and newer and is built if MAGNUM_WITH_GLFWAPPLICATION is enabled when building Magnum. To use this library with CMake, request the GlfwApplication component of the Magnum package and link to the Magnum::GlfwApplication target:

find_package(Magnum REQUIRED GlfwApplication)

# ...
target_link_libraries(your-app PRIVATE Magnum::GlfwApplication)

Additionally, if you're using Magnum as a CMake subproject, bundle the glfw repository and do the following before calling find_package() to ensure it's enabled, as the library is not built by default. If you want to use system-installed GLFW, omit the first part and point CMAKE_PREFIX_PATH to its installation dir if necessary.

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
# These two are be off-by-default and thus no longer needed with GLFW 3.4+
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(glfw EXCLUDE_FROM_ALL)

set(MAGNUM_WITH_GLFWAPPLICATION ON CACHE BOOL "" FORCE)
add_subdirectory(magnum EXCLUDE_FROM_ALL)

If no other application is requested, you can also use the generic Magnum::Application alias to simplify porting. Again, see Downloading and building and Usage with CMake for more information.

In C++ code you need to implement at least drawEvent() to be able to draw on the screen. The subclass can be then used directly in main() — see convenience macro MAGNUM_GLFWAPPLICATION_MAIN(). See Platform support for more information.

class MyApplication: public Platform::GlfwApplication {
    // implement required methods...
};
MAGNUM_GLFWAPPLICATION_MAIN(MyApplication)

If no other application header is included, this class is also aliased to Platform::Application and the macro is aliased to MAGNUM_APPLICATION_MAIN() to simplify porting.

DPI awareness

DPI awareness behavior is consistent with Sdl2Application except that iOS or Emscripten specifics don't apply here. In addition, on Windows, GLFW is implicitly advertising DPI awareness, so the manifest file described in HiDPI support doesn't necessarily need to be supplied. See Sdl2Application DPI awareness documentation for more information.

Public types

struct Arguments
Application arguments.
class Configuration
Configuration.
class ExitEvent
Exit event.
class GLConfiguration
OpenGL context configuration.
class InputEvent
Base for input events.
class KeyEvent
Key event.
class MouseEvent deprecated in Git master
Mouse event.
class MouseMoveEvent deprecated in Git master
Mouse move event.
class MouseScrollEvent deprecated in Git master
Mouse scroll event.
class PointerEvent new in Git master
Pointer event.
class PointerMoveEvent new in Git master
Pointer move event.
class ScrollEvent new in Git master
Scroll event.
class TextInputEvent
Text input event.
class ViewportEvent
Viewport event.
enum class Modifier: Int { Shift = GLFW_MOD_SHIFT, Ctrl = GLFW_MOD_CONTROL, Alt = GLFW_MOD_ALT, Super = GLFW_MOD_SUPER } new in Git master
Keyboard modifier.
enum class Key: Int { Unknown = GLFW_KEY_UNKNOWN, LeftShift = GLFW_KEY_LEFT_SHIFT, RightShift = GLFW_KEY_RIGHT_SHIFT, LeftCtrl = GLFW_KEY_LEFT_CONTROL, RightCtrl = GLFW_KEY_RIGHT_CONTROL, LeftAlt = GLFW_KEY_LEFT_ALT, RightAlt = GLFW_KEY_RIGHT_ALT, LeftSuper = GLFW_KEY_LEFT_SUPER, RightSuper = GLFW_KEY_RIGHT_SUPER, Enter = GLFW_KEY_ENTER, Esc = GLFW_KEY_ESCAPE, Up = GLFW_KEY_UP, Down = GLFW_KEY_DOWN, Left = GLFW_KEY_LEFT, Right = GLFW_KEY_RIGHT, Home = GLFW_KEY_HOME, End = GLFW_KEY_END, PageUp = GLFW_KEY_PAGE_UP, PageDown = GLFW_KEY_PAGE_DOWN, Backspace = GLFW_KEY_BACKSPACE, Insert = GLFW_KEY_INSERT, Delete = GLFW_KEY_DELETE, F1 = GLFW_KEY_F1, F2 = GLFW_KEY_F2, F3 = GLFW_KEY_F3, F4 = GLFW_KEY_F4, F5 = GLFW_KEY_F5, F6 = GLFW_KEY_F6, F7 = GLFW_KEY_F7, F8 = GLFW_KEY_F8, F9 = GLFW_KEY_F9, F10 = GLFW_KEY_F10, F11 = GLFW_KEY_F11, F12 = GLFW_KEY_F12, Space = GLFW_KEY_SPACE, Tab = GLFW_KEY_TAB, Quote = GLFW_KEY_APOSTROPHE new in 2020.06, Comma = GLFW_KEY_COMMA, Period = GLFW_KEY_PERIOD, Minus = GLFW_KEY_MINUS, Plus = '+', Slash = GLFW_KEY_SLASH, Percent = '%', Semicolon = GLFW_KEY_SEMICOLON, Smicolon = Semicolon deprecated in 2019.01, Equal = GLFW_KEY_EQUAL, LeftBracket = GLFW_KEY_LEFT_BRACKET new in 2020.06, RightBracket = GLFW_KEY_RIGHT_BRACKET new in 2020.06, Backslash = GLFW_KEY_BACKSLASH new in 2020.06, Backquote = GLFW_KEY_GRAVE_ACCENT new in 2020.06, World1 = GLFW_KEY_WORLD_1 new in 2020.06, World2 = GLFW_KEY_WORLD_2 new in 2020.06, Zero = GLFW_KEY_0, One = GLFW_KEY_1, Two = GLFW_KEY_2, Three = GLFW_KEY_3, Four = GLFW_KEY_4, Five = GLFW_KEY_5, Six = GLFW_KEY_6, Seven = GLFW_KEY_7, Eight = GLFW_KEY_8, Nine = GLFW_KEY_9, A = GLFW_KEY_A, B = GLFW_KEY_B, C = GLFW_KEY_C, D = GLFW_KEY_D, E = GLFW_KEY_E, F = GLFW_KEY_F, G = GLFW_KEY_G, H = GLFW_KEY_H, I = GLFW_KEY_I, J = GLFW_KEY_J, K = GLFW_KEY_K, L = GLFW_KEY_L, M = GLFW_KEY_M, N = GLFW_KEY_N, O = GLFW_KEY_O, P = GLFW_KEY_P, Q = GLFW_KEY_Q, R = GLFW_KEY_R, S = GLFW_KEY_S, T = GLFW_KEY_T, U = GLFW_KEY_U, V = GLFW_KEY_V, W = GLFW_KEY_W, X = GLFW_KEY_X, Y = GLFW_KEY_Y, Z = GLFW_KEY_Z, CapsLock = GLFW_KEY_CAPS_LOCK, ScrollLock = GLFW_KEY_SCROLL_LOCK, NumLock = GLFW_KEY_NUM_LOCK, PrintScreen = GLFW_KEY_PRINT_SCREEN, Pause = GLFW_KEY_PAUSE, Menu = GLFW_KEY_MENU, NumZero = GLFW_KEY_KP_0, NumOne = GLFW_KEY_KP_1, NumTwo = GLFW_KEY_KP_2, NumThree = GLFW_KEY_KP_3, NumFour = GLFW_KEY_KP_4, NumFive = GLFW_KEY_KP_5, NumSix = GLFW_KEY_KP_6, NumSeven = GLFW_KEY_KP_7, NumEight = GLFW_KEY_KP_8, NumNine = GLFW_KEY_KP_9, NumDecimal = GLFW_KEY_KP_DECIMAL, NumDivide = GLFW_KEY_KP_DIVIDE, NumMultiply = GLFW_KEY_KP_MULTIPLY, NumSubtract = GLFW_KEY_KP_SUBTRACT, NumAdd = GLFW_KEY_KP_ADD, NumEnter = GLFW_KEY_KP_ENTER, NumEqual = GLFW_KEY_KP_EQUAL } new in Git master
Key.
enum class PointerEventSource: UnsignedByte { Mouse } new in Git master
Pointer event source.
enum class Pointer: UnsignedByte { MouseLeft = 1 << 0, MouseMiddle = 1 << 1, MouseRight = 1 << 2, MouseButton4 = 1 << 3, MouseButton5 = 1 << 4, MouseButton6 = 1 << 5, MouseButton7 = 1 << 6, MouseButton8 = 1 << 7 } new in Git master
Pointer type.
using Modifiers = Containers::EnumSet<Modifier> new in Git master
Set of keyboard modifiers.
using Pointers = Containers::EnumSet<Pointer> new in Git master
Set of pointer types.

Constructors, destructors, conversion operators

GlfwApplication(const Arguments& arguments, const Configuration& configuration, const GLConfiguration& glConfiguration) explicit
Construct with an OpenGL context.
GlfwApplication(const Arguments& arguments, const Configuration& configuration = Configuration{}) explicit
Construct without explicit GPU context configuration.
GlfwApplication(const Arguments& arguments, NoCreateT) explicit
Construct without creating a window.
GlfwApplication(const GlfwApplication&) deleted
Copying is not allowed.
GlfwApplication(GlfwApplication&&) deleted
Moving is not allowed.

Public functions

auto operator=(const GlfwApplication&) -> GlfwApplication& deleted
Copying is not allowed.
auto operator=(GlfwApplication&&) -> GlfwApplication& deleted
Moving is not allowed.
auto keyName(Key key, UnsignedInt scanCode = 0) const -> Containers::StringView new in Git master
Name for given key.
auto keyToScanCode(Key key) const -> Containers::Optional<UnsignedInt> new in Git master
Scan code for given key.
auto exec() -> int
Execute main loop.
auto mainLoopIteration() -> bool new in 2020.06
Run one iteration of application main loop.
void exit(int exitCode = 0)
Exit application.
auto window() -> GLFWwindow*
Underlying window handle.

Protected functions

void create(const Configuration& configuration, const GLConfiguration& glConfiguration)
Create a window with given configuration for OpenGL context.
void create(const Configuration& configuration)
Create a window with given configuration.
void create()
Create a window with default configuration and OpenGL context.
auto tryCreate(const Configuration& configuration, const GLConfiguration& glConfiguration) -> bool
Try to create context with given configuration for OpenGL context.
auto tryCreate(const Configuration& configuration) -> bool
Try to create context with given configuration.
void tickEvent() virtual new in Git master
Tick event.

Screen handling

auto windowSize() const -> Vector2i
Window size.
void setWindowSize(const Vector2i& size) new in 2020.06
Set window size.
void setMinWindowSize(const Vector2i& size = {-1, -1}) new in 2019.10
Set window minimum size.
void setMaxWindowSize(const Vector2i& size = {-1, -1}) new in 2019.10
Set window maximum size.
auto framebufferSize() const -> Vector2i
Framebuffer size.
auto dpiScaling() const -> Vector2
DPI scaling.
auto dpiScaling(const Configuration& configuration) -> Vector2
DPI scaling for given configuration.
void setWindowTitle(Containers::StringView title) new in 2019.10
Set window title.
void setWindowIcon(Containers::ArrayView<const ImageView2D> images) new in Git master
Set window icon.
void setWindowIcon(std::initializer_list<ImageView2D> images) new in 2020.06
void setWindowIcon(const ImageView2D& image) new in 2020.06
void swapBuffers()
Swap buffers.
void setSwapInterval(Int interval)
Set swap interval.
void setMinimalLoopPeriod(Nanoseconds time) new in Git master
Set minimal loop period.
void redraw()
Redraw immediately.
void viewportEvent(ViewportEvent& event) private virtual
Viewport event.
void drawEvent() private pure virtual
Draw event.

Keyboard handling

void keyPressEvent(KeyEvent& event) private virtual
Key press event.
void keyReleaseEvent(KeyEvent& event) private virtual
Key release event.

Pointer handling

enum class Cursor: UnsignedInt { Arrow, TextInput, Crosshair, ResizeNWSE, ResizeNESW, ResizeWE, ResizeNS, ResizeAll, No, Hand, Hidden, HiddenLocked } new in 2020.06
Cursor type.
void setCursor(Cursor cursor) new in 2020.06
Set cursor type.
auto cursor() -> Cursor new in 2020.06
Get current cursor type.
void warpCursor(const Vector2i& position) new in 2020.06
Warp mouse cursor to given coordinates.
void pointerPressEvent(PointerEvent& event) private virtual new in Git master
Pointer press event.
void mousePressEvent(MouseEvent& event) deprecated in Git master private virtual
Mouse press event.
void pointerReleaseEvent(PointerEvent& event) private virtual new in Git master
Pointer release event.
void mouseReleaseEvent(MouseEvent& event) deprecated in Git master private virtual
Mouse release event.
void pointerMoveEvent(PointerMoveEvent& event) private virtual new in Git master
Pointer move event.
void mouseMoveEvent(MouseMoveEvent& event) deprecated in Git master private virtual
Mouse move event.
void scrollEvent(ScrollEvent& event) private virtual new in Git master
Scroll event.
void mouseScrollEvent(MouseScrollEvent& event) deprecated in Git master private virtual
Mouse move event.

Text input handling

auto isTextInputActive() const -> bool
Whether text input is active.
void startTextInput()
Start text input.
void stopTextInput()
Stop text input.
void textInputEvent(TextInputEvent& event) private virtual
Text input event.

Special events

void exitEvent(ExitEvent& event) private virtual
Exit event.

Enum documentation

enum class Magnum::Platform::GlfwApplication::Key: Int new in Git master

Key.

Enumerators
Unknown

Unknown key

LeftShift

Left Shift

RightShift

Right Shift

LeftCtrl

Left Ctrl

RightCtrl

Right Ctrl

LeftAlt

Left Alt

RightAlt

Right Alt

LeftSuper

Left Super key (Windows/⌘)

RightSuper

Right Super key (Windows/⌘)

Enter

Enter

Esc

Escape

Up

Up arrow

Down

Down arrow

Left

Left arrow

Right

Right arrow

Home

Home

End

End

PageUp

Page up

PageDown

Page down

Backspace

Backspace

Insert

Insert

Delete

Delete

F1

F1

F2

F2

F3

F3

F4

F4

F5

F5

F6

F6

F7

F7

F8

F8

F9

F9

F10

F10

F11

F11

F12

F12

Space

Space

Tab

Tab

Quote new in 2020.06

Quote (')

Comma

Comma

Period

Period

Minus

Minus

Plus

Plus. On the US keyboard layout this may only be representable as Shift =.

Slash

Slash

Percent

Percent. On the US keyboard layout this may only be representable as Shift 5.

Semicolon

Semicolon (;)

Smicolon

Semicolon (;)

Equal

Equal

LeftBracket new in 2020.06

Left bracket ([)

RightBracket new in 2020.06

Right bracket (])

Backslash new in 2020.06

Backslash (\)

Backquote new in 2020.06

Backquote (`)

World1 new in 2020.06

Non-US #1. Can be for example a backslash (\) next to left Shift.

World2 new in 2020.06

Non-US #2

Zero

Zero

One

One

Two

Two

Three

Three

Four

Four

Five

Five

Six

Six

Seven

Seven

Eight

Eight

Nine

Nine

A

Letter A

B

Letter B

C

Letter C

D

Letter D

E

Letter E

F

Letter F

G

Letter G

H

Letter H

I

Letter I

J

Letter J

K

Letter K

L

Letter L

M

Letter M

N

Letter N

O

Letter O

P

Letter P

Q

Letter Q

R

Letter R

S

Letter S

T

Letter T

U

Letter U

V

Letter V

W

Letter W

X

Letter X

Y

Letter Y

Z

Letter Z

CapsLock

Caps lock

ScrollLock

Scroll lock

NumLock

Num lock

PrintScreen

Print screen

Pause

Pause

Menu

Menu

NumZero

Numpad zero

NumOne

Numpad one

NumTwo

Numpad two

NumThree

Numpad three

NumFour

Numpad four

NumFive

Numpad five

NumSix

Numpad six

NumSeven

Numpad seven

NumEight

Numpad eight

NumNine

Numpad nine

NumDecimal

Numpad decimal

NumDivide

Numpad divide

NumMultiply

Numpad multiply

NumSubtract

Numpad subtract

NumAdd

Numpad add

NumEnter

Numpad enter

NumEqual

Numpad equal

enum class Magnum::Platform::GlfwApplication::Pointer: UnsignedByte new in Git master

Pointer type.

Enumerators
MouseLeft

Left mouse button. Corresponds to GLFW_MOUSE_BUTTON_LEFT or GLFW_MOUSE_BUTTON_1.

MouseMiddle

Middle mouse button. Corresponds to GLFW_MOUSE_BUTTON_MIDDLE or GLFW_MOUSE_BUTTON_2.

MouseRight

Right mouse button. Corresponds to GLFW_MOUSE_BUTTON_RIGHT or GLFW_MOUSE_BUTTON_3.

MouseButton4

Fourth mouse button, such as wheel left. Corresponds to GLFW_MOUSE_BUTTON_4.

MouseButton5

Fifth mouse button, such as wheel right. Corresponds to GLFW_MOUSE_BUTTON_5.

MouseButton6

Sixth mouse button. Corresponds to GLFW_MOUSE_BUTTON_6.

MouseButton7

Seventh mouse button. Corresponds to GLFW_MOUSE_BUTTON_7.

MouseButton8

Eighth mouse button. Corresponds to GLFW_MOUSE_BUTTON_8.

enum class Magnum::Platform::GlfwApplication::Cursor: UnsignedInt new in 2020.06

Cursor type.

Enumerators
Arrow

Arrow

TextInput

Text input

Crosshair

Crosshair

ResizeNWSE

Double arrow pointing northwest and southeast

ResizeNESW

Double arrow pointing northeast and southwest

ResizeWE

Double arrow pointing west and east

ResizeNS

Double arrow pointing north and south

ResizeAll

Four pointed arrow pointing north, south, east, and west

No

Slashed circle or crossbones

Hand

Hand

Hidden

Hidden

HiddenLocked

Hidden and locked

Typedef documentation

typedef Containers::EnumSet<Pointer> Magnum::Platform::GlfwApplication::Pointers new in Git master

Set of pointer types.

Function documentation

Magnum::Platform::GlfwApplication::GlfwApplication(const Arguments& arguments, const Configuration& configuration, const GLConfiguration& glConfiguration) explicit

Construct with an OpenGL context.

Parameters
arguments Application arguments
configuration Application configuration
glConfiguration OpenGL context configuration

Creates application with default or user-specified configuration. See Configuration for more information. The program exits if the context cannot be created, see tryCreate() for an alternative.

Magnum::Platform::GlfwApplication::GlfwApplication(const Arguments& arguments, const Configuration& configuration = Configuration{}) explicit

Construct without explicit GPU context configuration.

If Configuration::WindowFlag::Contextless is present or Magnum was not built with MAGNUM_TARGET_GL, this creates a window without any GPU context attached, leaving that part on the user.

If none of the flags is present and Magnum was built with MAGNUM_TARGET_GL, this is equivalent to calling GlfwApplication(const Arguments&, const Configuration&, const GLConfiguration&) with default-constructed GLConfiguration.

See also Enabling or disabling features for more information.

Magnum::Platform::GlfwApplication::GlfwApplication(const Arguments& arguments, NoCreateT) explicit

Construct without creating a window.

Parameters
arguments Application arguments

Unlike above, the window is not created and must be created later with create() or tryCreate().

Containers::StringView Magnum::Platform::GlfwApplication::keyName(Key key, UnsignedInt scanCode = 0) const new in Git master

Name for given key.

Human-readable localized UTF-8 name for given key, intended for displaying to the user in e.g. a key binding configuration. For Key::Unknown, a concrete scanCode can be passed. If there is no name for given key, an empty string is returned. If non-empty, the returned view is always Containers::StringViewFlag::NullTerminated and is valid until the keyboard layout is changed or the application exits.

Unlike e.g. Sdl2Application::keyName(), the function isn't static because it relies on GLFW being initialized.

Containers::Optional<UnsignedInt> Magnum::Platform::GlfwApplication::keyToScanCode(Key key) const new in Git master

Scan code for given key.

If key doesn't correspond to a physical key supported on given platform, returns Containers::NullOpt. Unlike e.g. Sdl2Application::scanCodeToKey(), GLFW doesn't provide any way to map from a scan code to a key.

Unlike e.g. Sdl2Application::keyToScanCode(), the function isn't static because it relies on GLFW being initialized.

int Magnum::Platform::GlfwApplication::exec()

Execute main loop.

Returns Value for returning from main()

Calls mainLoopIteration() in a loop until exit() is called. See MAGNUM_GLFWAPPLICATION_MAIN() for usage information.

bool Magnum::Platform::GlfwApplication::mainLoopIteration() new in 2020.06

Run one iteration of application main loop.

Returns false if exit() was called and the application should exit, true otherwise

Called internally from exec(). If you want to have better control over how the main loop behaves, you can call this function yourself from your own main() function instead of it being called automatically from exec() / MAGNUM_GLFWAPPLICATION_MAIN().

void Magnum::Platform::GlfwApplication::exit(int exitCode = 0)

Exit application.

Parameters
exitCode The exit code the application should return

When called from application constructor, it will cause the application to exit immediately after constructor ends, without entering the event loop. When called from within an event handler, it will cause it to exit at the start of next event loop iteration. Compared to requesting an application exit using the window close button or the Alt F4 / Cmd Q keyboard shortcut, the exitEvent() isn't called when using this function.

Calling this function from an application constructor is recommended over std::exit() or Fatal, which exit without calling destructors on local scope. Note that, however, you need to explicitly return after calling it, as it can't exit the constructor on its own:

MyApplication::MyApplication(const Arguments& arguments):
    Platform::Application{arguments, NoCreate}
{
    // …

    if(!everythingGoingAsExpected) {
        exit(1);
        return;
    }

    // …
}

GLFWwindow* Magnum::Platform::GlfwApplication::window()

Underlying window handle.

Use in case you need to call GLFW functionality directly.

void Magnum::Platform::GlfwApplication::create(const Configuration& configuration, const GLConfiguration& glConfiguration) protected

Create a window with given configuration for OpenGL context.

Parameters
configuration Application configuration
glConfiguration OpenGL context configuration

Must be called only if the context wasn't created by the constructor itself, i.e. when passing NoCreate to it. Error message is printed and the program exits if the context cannot be created, see tryCreate() for an alternative.

On desktop GL, if version is not specified in glConfiguration, the application first tries to create core context (OpenGL 3.2+) and if that fails, falls back to compatibility OpenGL 2.1 context.

void Magnum::Platform::GlfwApplication::create(const Configuration& configuration) protected

Create a window with given configuration.

If Configuration::WindowFlag::Contextless is present or Magnum was not built with MAGNUM_TARGET_GL, this creates a window without any GPU context attached, leaving that part on the user.

If none of the flags is present and Magnum was built with MAGNUM_TARGET_GL, this is equivalent to calling create(const Configuration&, const GLConfiguration&) with default-constructed GLConfiguration.

See also Enabling or disabling features for more information.

void Magnum::Platform::GlfwApplication::create() protected

Create a window with default configuration and OpenGL context.

Equivalent to calling create(const Configuration&) with default-constructed Configuration.

bool Magnum::Platform::GlfwApplication::tryCreate(const Configuration& configuration, const GLConfiguration& glConfiguration) protected

Try to create context with given configuration for OpenGL context.

Unlike create(const Configuration&, const GLConfiguration&) returns false if the context cannot be created, true otherwise.

bool Magnum::Platform::GlfwApplication::tryCreate(const Configuration& configuration) protected

Try to create context with given configuration.

Unlike create(const Configuration&) returns false if the context cannot be created, true otherwise.

void Magnum::Platform::GlfwApplication::tickEvent() virtual protected new in Git master

Tick event.

If implemented, this function is called periodically after processing all input events and before draw event even though there might be no input events and redraw is not requested. Useful e.g. for asynchronous task polling. Use setMinimalLoopPeriod() / setSwapInterval() to control main loop frequency.

If this implementation gets called from its override, it will effectively stop the tick event from being fired and the app returns back to waiting for input events. This can be used to disable the tick event when not needed.

Vector2i Magnum::Platform::GlfwApplication::windowSize() const

Window size.

Window size to which all input event coordinates can be related. Note that, especially on HiDPI systems, it may be different from framebufferSize(). Expects that a window is already created. See DPI awareness for more information.

void Magnum::Platform::GlfwApplication::setWindowSize(const Vector2i& size) new in 2020.06

Set window size.

Parameters
size The size, in screen coordinates

To make the sizing work independently of the display DPI, size is internally multiplied with dpiScaling() before getting applied. Expects that a window is already created.

void Magnum::Platform::GlfwApplication::setMinWindowSize(const Vector2i& size = {-1, -1}) new in 2019.10

Set window minimum size.

Parameters
size The minimum size, in screen coordinates

If a value is set to -1, it will disable/remove the corresponding limit. To make the sizing work independently of the display DPI, size is internally multiplied with dpiScaling() before getting applied. Expects that a window is already created.

void Magnum::Platform::GlfwApplication::setMaxWindowSize(const Vector2i& size = {-1, -1}) new in 2019.10

Set window maximum size.

Parameters
size The maximum size, in screen coordinates

If a value is set to -1, it will disable/remove the corresponding limit. To make the sizing work independently of the display DPI, size is internally multiplied with dpiScaling() before getting applied. Expects that a window is already created.

Vector2i Magnum::Platform::GlfwApplication::framebufferSize() const

Framebuffer size.

Size of the default framebuffer. Note that, especially on HiDPI systems, it may be different from windowSize(). Expects that a window is already created. See DPI awareness for more information.

Vector2 Magnum::Platform::GlfwApplication::dpiScaling() const

DPI scaling.

How the content should be scaled relative to system defaults for given windowSize(). If a window is not created yet, returns zero vector, use dpiScaling(const Configuration&) for calculating a value independently. See DPI awareness for more information.

Vector2 Magnum::Platform::GlfwApplication::dpiScaling(const Configuration& configuration)

DPI scaling for given configuration.

Calculates DPI scaling that would be used when creating a window with given configuration. Takes into account DPI scaling policy and custom scaling specified on the command-line. See DPI awareness for more information.

void Magnum::Platform::GlfwApplication::setWindowTitle(Containers::StringView title) new in 2019.10

Set window title.

The title is expected to be encoded in UTF-8.

void Magnum::Platform::GlfwApplication::setWindowIcon(Containers::ArrayView<const ImageView2D> images) new in Git master

Set window icon.

The images are expected to be with origin at bottom left (which is the default for imported images) and in one of PixelFormat::RGB8Unorm, PixelFormat::RGB8Srgb, PixelFormat::RGBA8Unorm or PixelFormat::RGBA8Srgb formats. If you have just one image, you can use setWindowIcon(const ImageView2D&) instead.

void Magnum::Platform::GlfwApplication::setWindowIcon(std::initializer_list<ImageView2D> images) new in 2020.06

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::Platform::GlfwApplication::setWindowIcon(const ImageView2D& image) new in 2020.06

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::Platform::GlfwApplication::swapBuffers()

Swap buffers.

Paints currently rendered framebuffer on screen.

void Magnum::Platform::GlfwApplication::setSwapInterval(Int interval)

Set swap interval.

Set 0 for no VSync, 1 for enabled VSync. Some platforms support -1 for late swap tearing. Default is driver-dependent.

void Magnum::Platform::GlfwApplication::setMinimalLoopPeriod(Nanoseconds time) new in Git master

Set minimal loop period.

This setting reduces the main loop frequency in case setSwapInterval() wasn't called at all, was called with 0, or no drawing is done and just tickEvent() is being executed. The time is expected to be non-negative, default is 0_nsec (i.e., looping at maximum frequency). If the application is drawing on the screen and VSync was enabled by calling setSwapInterval(), this setting is ignored.

Note that as the VSync default is driver-dependent, setSwapInterval() has to be explicitly called to make the interaction between the two work correctly.

void Magnum::Platform::GlfwApplication::redraw()

Redraw immediately.

Marks the window for redrawing, resulting in call to drawEvent() in the next iteration. You can call it from drawEvent() itself to redraw immediately without waiting for user input.

void Magnum::Platform::GlfwApplication::viewportEvent(ViewportEvent& event) virtual private

Viewport event.

Called when window size changes. The default implementation does nothing. If you want to respond to size changes, you should pass the new size to GL::DefaultFramebuffer::setViewport() (if using OpenGL) and possibly elsewhere (to SceneGraph::Camera::setViewport(), other framebuffers...).

Note that this function might not get called at all if the window size doesn't change. You should configure the initial state of your cameras, framebuffers etc. in application constructor rather than relying on this function to be called. Size of the window can be retrieved using windowSize(), size of the backing framebuffer via framebufferSize() and DPI scaling using dpiScaling(). See DPI awareness for detailed info about these values.

void Magnum::Platform::GlfwApplication::drawEvent() pure virtual private

Draw event.

Called when the screen is redrawn. You should clean the framebuffer using GL::DefaultFramebuffer::clear() (if using OpenGL) and then add your own drawing functions. After drawing is finished, call swapBuffers(). If you want to draw immediately again, call also redraw().

void Magnum::Platform::GlfwApplication::keyPressEvent(KeyEvent& event) virtual private

Key press event.

Called when a key is pressed. Default implementation does nothing.

void Magnum::Platform::GlfwApplication::keyReleaseEvent(KeyEvent& event) virtual private

Key release event.

Called when a key is released. Default implementation does nothing.

void Magnum::Platform::GlfwApplication::setCursor(Cursor cursor) new in 2020.06

Set cursor type.

Expects that a window is already created. Default is Cursor::Arrow.

void Magnum::Platform::GlfwApplication::pointerPressEvent(PointerEvent& event) virtual private new in Git master

Pointer press event.

Called when a mouse is pressed. Note that if at least one mouse button is already pressed and another button gets pressed in addition, pointerMoveEvent() with the new combination is called, not this function.

On builds with MAGNUM_BUILD_DEPRECATED enabled, default implementation delegates to mousePressEvent(). On builds with deprecated functionality disabled, default implementation does nothing.

void Magnum::Platform::GlfwApplication::mousePressEvent(MouseEvent& event) virtual private

Mouse press event.

Default implementation does nothing.

void Magnum::Platform::GlfwApplication::pointerReleaseEvent(PointerEvent& event) virtual private new in Git master

Pointer release event.

Called when a mouse is released. Note that if multiple mouse buttons are pressed and one of these is released, pointerMoveEvent() with the new combination is called, not this function.

On builds with MAGNUM_BUILD_DEPRECATED enabled, default implementation delegates to mouseReleaseEvent(). On builds with deprecated functionality disabled, default implementation does nothing.

void Magnum::Platform::GlfwApplication::mouseReleaseEvent(MouseEvent& event) virtual private

Mouse release event.

Default implementation does nothing.

void Magnum::Platform::GlfwApplication::pointerMoveEvent(PointerMoveEvent& event) virtual private new in Git master

Pointer move event.

Called when any of the currently pressed pointers is moved or changes its properties. Gets called also if the set of pressed mouse buttons changes.

On builds with MAGNUM_BUILD_DEPRECATED enabled, default implementation delegates to mouseMoveEvent(), or if PointerMoveEvent::pointer() is not Containers::NullOpt, to either mousePressEvent() or mouseReleaseEvent(). On builds with deprecated functionality disabled, default implementation does nothing.

void Magnum::Platform::GlfwApplication::mouseMoveEvent(MouseMoveEvent& event) virtual private

Mouse move event.

Default implementation does nothing.

void Magnum::Platform::GlfwApplication::scrollEvent(ScrollEvent& event) virtual private new in Git master

Scroll event.

Called when a scrolling device is used (mouse wheel or scrolling area on a touchpad).

On builds with MAGNUM_BUILD_DEPRECATED enabled, default implementation delegates to mouseScrollEvent(). On builds with deprecated functionality disabled, default implementation does nothing.

void Magnum::Platform::GlfwApplication::mouseScrollEvent(MouseScrollEvent& event) virtual private

Mouse move event.

Default implementation does nothing.

bool Magnum::Platform::GlfwApplication::isTextInputActive() const

Whether text input is active.

If text input is active, text input events go to textInputEvent().

void Magnum::Platform::GlfwApplication::startTextInput()

Start text input.

Starts text input that will go to textInputEvent().

void Magnum::Platform::GlfwApplication::stopTextInput()

Stop text input.

Stops text input that went to textInputEvent().

void Magnum::Platform::GlfwApplication::textInputEvent(TextInputEvent& event) virtual private

Text input event.

Called when text input is active and the text is being input.

void Magnum::Platform::GlfwApplication::exitEvent(ExitEvent& event) virtual private

Exit event.

If implemented, it allows the application to react to an application exit (for example to save its internal state) and suppress it as well (for example to show a exit confirmation dialog). The default implementation calls ExitEvent::setAccepted() on event, which tells the application that it's safe to exit.