@ -47,10 +47,9 @@ Windowed applications provide a window and keyboard and mouse handling. The
most basic toolkit (and toolkit packaged for most systems) is GLUT, which is
most basic toolkit (and toolkit packaged for most systems) is GLUT, which is
implemented in @ref Platform::GlutApplication. As said above, the usage is
implemented in @ref Platform::GlutApplication. As said above, the usage is
similar for all toolkits, you must provide one-argument constructor and
similar for all toolkits, you must provide one-argument constructor and
implement at least @ref GlutApplication::viewportEvent() "viewportEvent()" and
implement at least @ref GlutApplication::drawEvent() "drawEvent()" function.
@ref GlutApplication::drawEvent() "drawEvent()". The class can be then used
The class can be then used directly in `main()`, but for convenience and
directly in `main()`, but for convenience and portability it's better to use
portability it's better to use @ref MAGNUM_GLUTAPPLICATION_MAIN() macro.
@ref MAGNUM_GLUTAPPLICATION_MAIN() macro.
To simplify the porting, the library provides `Platform::Application` typedef
To simplify the porting, the library provides `Platform::Application` typedef
and `MAGNUM_APPLICATION_MAIN()` macro (but only if only one application header
and `MAGNUM_APPLICATION_MAIN()` macro (but only if only one application header
@ -78,7 +77,6 @@ class MyApplication: public Platform::Application {
MyApplication(const Arguments& arguments);
MyApplication(const Arguments& arguments);
private:
private:
void viewportEvent(const Vector2i& viewport) override;
void drawEvent() override;
void drawEvent() override;
};
};
@ -87,11 +85,6 @@ MyApplication::MyApplication(const Arguments& arguments): Platform::Application(
Renderer::setClearColor({0.0f, 0.0f, 0.4f});
Renderer::setClearColor({0.0f, 0.0f, 0.4f});
}
}
void MyApplication::viewportEvent(const Vector2i& size) {
// Resize the framebuffer to new window size
defaultFramebuffer.setViewport({{}, size});
}
void MyApplication::drawEvent() {
void MyApplication::drawEvent() {
// Clear the window
// Clear the window
defaultFramebuffer.clear(DefaultFramebuffer::Clear::Color);
defaultFramebuffer.clear(DefaultFramebuffer::Clear::Color);
@ -104,6 +97,28 @@ void MyApplication::drawEvent() {
MAGNUM_APPLICATION_MAIN(MyApplication)
MAGNUM_APPLICATION_MAIN(MyApplication)
@endcode
@endcode
@subsection platform-windowed-viewport Responding to viewport size changes
By default the application doesn't respond to window size changes in any way,
as the window has fixed size in most cases. To respond to size change for
example by resizing the default framebuffer, you need to reimplement
@ref GlutApplication::viewportEvent() "viewportEvent()" function and pass the
new size to the framebuffer:
@code
class MyApplication: public Platform::Application {
// ...
private:
void viewportEvent(const Vector2i& size) override;
};
// ...
void MyApplication::viewportEvent(const Vector2i& size) {
defaultFramebuffer.setViewport({{}, size});
}
@endcode
@section platform-windowless Windowless applications
@section platform-windowless Windowless applications
Windowless applications provide just a context for ofscreen rendering or
Windowless applications provide just a context for ofscreen rendering or