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.
preparations
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.
First steps
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 :
camera:=GLCamera1;
lighting:=false;
- in GLSceneEditor :
cube1.texture.image:= just_some_256x256.bmp // or .jpg
cube1.texture.disabled:=false;
- to the form :
drop a trackbar,50..500, frequency:=50, position:=50; name:=focal;
trackbar.onchange :
GLCamera1.focallength:=focal.position;
Compile,execute - > the texture image zooms until it disappears
next steps
rotate a cube interactively
to the form :
- drop a trackbar,0..360, frequency:=10 ,position:=0; name:=xaxisrot;
trackbar.onchange :
cube1.pitchangle:=xaxisrot.position;
- drop a trackbar,0..360, frequency:=10 ,position:=0; name:=yaxisrot;
trackbar.onchange :
cube1.turnangle:=yaxisrot.position;
- drop a trackbar,0..360, frequency:=10 ,position:=0; name:=zaxisrot;
trackbar.onchange :
cube1.rollangle:=zaxisrot.position;
Compile,execute - > rotation along the local axis
note
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
Results
- with the current camera position( direction = -Z, up = Y),
the coordinate system is :
X to the right
Y up
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.
More
- add a performance monitor
add a TTimer to the form, 1000ms, enabled, ontimer :
Caption:=Format('%.2f FPS', [GLSceneViewer1.FramesPerSecond]);
GLSceneViewer1.ResetPerformanceMonitor;
set GLSceneViewer1.monitor:=true;
that was it.
- add animation
add a TGLCadencer to the form, scene:=GLScene1, onprogress :
cube1.turnangle:=newtime*90;
it turns with 90 degrees per second.
- add lighting
try : cube1.material.frontproperties.texture.texturemode:=bmModulate;
or
remove the texture by cube1.texture.disabled:=true;
GLSceneViewer1.lighting:=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
- add fog
in GLSceneViewer :
set FogEnable:=true;
FogColor:=clrMediumSpringGreen;
FogStart:=0;
FogEd:=20;
FogMode:=fmLinear; // experiment with them
animating the objects
- as seen above, objects can be moved with the GLCadencer :
GLCadencer.scene:=GLScene1,
GLCadencer.onprogress :
cube1.turnangle:=newtime*90;
- or as in the sound demo:
var alpha : Single;
GLSphere.Onprogress :
// Move the red sphere (sound source) along an elliptic path
alpha:=60*DegToRad(newTime);
TSphere(Sender).Position.SetVector(sin(alpha)*2, 0.5, cos(alpha)*5, 1);
adding sound
from the sound demo :
the sphere moves, the sound plays.
There is more to this, we'll cover it later.
selecting objects
according to the pick demo :
here the emission color was used to highlite the selected object.
It may make sense to store the old emission.color
oldcolor:THomogeneousFltVector;
where THomogeneousFltVector is defined in Geometry
Materials
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.
Textures
According to OpenGL, textures have to be 2^N in size. Square or not square, Eg
- 4096x4096
- 2048x2048
- 1024x..
- ..x512
- ..x256
- ..x128
- ..x64
- ..x32
- 16x16
- 1024x64
- 512x128
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
procedure tform1.Formcreate(sender:tobject);
var jpg:TJPEGImage;
begin
jpg:=TJPEGImage(cube1.material.texture.image); // for a texture designtime assigned to cube1
jpg.assign(cube1.material.texture.image);
..
end;