DSDrive – a new racing game made in Castle Game Engine

Posted on

1
2
3
4
5
6
7
8

We’re proud to present DSDrive, a simple racing game developed by DidiSoft entirely with Castle Game Engine and Lazarus (and Blender and LazPaint). It is a car race game against 10 opponents and/or time on three different racetracks. In the box you can change the tires, refuel, adjust the brakes and adjust the wing angle. There are three different types of weather. Different views are possible.

You can download the game and the source code from the itch.io page .

All feedback is most welcome on the related forum thread!

Comments on the forum (3) ➤

Render 3D and 2D games inside Delphi VCL and FMX forms using TCastleControl

Posted on

Castle Game Engine 3D in Delphi FMX form
Castle Game Engine 2D animation in Delphi VCL form
Castle Game Engine 3D in Delphi VCL form
Castle Game Engine 3D in Delphi FMX form
Castle Game Engine UI in Delphi FMX form
Castle Game Engine UI in Delphi VCL form

We announced this feature already some time ago and you can watch my presentation from Embarcadero CodeRage 2022 about it. A lot of polishing work happened since then, so it’s time to announce it officially:

Castle Game Engine now offers a TCastleControl component that you can install in Delphi IDE and drop on a VCL or FMX form. It allows you to load any 3D or 2D object hierarchy (designed in CGE editor or just instantiated by code) and render it inside a Delphi form. Inputs (mouse, keys) are handled, animations play. You can embed a fully-featured game inside a Delphi form this way or you can use it to just add something small, e.g. a visualization of some 3D object (from glTF, X3D, MD3 or other formats) to an existing form design.

Everything is documented on TCastleControl manual page. The VCL and FMX variants of the component are practically equivalent, they are also practically equivalent to Lazarus (LCL) version of TCastleControl.

The short instructions are:

  1. Get the Castle Game Engine. Take a look at our installation manual if you have any questions.

  2. Install the components in Delphi IDE: Go to the packages/delphi subdirectory and open the AllPackages.groupproj there. It’s a group of 3 packages.

    First, you can build them all at once.

    Then install them. Make sure your target is “Windows 32-bit” and click “Install” on all 3 packages. The menu option to “Install” is available when you right-click each .bpl. (Again, remember to use “Windows 32-bit”; Delphi IDE is 32-bit, you cannot install packages when your platform is Windows 64-bit.)

  3. Then open the examples. They are in examples/delphi, one example for VCL one for FMX. These are regular Delphi projects, open them, play with stuff on form, compile and run (for Windows 32-bit or 64-bit).

    You can also open each example in CGE editor, to edit the 3D / 2D / UI designs there. Compiling from CGE editor runs Delphi command-line compiler under the hood — so you can hit F9 from CGE editor, or from Delphi, and it practically does the same.

  4. That’s it. Go ahead and have fun with the engine! 🙂

    Follow the manual. If you want to use Delphi for everything — configure in CGE editor “Preferences” Delphi as your compiler and code editor. And open all the examples in examples/ subdirectory — all of them work with Delphi, though most of them do not use Delphi forms, they use our own TCastleWindow which is just a window filled completely with CGE rendering. Such applications are designed completely in CGE editor.

Since the initial announcement, we have improved input (mouse and key) handling on both VCL and FMX, we added code to avoid rendering FMX version at design-time (it seems FMX native components just cannot reliably render at design-time), and we improved how controls work with our views.

Let me know your feedback, about the new TCastleControl for FMX and VCL, and everything else! If you have any questions, hop onto our forum and Discord. And if you like this, please support us on Patreon!

Comments on the forum ➤

Editor improvements: color picker, display statistics, simple grid and axis

Posted on

