Multiple viewports to display one world

Multiple Viewports example
view3dscene with 4 viewports

1. Introduction

It is possible to have multiple viewports visible at the same time. As TCastleViewport is a regular user interface control, you can add as many viewports as you like on a particular TUIState. And you can configure the size and position of each viewport.

These viewports may even display the same world (but from different cameras). This feature is very useful for split-screen games. Or if you want to show additional view of the world (e.g. from the camera attached to a missile, or from camera observing the world from the top).

2. Usage

To use this feature, just set the Items property of one viewport to Items from another viewport. Like

Viewport1.Items := Viewport2.Items;

Note that you cannot (yet) do this from the CGE editor. In the editor you can set multiple viewports, and their cameras, but you cannot yet make them share the same items.

3. Examples

4. Cameras

When sharing Items across multiple viewports: All the cameras (from all the viewports) should also be added to the same Items (TCastleRootTransform). You always want to keep the connection that "the camera used by viewport, set in Viewport.Camera, is also part of the Viewport.Items ".

To improve this documentation just edit the source of this page in AsciiDoctor (simple wiki-like syntax) and create a pull request to Castle Game Engine WWW (cge-www) repository.