Page 7/36
Hello world ! example
Many programming guides contain the obligatory Hello world ! example. It is usually
simple application where user presses button and message window saying Hello world ! appears.
This is necessary for readers that cant wait to start with something in practice. In my opinion the
equivalent to this in 3D graphics programming is a spinning cube.
So here is step by step guide how to create spinning cube in GLScene:
1. Start new application in Delphi.
2. Double click on GLScene to add GLScene1 white cube on GLScene tab first from left.
3. Double click on GLSceneViewer to add GLSceneViewer1 white cube with camera on GLScene
tab second from left.
4. Select alClient as Align property for GLSceneViewer1.
5. Double click on GLCadencer to add GLCadencer1 metronome on GLScene tab fifth from left.
6. Select GLScene1 as Scene property of GLCadencer1.
7. Double click on GLScene1 in object tree view to open GLScene editor.
8. Right click on Cameras in GLScene editor and click on Add camera.
9. Select Camera1 and set Position.X := 5; Position.Y := 5; Position.Z := 5; to move the camera
back so it can overlook the scene.
10.Right click on Scene objects in GLScene editor and select Add object then LightSource.
11.Select GLLightSource1 and set Position.Z := 10 to move the light up so it can shine on the cube
from above.
12.Right click on Scene objects in GLScene editor and select Add object then Basic geometry then
Cube.
13.Select Camera1 and set GLCube1 as Target property to make the camera look at the cube.
14.Select GLSceneViewer1 and select GLCamera1 as Camera property.
15.Double click on GLCube1 in object tree view to add progress event on the form.
16.Write GLCube1.TurnAngle := GLCube1.TurnAngle + deltaTime * 100; this will make the cube
spin around Z axis.
17.Press F9 and see your first spinning cube!
One might say that a spinning cube is a trivial thing. It indeed is with GLScene but lets
reconsider what it takes to draw a spinning cube on modern hardware and operating system. First
GLScene itself has good few thousands of lines of code. Not all of it is used to render a cube of
course. Then we have OpenGL with all the possible drivers. And in the end there is the operating
system on top of all that. So you can see there was a lot of work and effort done by other people so
you can make your spinning cube.
GLScene beginner's guide, Jan Zizka, 2005