In the
previous topic you build a GLScene application but so far you could not see any results. Why can’t you see the cube? Well in order for you to see anything at all you will need to create a way to view the scene. This is done using a camera. We are now going to add a camera to the scene.
Need to know
The scene editor doesn’t always know where you click on. A work around is to select any other node in the editor and then select the node you want. Only then will the object inspector (F10) and the context popup menu be correct.
- Left click on
"Scene objects" to make that option active
- Left click on
"Cameras" to make that option active
This weird toggle action will sort out the Scene editor if it get’s confused. Use this trick whenever the object inspector or context menu fails to show the correct information.
- Open the scene editor again. Right click on the TGLScene
icon on the form and select “Show scene editor”
- Right click on
“Cameras” and select “Add camera”

You now have a camera but don’t bother to go and check out your creation on the form. There is still nothing there!
Need to know
Every new object that is created is always placed in the center of the scene by default.
So you can see that the camera occupies the same space as the cube. Besides the camera points at some default direction and chances are that it is not pointing to the cube anyway.
Well that is easy to fix. We are going to tell the camera to look at the cube
- Select
GLCamera1 and press F10 to bring up the object inspector.
In the object inspector you will see the camera properties.
- Set the “TargetObject” to GLCube1

From now on the camera will always point at GLCube no matter where the Cube or camera is located.
Still the GLSceneViewer won’t show anything. The main reason for this is that the viewer has not yet been told for which camera it should display a view. In GLScene you can have multiple camera’s and you can switch your view from one camera to another.
- Close the Scene editor
- Select the TGLSceneviewer control
- Press F10 to bring up the object inspector
One of the properties of a tGLSceneViewer is the Camera property. This property defines wich camera should be used to render the 3D view for the viewer.
- Set the “Camera” property to GLCamera1

Still nothing to see. Let’s summarize what we have done and see if we can identify what we have missed.
- We created a cube and a camera.
- We told the camera to look at the cube.
- We told the viewer to use camera1.
- However, we never told the camera and cube where to go!
The camera is located in exactly the same spot as the cube so basically were too close to see anything at all. For now let’s just get this thing working. After that we need to spend some time to talk about 3D coordinates.
- Right click on the TGLScene
icon on the form and select “Show scene editor”
- Select
GLCamera1 and press F10 to bring up the object inspector.
- Set the position coordinates to X=1, Y=1 and Z=1

Finally, something appears on the screen. It looks pretty bad but at least it’s something right?

What you see is the silhouette of a 3D cube as seen from an angle. It is all black because… There are no lights! Every scene needs lights. Without lights you can’t see anything. So let’s add a light.
- Right click on the TGLScene
icon on the form and select “Show scene editor”
- Right click on
“Scene Objects” and select a “Lightsource”

Nothing changed. The new light is added to the center of the scene and in our case the light would end up in the inside of the cube. We need to move the light up to get it out of the cube.
- Select the new light in the scene editor and press F10 to bring up the object inspector.
- Change the position of the light as shown below.

And finally the cube is shown in all it’s glory.

Congratulations you have mastered the very basics of GLScene. We have created an application containing a TGLScene

and a TGLSceneViewer

We have added a cube, a camera and a light. We told the viewer to use our new camera. We made the camera look at the cube and placed the camera away from the cube so it can look at it. We added a light and placed it above the cube and presto we are done! So the minimum requirements in order for you to see anything in GLScene are:
- TGLScene component (The scene master object)
- TGLSceneViewer (To see stuff)
- TGLCamera (were to see stuff from)
- TGLLight (So we can see stuff)
- TGLCube (Stuff to see)
Obviously these objects need to be configured in such a way that the camera can actually see the cube and the light can shine on the outside of the cube.
Although we have achieved to display a 3D object in Delphi, we need to be able to manipulate the object in 3D space. Gain control so to speak. Save this project and name it "glscenebase.dpr" or something. You will find that it will come in handy every time you want to try something. Also you will need this project for the next tutorial. The
Control Objects tutorial will teach you how to control objects in space.