glScen - Quick Start
|Top Previous Next|
GLScene quickstart guide
It is assumed that you did run the demos. As it is a big package, which requires some digging into, one can become lost quite quick. The purpose of this page summarizes a few points of GLScene. It is designed to enable you do the first steps with out going into the source.
GLScene is installed and available as components.
Version 073 of GLScene has a little bug that surfaces when installing the FMOD. The build options of GLScene and FMod were different. The solution is : at installation of the FMod, change the build options of both packages to never rebuild. This will be changed in the next version.
FMod is installed and available as components.
A textured cube, the camera can be zoomed in interactively.
Get a new application with a form
Drop GLScene onto the form
Drop GLSceneViewer, align:=alnone, backgroundcolor:=clbtnface
Doubleclick GLScene, GLSceneEditor appears as separate form
in GLSceneEditor :
add a camera (GLCamera1), position.Z:=10
add a cube(Cube1), showaxes:=true;
in the SceneViewer :
in GLSceneEditor :
cube1.texture.image:= just_some_256x256.bmp // or .jpg
to the form :
drop a trackbar,50..500, frequency:=50, position:=50; name:=focal;
Compile,execute - > the texture image zooms until it disappears
rotate a cube interactively
to the form :
drop a trackbar,0..360, frequency:=10 ,position:=0; name:=xaxisrot;
drop a trackbar,0..360, frequency:=10 ,position:=0; name:=yaxisrot;
drop a trackbar,0..360, frequency:=10 ,position:=0; name:=zaxisrot;
Compile,execute - > rotation along the local axis
Though Eric didn't test this feature, it certainly is worth a note :
Cube1.TransformationMode:=tmParentNoPos makes the rotations relative to the fixed coordinate system.
Please report, if you find a bug
with the current camera position( direction = -Z, up = Y),
the coordinate system is :
X to the right
Z out of the screen
The coordiante system is righthanded, meaning : with your right hand:
if the thumb points to X, and the index finger points to Y, then the middle finger points to Z, right angles assumed
Yes, rotations are measured in degrees, the underlying OpenGL does it this way.
the GLSceneEditor(double click on the Scene) gives information about the OpenGL driver :
the manufacturer, buffer and pixel depths, limitations, and supported extensions by clicking on the '?'
There is a connection between point of view, near plane, far plane (frustrum) and the camera.focallength. The current implementation lets the object disappear when zooming in too close. glOrtho, the 'infinite projection' is currently not implemented.
with some tries
the translation of the cube works the same way by setting the cube's position property.
the cube's scale and cubedepth/cubeheight/cubewidth do the same, at least with just one cube. Scaling affects children if there are any. depht/width/heigth is the dimnsion.
A texture on a cube/cone/disk/cylinder is painted right, on a
- sphere it is painted upside down in version 073, it is fixed for later versions
- torus/teapot it is somewhat strange, as it is uv mapped to xy
- dodecahedron it is not painted at all
textures added during designtime slow the system down. A truecolor texture (bmp) with a size of 2048^2 took half an hour to compile. Either use jpg images or load them later.
add a performance monitor
add a TTimer to the form, 1000ms, enabled, ontimer :
Caption:=Format('%.2f FPS', [GLSceneViewer1.FramesPerSecond]);
that was it.
add a TGLCadencer to the form, scene:=GLScene1, onprogress :
it turns with 90 degrees per second.
try : cube1.material.frontproperties.texture.texturemode:=bmModulate;
remove the texture by cube1.texture.disabled:=true;
from GLSceneEdit :
add a GLLightSource, diffuse:=clrWhite, position:=(5,5,5)
as white light on a black body leaves black :
cube1.material.frontproperties.diffuse:=clrwhite; // or whatever except black
generally, the surface properties have be adapted for the light.
a black surface doesn't reflect a color, wherever it may come from
the material.frontproperties.ambient shouldn't be black for ambient light
the material.frontproperties.specular shouldn't be black for specular light
in GLSceneViewer :
FogMode:=fmLinear; // experiment with them
animating the objects
as seen above, objects can be moved with the GLCadencer :
or as in the sound demo:
var alpha : Single;
// Move the red sphere (sound source) along an elliptic path
TSphere(Sender).Position.SetVector(sin(alpha)*2, 0.5, cos(alpha)*5, 1);
from the sound demo :
add a soundlibrary with a sound *.wav
add an FMod
GLSFMOD.Listener:=_an_object; // here the mickey
GLSFMOD.Pause:=false; // it plays now
GLSFMOD.updatefrequency:=10; // the soundprocessor is updated with new position information
the sphere moves, the sound plays. There is more to this, we'll cover it later.
according to the pick demo :
attach a mousemove event to the GLSceneViewer
VAR pick : TGLCustomSceneObject; // local
VAR oldpick : TGLCustomSceneObject; //global
pick:=(GLSceneViewer1.GetPickedObject(x, y) as TGLCustomSceneObject);
if (pick<>oldpick) then begin
if assigned(oldpick) then oldpick.material.frontproperties.emission.color:=clrblack;
if assigned(pick) then
here the emission color was used to highlite the selected object.
It may make sense to store the old emission.color
where THomogeneousFltVector is defined in Geometry
A GLMaterialLibrary can hold some materials, textures. Their application is straightforward.
Somehow, containing a few textures, even if they are not used, the compile time of the project increases significantly. The are part of the DFM file and compiled as such. Replace BMP with JPG.
According to OpenGL, textures have to be 2^N in size. Square or not square, Eg
Just any combination of the 2^N numbers. The GLSceneEditor has an Info button, that shows the maximumvalues of the texture size. Textures bigger than the screen may not work on standard graphic cards.
GLScene allows texture maps of odd dimensions, it resizes them internally and clamps them to the limit that the OpenGL driver allows. the size of the texture has no influence on the texture coordinates, the texture is seen as 1.0 x 1.0 square in OpenGL.
jpeg textures have to be 'activated' :
USES ......,JPEG; // include the jpeg library
jpg:=TJPEGImage(cube1.material.texture.image); // for a texture designtime assigned to cube1