2.4. Custom viewports

A viewport is just a 2D rectangular control that provides a view of 3D world. As said previously, scene manager by default acts as a viewport. But you can also have additional, custom viewports, offering simultaneous different views of the same 3D world. This is done by the TCastleViewport class.

You can have many viewports on the 2D window to observe your 3D world from various cameras. You can make e.g. split-screen games (each view displays different player), 3D modeling programs (where you usually like to see the scene from various angles at once), or just show a view from some special world place (like a security camera).

Your viewports may be placed in any way you like on the screen, they can even be overlapping (one viewport partially obscures another). Each viewport has it's own dimensions, own camera, but they can share the same 3D world (the same scene manager). Each viewport has also it's own rendering methods, so you can derive e.g. a specialized viewport that always shows wireframe view of the 3D world.

The scene manager itself also acts as a viewport, if DefaultViewport is true. This is comfortable for simple programs where one viewport is enough. When DefaultViewport is false, scene manager is merely a container for your 3D world, referenced by custom viewports (TCastleViewport classes).

See the example in engine sources examples/3d_rendering_processing/multiple_viewports.lpr for demo of using custom viewports.

Figure 2.2. Simple scene, viewed from various viewports simultaneously.

Simple scene, viewed from various viewports simultaneously.

Figure 2.3. Interactive scene, with shadows and mirors, viewed from various viewports.

Interactive scene, with shadows and mirors, viewed from various viewports.