Making Games with GLScene in Lazarus on Windows

Version 1.4 of GLScene was available for download at the end of 2015. (This home page shows only updates to 2011). The instructions below are for the set-up of GLScene on Lazarus and for a simple sample program. We based the brief instructions for the program on the introductory pages, which, although still useful, include some instructions that no longer apply. We used a freshly installed 64-bit Lazarus v1.6 for our initial work, then encountered many problems with samples in the physics section. We repeated the installation with 32-bit Lazarus v1.6 and successfully repeated all the steps below in a few minutes. It is very quick when you know what you are doing!

With the camera at the convenient coordinate X = 0, Y = 3 and Z = 15:
  • X increases to the right;
  • Y increases up the screen;
  • Z increases towards you (in front of the screen).

It is easier to use GLScene if you have already used Box2D; objects are positioned by their centres.

See the following pages for notes on some of the many supplied samples and for instructions on the use of joints.

  1. Download the 18.7MB Lazarus version, GLScene_v1.4_for_Lazarus.7z (modified 2016-01-12).
  2. Use 7-Zip to unzip the contents to a convenient directory. (We use a folder within c:\lazarus\components).
  3. Copy the .dll files in the GLSceneLCL\external folder to the C:\Windows\System32 folder so that you do not need them in the project folder.
  4. Start a new form-based application in Lazarus. Save all, saving the project as FirstGLScene and the unit as uFirstGLScene.
  5. Select menu item Package > Open Package File (.lpk)..., navigate to the GLScene Packages folder and then select the package GLSceneLCL_RunTime. Click on the Compile icon and view the Messages window.
    The new facility Window > Center a lost window may be useful if the messages window is hidden. Selecting menu item View > Messages is an alternative method for bringing the window to the top.
    You should see a success message.
  6. Select menu item Project > Project Inspector... and add GLSceneLCL_RunTime as a new requirement.
  7. Compile the other packages (except for GLSceneLCL_SDL, which is stated to introduce conflicts). The order we used was GLSceneLCL_DesignTime, GLSceneLCL_WinOnly, GLSceneLCL_OpenAL, GLSceneLCL_ODE, GLSceneLCL_NGD, GLSceneLCL_FMOD, GLSceneLCL_CgShader (which all compiled successfully) and GLSceneLCL_BASS (which gave this error when compiled with 64-bit Lazarus):
    GLSMBASS.pas(146,91) Error: Incompatible types: got "Pointer" expected "QWord"
    Thanks to Suny Dev for pointing out that GLSMBASS.pas (in the Source folder) will compile if you remove Pointer from line 146 so that it reads
    if not BASS_Init(1, OutputFrequency, BASS_DEVICE_3D, (TWinControl(Owner).Handle), nil) then
    You should now be able to compile and run many of the supplied examples, as detailed on the following page, but you do not yet have the visual components to drop onto a form.
  8. Select menu item Package > Install/Uninstall Packages..., select GLSceneLCL_DesignTime then press the buttons Install selection and Save and rebuild IDE. Accept the invitation to continue.
    Lazarus should reopen with the component tabs GLScene, GLScene PFX, GLScene Utils, GLScene Terrain and GLScene Shaders.
  9. Add to the form the first two components on the GLScene tab (a GLScene and a GLSceneViewer).
  10. Drag the bottom right corner of the GLSceneViewer to give the scene a reasonable size.
  11. Double click on the GLScene1 icon to obtain the GLScene Editor. Click on Scene objects then on the top right icon to add a camera. Click on Scene objects again to add a Sphere (Basic geometry). Finally, add a light source to Scene objects.
    The Scene Editor should look like this.
    GLScene Editor

    GLScene Editor

  12. Use the Object Inspector to change the Z-coordinate of the camera's position to 8, the x, y, and z coordinates of the light source to -10, 5 and 2, respectively.
  13. Add a .bmp or .jpg image from the Samples\media folder to the sphere by clicking on (1) the ellipsis of the Material property the get the Material Editor, then (2) on the Texture tab, (3) on the ellipsis of the image, (4) on the selected image and (5) on the Open button.
    The image mur_NormalMap.bmp shows up well.
  14. Clear the Disabled check box and select Sphere from the left combo box for the Material Preview. Click the OK button.
  15. Using the Object Inspector, set the TextureMode property of the sphere's texture to tmModulate (so that it is affected by the light) and the Camera property of GLSceneViewer1 to GLCamera1.
  16. Double click in the OnKeyDown event edit box to create FormKeyDown procedure and copy this code into it.
      case Key of
        37: GLSphere1.Position.X := GLSphere1.Position.X - 0.1;
        39: GLSphere1.Position.X := GLSphere1.Position.X + 0.1;
    
        38: GLSphere1.Position.Y := GLSphere1.Position.Y + 0.1;
        40: GLSphere1.Position.Y := GLSphere1.Position.Y - 0.1;
    
        107: GLSphere1.Position.Z := GLSphere1.Position.Z + 0.1;
        109: GLSphere1.Position.Z := GLSphere1.Position.Z - 0.1;
      end;          
    
    
  17. Execute the program and use the arrow, + and - keys to move the sphere.
    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.
Programming - a skill for life!

Using SDL, Box2D or the GLScene or Castle Game Engine to write games in Pascal