Linux fully supported with Delphi

Posted on

play_animation demo with Castle Game Engine on Delphi/Linux
TCastleControl on FMX form with Castle Game Engine on Delphi/Linux
Downloads with Castle Game Engine on Delphi/Linux
Automatic Castle Game Engine tests on Delphi/Linux

We are proud to announce that Castle Game Engine supports now the Linux platform with the Delphi compiler! You can now deploy your Delphi games to Windows and Linux with the same code-base.

This blog post describes various details, but really the recap is short: it just works and we have extensive documentation about Delphi + Linux specific things. Go ahead, download the latest CGE and try it out 🙂

Details about what happened:

  1. Well, 410 commits happened 🙂 And I initially thought this (making CGE work with Delphi/Linux) will take me a few hours to do. Then I thought it will take me a few days. It ended up taking me almost 4 months (although I was doing many other CGE tasks in parallel to this). Let this be a lesson of humility for all devs who dare make optimistic estimates!

  2. Both TCastleWindow and TCastleControl applications work perfectly with Delphi for Linux.

  3. All TCastleWindow examples work on Delphi/Linux. Explore the examples in CGE examples/ subdirectory and build and run on Linux with Delphi.

    All TCastleControl examples using FMX (FireMonkey) work on Delphi/Linux. This includes examples/delphi/fmx/, examples/delphi/fmx_play_animation/.

    examples/delphi/fmx_play_animation/ is actually a new example. Cross-platform 3D model viewer and animation player using Castle Game Engine components (TCastleControl, TCastleScene) and FireMonkey.

  4. The page about TCastleControl in FMX applications stays up-to-date and relevant for Delphi/Linux.

  5. Downloads (web requests) using TCastleDownload work too on Delphi/Linux. You can test them by

    Our code using TNetHttpClient on Delphi was much improved. It supports now various HTTP methods (including POST with POST form data). The code for aborting downloads in progress was also improved to behave cleanly and not cause crashes.

    It also got some Linux-specific fixes to work around Delphi issues. In particular, we handle redirects manually on that platform, as we cannot rely on TNetHttpClient.HandleRedirects on Linux.

    All in all, it was quite non-trivial to make it always work, but now it does 🙂 It can be interrupted, it can send GET and POST and others, it can redirect, it can download files of unknown size, it can download URL like http://castle-engine.io/latest.zip.

  6. Under the hood, the TCastleWindow and TCastleControl for Delphi on non-Windows are actually shared more than in FPC: they both rely on a common TFmxOpenGLUtility class responsible for some platform-specific work, in particular to initialize OpenGL context inside an FMX window.

    Moreover, under the hood, TCastleWindow relies on CASTLE_WINDOW_FORM which is a new name for a generalized old CASTLE_WINDOW_LCL. It makes TCastleWindow actually use FMX and the above-mentioned TFmxOpenGLUtility.

  7. This makes our code much more cross-platform in case of Delphi. Doing Delphi/Android or Delphi/iOS after this should be a breeze. But I’m not going to do any estimates, in light of the first point on this list 🙂

  8. All 407 automatic tests, exercising some edge-cases (also with window sizes and multiple contexts) pass on Delphi/Linux. You can run them yourself, just compile and run the project in tests/ just like any other CGE project.

  9. Underneath, the code to initialize contexts got some upgrades. The glX and EGL context management has been refactored to separate units and extending them is easier.

    EGL initialization has been separated from OpenGLES.

    Finally, we can use EGL (on any platform) to initialize both OpenGL and OpenGLES. Our Delphi/Linux port relies on it: both TCastleWindow and TCastleControl underneath use

    • a window created by FMXLinux,
    • with a GTK3 widget,
    • with OpenGL(ES) context initialized using EGL.
  10. Our file filters are easier exposed for Delphi: TFileFilterList has now methods TFileFilterList.LclFmxFilters, TFileFilterList.LclFmxFiltersFromString (suitable for both LCL and FMX) and we have CastleFmxUtils unit with utilities to place CGE filtes in FMX open/save dialogs.

  11. Our package checking application was much extended and it now checks also Delphi packages for correctness.

    This makes it easier to design good packages for Delphi — that include 100% of units, and that are disjoint where they should.

    This also means we can change the files included in packages with confidence. Both DPK and DPROJ of packages are checked, and we make sure they include all files they should (scanning actual CGE files), with proper relative paths, and nothing more.

    If you’re interested in code, see our check_packages utility code. While it’s an internal CGE tool, it is possible it could be useful for other projects as well. The tool can be compiled with both FPC and Delphi (and regardless of the compiler, it can check both Lazarus and Delphi packages). See the README for instructions how to adjust it for your own purposes.

  12. Simple shell tests (mostly some grep calls) in cge_shell_tests also check now that Delphi packages are correct, in particular that VCL or FMX dependencies don’t happen in packages where they shouldn’t.

Note: Embarcadero had a server outage recently. Everything should be back online for users with Delphi 12 or Delphi 11.3. See Embarcadero blog, GetIt Update for Delphi 12, GetIt Update for Delphi 11.3. If you experience problems using GetIt to get FMXLinux, please consult the above articles.

Start the discussion at Castle Game Engine Forum