OpenGL Library for Delphi,
maintained by Eric Grange,
based on Mike Lischke's GLScene.

 

User Tutorials - Build a basic scene - Make it all work


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.

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.
 

 
image
 
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

In the object inspector you will see the camera properties.
image
 
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.


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.

image
 


Still nothing to see. Let’s summarize what we have done and see if we can identify what we have missed.


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.


image
 

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


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.

image
 

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.
image
 

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

Congratulations you have mastered the very basics of GLScene. We have created an application containing a TGLScene image and a TGLSceneViewer image 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:


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.
 
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.2
Page was generated in 0.1348 seconds