Color picker used for light color
Color picker used for fog color
Color picker used for UI color
  1. Choosing colors inside CGE editor is now using a modern, cross-platform, comfortable color picker dialog. To see it, simply click on “…” in the editor object inspector to adjust any color — of user interface (like TCastleRectangleControl.Color), or 3D stuff (like TCastleAbstractPrimitive.Color), of background (like TCastleBackground.SkyTopColor).

    The new color picker dialog pops up, allowing you to configure color using HSV, RGB, allowing to copy-paste color as a hex value, adjust alpha, and it even shows sample code how to set the color using Pascal code.

    The dialog updates the resulting color in real-time, so you can watch the resulting color in the design as you drag any slider in the dialog. You can “Revert” the color (to the state before you opened the dialog), by default the color is applied without any extra action necessary. Moving the mouse out of the picker dialog also leaves the color applied — this is similar to color dialog behavior of e.g. Blender and Godot.

    Underneath, we use LCL mbColorLib components pack. Big thanks to mbColorLib authors (Marko Binić, Werner Pamler and to Andrzej Kilijański for integrating it in CGE!

  2. You can now easily display rendering statistics (FPS, draw calls, shapes rendered). Use the “Edit -> Show Statistics (F8)” menu item in the editor.

  3. For some time now, we have a simple way to display 3D grid and axis (X,Y,Z axes) in the editor: use menu item “Viewport -> Show Grid And Axis”. It’s just a simple initial implementation — in the future the grid and axis sizes should adjust better to your current view, so that they use a reasonable units, to not look too tiny/too huge in various cases.

Comments on the forum ➤

Physics layers – configure what collides with what

Posted on

Physics collisions on platformer
Physics layer choice in platformer
Physics collisions
Physics collisions
Physics names

I’m proud to announce new feature that enhances our physics: physics layers.

The idea is really simple: you can spread your objects (TCastleRigidBody) into multiple layers, and then configure which layer can collide with which. This way you can make certain things ignore other things. For example, maybe enemy_bullets should not hit other enemies or maybe enemies should not consider each other when walking (in some 2D games, it is normal that enemies can “pass through” each other).

There are really just 2 things to configure:

  1. At each rigid body, set the TCastleRigidBody.Layer to indicate the layer on which the body is.

    To help with this, you can add names and even longer descriptions to layers. Do this through Viewport.Items.PhysicsProperties.LayerNames. In the usual workflow, just click to configure LayerNames using “…​” button in the editor. The names and descriptions are only for the developer, to better document the layer meaning.

  2. Configure which layer collides with which using the checkboxes at Viewport.Items.PhysicsProperties.LayerCollisions. You can set them from code, or click on “…​” from CGE editor to configure them visually.

The simple usage example is in examples/physics/physics_3d_collisions_layers/. More involved example is in examples/platformer.

The documentation of this feature is part of the manual about physics.

Comments on the forum ➤

Web target – progress and plans

Posted on

WebGL

After the big engine release of 7.0 (coming really soon!), I’m dedicated to focus on adding the web target as a new engine platform.

The goal is simple: allow you to recompile more-or-less any application you wrote using Castle Game Engine (using TCastleWindow) to the web. So you can put your application on a website, as part of a normal HTML webpage, and users can play it instantly, without the need to download / install any native application or plugin.

How:

  • We’re using FPC WebAssembly target. Huge thank you go to the whole FPC team of course for making it possible!

    Possibly there will be some additional “glue” bits done using pas2js (such “glue” is necessary as WebAssembly doesn’t otherwise get access to JavaScript APIs available in a web browser).

  • We will render using WebGL 1.0, with optional WebGL 2.0 features. This is very similar to current rendering on mobile, where we use OpenGL ES 2.0, with optional OpenGL ES 3.0 features.

  • For audio, we will add a new sound backend using WebAudio. This will be the default sound backend on the web (like the OpenAL is now the default backend on non-web platforms).

    It is also possible our FMOD sound backend will also be ported to web, as FMOD supports HTML5. This would make FMOD a truly cross-platform sound backend, working on every platform we support in CGE.

    I recently wrote more about WebAudio in the context of X3D 4.0. Supporting advanced X3D 4.0 audio nodes is not our priority, but since WebAudio will happen anyway, on the web… they will open this possibility. There is also LabSound that provides WebAudio-like API on non-web platforms, and in principle it could one day replace OpenAL, making web and non-web audio handling closer.

  • For data delivery, we know we’ll have to invent a simple format to carry our game data as one big binary blob. The simple plan is to just pack game data into zip.

  • For development purposes, likely we’ll add a “Run simple webserver on localhost” feature, to allow you easily run WebAssembly applications. This can be done using a number of things, I like most the idea of using fpWeb which can instantiate a standalone HTTP server in just a few lines of code.

What we have now:

  • Branch webassm_platformer_test in CGE contains a code that compiles (but it is not functional yet!) for WebAssembly. This means that CGE compiles, and also build tool supports a new OS/CPU. So you can enter any CGE project, and execute on command-line:

    castle-engine compile --os=wasi --cpu=wasm32
    # or
    castle-engine compile --os=wasi --cpu=wasm32 --mode=debug
    
  • We’ve encountered FPC issue #40229 (Wasm32 symbol xxx without index value error) but it is now happily fixed 🙂 Many thanks go to Nikolay Nikolov from FPC team for fixing, and Andrzej Kilijański for preparing a code to easily reproduce the issue.

  • Trung Le (Kagamma) has been doing lots of work with CGE + FPC WebAssembly. His fork contains a branch wasm32-wasi-port with lots of active work. I absolutely expect that we’ll merge it to CGE webassm_platformer_test at some point, and then to master branch 🙂

  • As noted by Trung Le (Kagamma), the important issue hanging on FPC now is #39547 (wasm32-wasi: Cannot create dynamic library). Go ahead and upvote it 🙂

  • File-size tests are promising. Compilation of examples/platformer, which practically uses 100% of CGE units, yields a binary platformer.wasm that has 16 MB. Gzipped it has 3.4 MB.

    The gzipped size is really what matters — both web browsers and servers support gzip-(de)compression on the fly, you can also just put ready-gzipped version on the server and tell the browser to just decompress. So in all practical cases, users will download 3.4 MB, not 16 MB.

    Note that above is for a release build. The debug build weights 51 MB, and gzipped 12 MB. How is the debug build actually useful on the web — I am not certain now 🙂

    We could also use Brotli, a newer compression method also commonly supported by web browsers and servers.

I want to thank everyone involved in this and let’s push forward! Web target is a really cool feature, from my talks I know it’s an important feature for many CGE users, and I feel we have it in our reach. Let’s keep coding and enjoy making games 🙂

Comments on the forum (7) ➤

International fonts improvements: better sizing properties, better IME support on Windows (to input e.g. Chinese in TCastleEdit), better example

Posted on

Local chars demo
  1. Our demo examples/fonts/test_local_characters was improved a lot.

    It’s now both simpler and more powerful, shows the advised approaches: just set up TCastleFont to load fonts from TTF/OTF and assign it to TCastleUserInterfaceFont.CustomFont (like TCastleLabel.CustomFont) or TCastleText.CustomFont.

    See manual about text and fonts.

  2. With big thanks to Freedomax, our TCastleEdit now works with Windows IME much better. The IME popup appears at a proper place, and is thus visibly associated with the input box. This is great for languages relying on IME for input, like Chinese. See PR 457 for movie how it looks.

  3. The way we calculate font sizes is now easily customizable using published properties (available also in editor):

  4. Font sizes have also better names, following standard conventions:

    See terminology: Metric typographic units – Wikipedia, Glossary – Google Fonts.

Comments on the forum ➤

Come to International Pascal Congress (July 3-7, 2023, Salamanca) to listen to my talk and attend Castle Game Engine course

Posted on

Castle Game Engine

I’m proud to announce I’ll be part of International Pascal Congress, an event taking place July 3-7 (this year, 2023) in the Salamanca city (Spain).

You can register now (see the registration page for prices)! Note that 1st early registration phase is only up to the 10th April, and registering early costs less.

The program is full of talks and presentations that should be appealing to every Pascal user, coming both from FPC (e.g. Michael Van Canneyt will give a talk “Free Pascal: Past, Present and Future”) and Delphi (e.g. Marco Cantù will give a talk “Delphi’s Object Pascal Evolution”). See the Plenary talks for details.

And of course from yours truly 🙂 I will be:

  1. Making one of keynote lectures titled “Developing games and graphic visualizations in Pascal”.

    This will be an overview of the most important concepts of developing graphic applications, including in particular 3D visualizations and games, and how to do them in practical Pascal applications.

    We will start with an overview of APIs, like OpenGL(ES) and Vulkan, and their most important concepts like shaders.

    We will show how to use these graphic APIs from Pascal, from various Delphi (like Firemonkey 3D) and Lazarus (like TOpenGLControl) components.

    Then we will move to high-level libraries and game engines, like

    Finally I will talk about the important features you should consider when choosing a library (and creating your own): 3D model formats (how and why are formats like glTF and X3D developed), PBR (physically based rendering), mixing 2D and 3D, physics and more.

  2. I will give a course Developing games using Castle Game Engine.

    The course consists of 4 sessions, throughout which I’ll present using CGE to make 3D and 2D games, with physics, user interface, spatial sounds, and even using GitHub Actions.

Read all the information on International Pascal Congress. See you in Salamanca! 🙂

Comments on the forum ➤

MD3 support improvements: multiple animations, tags, configurable skins

Posted on

MD3 animations example
MD3 animations, tags, skins example using Tremulous models
MD3 animations on a Tremulous model
MD3 animations example

As a fan of Tremulous, I’m happy to announce big improvements to our MD3 file format support.

Note that we still recommend glTF as the best 3D model format in general. MD3 is an older model format, with some known limitations (precalculated frames per second, no PBR, no runtime manipulation of rig…) but it is just so fun and easy to support that I couldn’t resist adding a few features 🙂

  1. New example examples/animations/md3_animations_tags shows using MD3 animations, tags and skins.

  2. Manual page dedicated to MD3 documents everything about our support.

  3. Multiple animations from MD3 file are supported in natural way.

    We read animation.cfg automatically when you load MD3 into TCastleScene.

    You can play MD3 animations using TCastleSceneCore.PlayAnimation or TCastleSceneCore.AutoAnimation, list animations using TCastleSceneCore.AnimationsList and so on. See manual about running animations from code.

    This also means you can set animations in CGE editor (TCastleSceneCore.AutoAnimation property is a combo-box there to choose animation).

    You can also play MD3 animations in view3dscene (open “Animations” panel).

  4. Optimized reading vertexes and triangles from MD3.

  5. Tags from MD3 are supported. Tags in MD3 are places where you can attach additional things to the model, e.g. a weapon to a character’s hand. This way the weapon will be animated naturally along with the character’s hand movement.

    We support them now in CGE, and you can use ExposeTransforms mechanism to attach anything to an MD3 tag (you can attach another MD3 model or anything else, any CGE TCastleTransform and TCastleScene).

  6. You can choose MD3 skin. While by default for xxx.md3 we load xxx_default.skin, but you can now change the skin, by adding an anchor like #skin:yyy to the URL. For example, loading head.md3#skin:light will load the skin from head_light.skin.

Have fun 🙂

Comments on the forum ➤

Tremulous animations played from MD3 file

Posted on

Tremulous MD3 animation - Marauder
Tremulous MD3 animation - Tyrant

New example split_long_md3_animation_into_logical_pieces shows how to play subanimations in MD3 files. In a broader context, it shows how to use TCastleSceneCore.ForceAnimationPose to manually “drive” the animation, picking the animation frames you want.

The MD3 format comes from Quake 3 and it’s used by various games sharing that game engine. In particular I’m a big fan of Tremulous so this example naturally shows Tremulous cool low-poly aliens rendered and animated using Castle Game Engine 🙂

The MD3 file itself doesn’t specify particular animations, it is essentially one long animation that in practice usually contains glued a number of “subanimations” in our terminology. The accompanying animation.cfg specifies the “subanimations”, where do they start and finish. The example code defined a ready class that loads animation.cfg, and allows to query and easily play “subanimations” specified there.

If you use MD3 files with accompanying animation.cfg files, you will find the class TSceneSubAnimations to be a ready-to-use component that allows you to deal with MD3 animations easily.

If you’re looking into more general “how can I manually control the animation” then look under the hood and see how is the TCastleSceneCore.ForceAnimationPose used there.

Here’s a quick demo:

Comments on the forum ➤

New component to place Tiled map in a viewport

Posted on

Tiled snow map
Tiled beach map
Tiled map - layers
Tiled map in 3D
Tiled map

Following the Tiled improvements and optimizations done in January, it was most natural to introduce a dedicated class TCastleTiledMap that represents a Tiled map in a viewport. It descends from TCastleTransform and thus can be moved, rotated, scaled (in 2D or 3D), just like anything else in the viewport.

The usage demo, along with many sample maps, is in examples/tiled/map_viewer_in_viewport.

Most important Tiled-specific API:

The full documentation is in Tiled map manual page.

Many thanks go to Freedomax for implementing animations on Tiled maps and providing a lot of Tiled fixes (seams fix, ForceTilesetSpacing, proper Z-order of tiles in all situations, relative URL fix…) and examples!

Comments on the forum (3) ➤