Learning from GLScene Samples

See the preceding page for the set-up of GLScene in Lazarus. There are a large number of samples, many with copious notes from which you can learn the capabilities of GLScene. A table of comments on specific examples (tested with both 64-bit and 32-bit Lazarus) follows these points of general advice.

  1. View the .lpi file of the sample and remove any spaces before the names of the required packages. (You must be able to see GLSceneLCL_RunTime as a required package in the Property Inspector before compiling). Change any of the remaining old names such as GLS_WinOnly to the corresponding new names such as GLSceneLCL_WinOnly.
  2. Accept any invitations to continue when loading.
  3. When executing the application, you may receive an error message that WGL_ARB_pbuffer support is required. Check the box with caption Ignore this exception type and press the button to continue.
Name Category Notes
actor meshes A great sample to start with. Thoroughly commented code and not too daunting. Animations selectable from combo box: stand, run, attack, pain, jump, flip, salute, taunt, wave, point, death (some available while crouching).
ducky meshes Duck is composed of NURBS surfaces. You can view as wire frame and can change the resolution so that at low resolution it looks angular. Take a look at duck1.nurbs, duck2.nurbs and duck3.nurbs in a text editor. Rotate the duck with the mouse to view it at different angles.
bendingcyl extrusion The TGLPipe object extrudes a circle along a trajectory. When you check the splines box the pipe bends realistically as the object's SplineMode becomes lsmCubicSpline. Find the pipe in the Advanced geometry submenu of the Add object menu of the GLScene Editor.
customquad materials Very effective demo of supplying your own texture coordinates and vertices for images.
multimaterial materials Effective demonstration when debugged. Line of code with corrected filename: with AddTextureMaterial('specular', 'GLScene_alpha.bmp') do
mirror materials Works well. To add a mirror to your own program, find it in the Special objects submenu of the Add Object menu in the GLScene Editor
procedural materials Uses unit GLProcTextures instead of an image to display clouds.
cubemap materials Your graphics hardware must support cube maps.
dyncubemap materials Your graphics hardware must support cube maps.
caterpillar sprites Worked when we copied Flare1.bmp from Samples\media to the project folder. The comment introducing the program states that the file is "expected to be in the same directory as the compiled EXE".
pong movements Impressive graphics in a version that is very easy to play. Change relevant the PackageName in Pong.lpi to GLSceneLCL_WinOnly. Accept two invitations to continue without loading a component class. Change line 74 to MakeVector(ballVector, 15 * cos(angle), 15 * sin(angle), 0); for a more challenging game to play.
events movements Uses timer events to rotate three "cubes" that have a Y scale of 5.
manual movements Moves a "moon" and "earth" around a rotating "sun" using a cadencer to perform the animation as fast as possible.
SmoothNavigator movements "A demo that shows what all classes inside the GLSmoothNavigator.pas unit are capable of." Works impressively with mouse, but WASD keys did not work for us.
boxedin collisions A stunning demo dating back to 2002 of a sphere colliding with surrounding walls and different shapes of object.
RayBox collisions Emits a sound when box hit by ray and outputs the point of intersection. Sometimes the ray appears to collide, but if you rotate the box and ray with the mouse you can see that the ray misses. If you un-check the Change pos scale box the original box properties will be used, otherwise they are changed randomly.
SphereBoxIntersectDemo collisions Press Random Box Rotation button. If there is no intersection it emits a sound and if there is the bottom label shows "Intersected". Sometimes there appears to be an intersection, but if you rotate the box and sphere with the mouse you can see a gap between them. Uses function IntersectSphereBox in unit GLVectorGeometry.
torque behaviours Illustrates how to apply torque and different ways of achieving rotational damping.
projection graph The demo comprises a plane and randomly generated points, which are rendered directly with regular scene objects. The projection points on the plane are computed using a ParallelProjectionMatrix and lines between the points and the plane are rendered on the fly in a TGLDirectOpenGL.
canvas bench The bench folder contains several programs for testing performance. In canvas, the GLCanvas is shown to be considerably faster than the TCanvas used in a PaintBox control for 20000 lines, ellipses, rectangles and test messages and for 200000 points.

The following page describes the Newton physics samples, which are more difficult to set up.

Programming - a skill for life!

How to set-up and use GLScene in Lazarus