# Last refactor before CGE 7.0 release: Say hello to TCastleViewport and TCastleWindowBase, say goodbye to TCastleSceneManager and TCastleWindow

**URL:** https://forum.castle-engine.io/t/last-refactor-before-cge-7-0-release-say-hello-to-tcastleviewport-and-tcastlewindowbase-say-goodbye-to-tcastlescenemanager-and-tcastlewindow/112
**Category:** News
**Created:** [December 29, 2019, 12:17am UTC](https://forum.castle-engine.io/t/last-refactor-before-cge-7-0-release-say-hello-to-tcastleviewport-and-tcastlewindowbase-say-goodbye-to-tcastlescenemanager-and-tcastlewindow/112 "2019-12-29T00:17:38Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [December 29, 2019, 12:17am UTC](https://forum.castle-engine.io/t/last-refactor-before-cge-7-0-release-say-hello-to-tcastleviewport-and-tcastlewindowbase-say-goodbye-to-tcastlescenemanager-and-tcastlewindow/112/1 "2019-12-29T00:17:38Z")

</div>

| [![multiple_viewports](https://castle-engine.io/wp/wp-content/uploads/2019/12/multiple_viewports-200x117.png)](https://castle-engine.io/wp/wp-content/uploads/2019/12/multiple_viewports.png "multiple\_viewports") |

This week I finished the last big engine API change before the next release! `TCastleSceneManager` is now deprecated: instead you should use [TCastleViewport](https://castle-engine.io/apidoc-unstable/html/CastleViewport.TCastleViewport.html) to display 3D models. This makes things much simpler, and it allowed me to make `TCastleViewport` defaults much better.

## 1. TCastleViewport

A simplest working source code demonstrating this (it will compile — [get the engine](https://castle-engine.io/) and test it!) looks like this:

```
uses SysUtils,
  CastleWindow, CastleSceneCore, CastleScene, CastleViewport, CastleCameras, CastleVectors;

var  
Window: TCastleWindowBase;  
Viewport: TCastleViewport;  
Scene: TCastleScene;  
begin  
Window := TCastleWindowBase.Create(Application);  
Window.Open;

Viewport := TCastleViewport.Create(Application);  
Viewport.FullSize := true;  
Viewport.AutoCamera := true;  
Viewport.AutoNavigation := true;  
Window.Controls.InsertFront(Viewport);

Scene := TCastleScene.Create(Application);  
Scene.Load(‘data/bridge\_final.x3dv’);

Viewport.Items.Add(Scene);  
Viewport.Items.MainScene := Scene;

Application.Run;  
end.
```

See the [CGE examples: 3d\_rendering\_processing/view\_3d\_model\_basic.lpr](https://github.com/castle-engine/castle-engine/blob/master/examples/3d_rendering_processing/view_3d_model_basic.lpr) for a complete code with some additional comments.

The advantages of the new approach:

1. Previously, [TCastleViewport](https://castle-engine.io/apidoc-unstable/html/CastleViewport.TCastleViewport.html) was in most practical cases reserved for _“secondary viewport”_, that shows something also visible in the _“primary viewport”_. The _“primary viewport”_ was [TCastleSceneManager](https://castle-engine.io/apidoc-unstable/html/CastleViewport.TCastleSceneManager.html) with `DefaultViewport = true`. This entire complication (and complication of terminology – _“how is scene manager different from viewport”_) no longer exists.

2. Moreover, this allowed me to minimize compatibility break while still changing some defaults. Since `TCastleViewport` was so seldom used, we change it’s default properties:

## 2. TCastleWindowBase, TCastleControlBase

Also [TCastleWindow](https://castle-engine.io/apidoc-unstable/html/CastleWindow.TCastleWindow.html) and [TCastleControl](https://castle-engine.io/apidoc-unstable/html/CastleControl.TCastleControl.html) are deprecated, in favour of their “Base” counterparts: [TCastleWindowBase](https://castle-engine.io/apidoc-unstable/html/CastleWindow.TCastleWindowBase.html) and [TCastleControlBase](https://castle-engine.io/apidoc-unstable/html/CastleControl.TCastleControlBase.html). Why:

- This way you don’t have a default viewport (scene manager) instance, which avoids some traps (the default navigation may catch some keys), and it is often not necessary.
- This way you create the [TCastleViewport](https://castle-engine.io/apidoc-unstable/html/CastleViewport.TCastleViewport.html) yourself, as many as you need. So you have more power over the engine. This way it is clear that [TCastleViewport](https://castle-engine.io/apidoc-unstable/html/CastleViewport.TCastleViewport.html) is just a regular user-interface class: you can create it as many times as needed, you can position and resize it however you like.

- This way you can create and adjust the [TCastleViewport](https://castle-engine.io/apidoc-unstable/html/CastleViewport.TCastleViewport.html) using [CGE editor](https://castle-engine.io/manual_editor.php), just like any other UI control.

Many parts of the [manual](https://castle-engine.io/manual_intro.php) and [examples](https://github.com/castle-engine/castle-engine/tree/master/examples) have been updated to show “the new approach”. I’m working to finish updating the manual now.

---

_[View the full topic](https://forum.castle-engine.io/t/last-refactor-before-cge-7-0-release-say-hello-to-tcastleviewport-and-tcastlewindowbase-say-goodbye-to-tcastlescenemanager-and-tcastlewindow/112)._
