MoonWorks-docs/content/Window/_index.md

52 lines
3.0 KiB
Markdown
Raw Normal View History

2021-01-25 05:09:37 +00:00
---
title: "Window"
date: 2021-01-24T20:43:17-08:00
weight: 1
---
2023-04-19 16:53:55 +00:00
Window management in MoonWorks is implemented using the [SDL2](https://www.libsdl.org) library. All window management is handled through the `Window` class. A reference to this class named `MainWindow` is automatically created on startup and can be retrieved from your `Game` subclass.
2021-01-25 05:09:37 +00:00
Your game is assumed to have a window and you must pass a `WindowCreateInfo` struct when creating your `Game`.
2021-01-26 05:06:22 +00:00
- `WindowTitle` is the name of the window that will be displayed in the operating system.
2021-01-25 05:09:37 +00:00
- `WindowWidth` is how wide the window will be.
- `WindowHeight` is how tall the window will be.
- `ScreenMode` determines whether the window will be created in windowed mode, fullscreen, or borderless fullscreen.
`PresentMode` refers to the way that your game's render is presented to the screen.
2023-04-19 16:53:55 +00:00
- `SystemResizable` specifies if the user will be able to resize the window by clicking and dragging the corners.
- `StartMaximized` specifies if the window will open at the maximum desktop resolution.
2021-01-25 05:09:37 +00:00
`PresentMode` has two modes that allow tearing: `Immediate` and `FIFORelaxed`.
`Immediate` means that the presentation system does not wait for vertical refresh to update the screen and presents the image as soon as possible.
`FIFORelaxed` means that the presentation system *usually* waits for vertical refresh to update the screen, but if a vertical refresh period has passed since the last screen update then the presentation system does not wait for a new one.
The two modes that do not allow tearing are Mailbox and FIFO.
`Mailbox` means that the presentation system waits for vertical refresh to update the screen. A queue is used to hold presentation requests, and if the queue is full, then an existing entry is replaced in the queue. This allows for low latency while still preventing tearing. The drawback is that this presentation mode is often not supported on non-Linux systems or older hardware.
`FIFO` means that the presentation system waits for vertical refresh to update the screen, and new requests are appended to the end of a queue. This mode is required to be supported by the device and prevents screen tearing, but the latency may be slightly worse than the alternatives.
2023-04-19 16:53:55 +00:00
You can change the screen mode at runtime with the `SetScreenMode` method:
2021-01-25 05:09:37 +00:00
```cs
2023-04-19 16:53:55 +00:00
Window.SetScreenMode(ScreenMode.Fullscreen);
2021-01-25 05:09:37 +00:00
```
2021-03-17 19:40:36 +00:00
You can change the window size at runtime with the `SetWindowSize` method.
```cs
Window.SetWindowSize(1280, 720);
```
2021-01-25 05:09:37 +00:00
Note that if you change the screen resolution, it is *your* responsibility to manage any graphics state that may need to change as a result of this change.
2023-04-19 16:53:55 +00:00
You may specify a method to be called when the window size changes by calling `RegisterSizeChangeCallback`.
```cs
Window.RegisterSizeChangeCallback(MySizeChangeCallback);
```
MoonWorks does support your application having multiple windows. To create a new Window, you can call the Window class's constructor. To make it renderable you will need to call `ClaimWindow` from the `GraphicsDevice`, which we will get to later.