Engine improvements: Prettier lighting with SeparateDiffuseTexture, cross-platform TCP client/server classes, EnablePhysics

Posted on


To finish the week of many annoucements, here are 3 more engine features added lately.

BTW, I also wrote a wiki page documenting common properties to “make rendering prettier”. Check it out:)

New engine features:

  1. Scene.Attributes.SeparateDiffuseTexture allows to get a prettier lighting behavior. The textures (in Appearance.texture or CommonSurfaceShader.diffuseTexture) will then really affect only the diffuse lighting term. This is generally better and prettier (specular highlights are then brighter), and it’s also more correct (according to X3D spec). But note that it is only possible in Phong shading (when Scene.Attributes.PhongShading is also true), and it makes rendering a little more expensive (for now).

    In view3dscene (see view3dscene from snapshots) you can use menu item View -> Separate Diffuse Texture (When Phong Shading) in addition to View -> Phong Shading on Everything. By default it is false, to be compatible with previous look, and also because it’s more consistent with Gouraud shading behavior. (And the Gouraud shading is default, in turn, for speed.)

  2. Client and server classes for implementing TCP client/server communication in Castle Game Engine games are available. See the unit CastleClientServer, and the demos in examples/tcp_connection. Thanks go to Benedikt Magnus for implementing this!

  3. You can now instantly disable/enable physics by setting SceneManager.Items.EnablePhysics to false/true.

Comment on this post ➤

Engine improvements: generating compressed/downscaled textures is smarter

Posted on


Since a long time, you can automatically generate compressed and/or downscaled textures versions using our build tool.

This process is now smarter. Instead of detecting which files to update looking at file modifications times, it now looks at file contents (using fast MD5 checksums), and automatically creates/updates a castle_engine_auto_generated.xml file. The castle_engine_auto_generated.xml is automatically created and maintained in your data/ directory when you call castle-engine auto-generate-textures.

We plan to extend this feature even more, to store more information inside the automatically-maintained castle_engine_auto_generated.xml. In the future, this file can be used to:

  1. Track the size of the texture. This allows to avoid trying to load non-square compressed texture on iOS, which is not possible — thanks to weird Apple limitations. Currently we just avoid using any auto-generated compressed textures on iOS.
  2. Track the DXT* version generated, for the case when we automatically choose the best DXT* version depending on the image alpha channel. This would complete a currently unfinished-and-undocumented feature of <format name="DXT_AutoDetect" /> in material_properties.xml.
Comment on this post ➤

Engine improvements: Localization

Posted on


You can now comfortably localize (translate) your game.

Two approaches are possible:

  1. Use our own localization class from the CastleLocalization unit. It can read from a number of translation formats (XML, JSON, CSV, GetText MO). It can translate user-interface controls, like TCastleLabel. The demo is inside examples/localization/custom/.

    For advanced users, the system allows to aid in localizing your custom classes too (see OnUpdateLocalization) and to add your own translation formats (see FileLoader).

    Thousand thanks go to Benedikt Magnus for developing this!

  2. Use the standard GetText unit from FPC. You use GetText formats for translating (PO, MO), utilizing tools like PoEdit. The resourcestrings are translated automatically. The demo is inside examples/localization/gettext/.

    The engine uses resourcestrings for some internally-generated messages (and it will use them more), so these can be translated too.

In both cases, you can use a cross-platform CastleSystemLanguage unit that tells you the preferred user language.

Note that, while both approaches (GetText, our own) provide some infrastructure to aid you in translating (resourcestrings, special handling for UI controls), you can also translate things “explicitly” in both cases. Using the TMOFile.Translate(‘my_id’) in GetText, or Localization.Items[‘my_id’] in CastleLocalization.

So both systems are really flexible, and should fill all your needs 🙂

A related feature is also new TInputPressRelease.KeyString. This expresses key press as a string with UTF-8 encoding, and allows us to accept input of international characters across Castle Game Engine (for example in TCastleEdit). Many thanks go to Eugene Loza for this!

Comment on this post ➤

Engine improvements: 2D rendering (TGLImage) – customize shader, documentation, getting contents from GPU

Posted on

  1. I wrote a wiki page documenting two approaches for 2D rendering using Castle Game Engine. Advised
    reading for people implementing 2D games 🙂

  2. You can customize the look of TGLImageCore using the TGLImageCore.CustomShader. Or you can customize the look of TCastleImageControl using TCastleImageControl.CustomShader. The demo: examples/images_videos/image_render_custom_shader.lpr.

  3. You can now assign the TCastleImageControl.DrawableImage. This allows you to render TGLImage on GPU using any fancy method, and then use it as a source of TCastleImageControl efficiently.

  4. Remember that you can draw one TGLImage over another, or draw arbitrary (2D or 3D) things into the TGLImage, using fast GPU rendering. The demo how to do this is in examples/images_videos/draw_images_on_gpu.lpr.

  5. You can get the contents of TGLImageCore to TCastleImage (thus getting the memory from GPU to RAM, available to CPU) using the GetContents helper method.

Comment on this post ➤

Engine improvements: User-interface – horizontal/vertical layout groups, on-screen keyboard and FreeType on Android, better UI scaling

Posted on

"The Unholy Society" fight UI, implemented with UI scaling and TCastleHorizontal/VerticalGroup layouts
"The Unholy Society" fight configuration UI (internal), using TCastleHorizontal/VerticalGroup layouts inside a scroll view
  1. We include new classes TCastleHorizontalGroup, TCastleVerticalGroup to easily layout your controls horizontally or vertically.

  2. FreeType library on Android (thanks to Benedikt Magnus!).

  3. TCastleEdit.AutoOnScreenKeyboard (also thanks to Benedikt Magnus!). Note that the keys from the on-screen keyboard are not yet automatically passed to your applications — we’re working on it.

  4. Many parts of the user-interface (TUIControl descendants) are now calculated using floating-point values, and can even be specified using floating-point values. E.g. you can now use FloatWidth instead of Width, CalculatedFloatWidth instead of CalculatedWidth, ScreenFloatRect instead of ScreenRect and so on. Some of the public properties have also just changed to be floats (like padding, margins, anchors deltas), which may break compatibility in rare cases.

    The primary reason for this change is that when using UI scaling, it doesn’t really make sense to limit sizes or positions to integers. They do not hit the exact pixel boundaries anyway (in case some UI scaling is applied), instead they should be rounded to pixels only at the very bottom of the rendering code. So anchors and such should be calculated using floats, otherwise a Round() in the middle of an operation (before we work in the “final” resolution) would needlessly make UI controls “snap” to an invisible grid.

    A minor reason is also that this is more friendly to animations. Although animations could be done earlier too (having an “animation driver” remember position as float). But it’s easier now, you can just animate existing float properties, like

    Control.AnchorHorizontalDelta := Control.AnchorHorizontalDelta + UpdateSeconds;

    in your OnUpdate event.

  5. Improvements to VisibleChange to help with implementing controls that react to children changes.

Comment on this post ➤

Engine improvements: Rejuvenated PlayAnimation method (easily play animations backward, with blending, stop notifications…)

Posted on

"The Unholy Society" NPC (and enemy), animated with PlayAnimation
PlayAnimation demo with animation blending
view3dscene controllig animation forward/backward

I have a large backlog of new Castle Game Engine improvements to announce 🙂 Let me try to make it up, by making a new announcement more-or-less daily for the following week. Remember that everything I describe is available to you right now: simply use the Castle Game Engine version from GitHub (6.5).

  1. We start with the improvements to our PlayAnimation method. It is the primary way to run animations using Castle Game Engine (documented in the manual).

    • New overloaded PlayAnimation version with TPlayAnimationParameters, that allows to specify:
    • New overloaded PlayAnimation(AnimationName: string, Loop: boolean) version. This replaces (deprecates) older overload with "Looping: TPlayAnimationLooping" parameter — the TPlayAnimationLooping did not really prove to be of much use, so it’s simpler to just specify Loop as a boolean.

  2. I have also written a large documentation “How to animate things using X3D”. This may be useful for developers that want to understand how the X3D nodes are used for animations. The PlayAnimation method, under the hood, uses the X3D nodes.

Comment on this post (1 comment now) ➤

Connect4 – new Android game using Castle Game Engine

Posted on

Connect4 screenshot

We’re proud to present Connect4, a free game for Android published by Benedikt Magnus and LanIstAn today!

The game is using Castle Game Engine, with our 2D user-interface rendering, and includes music, localization (English, Polish, German, Spain), and networking support. You can plan against a computer, or against a friend over the network. I believe this is the first game with networked play done using CGE.

I really like this part of developing Castle Game Engine — seeing how others are using it to create the coolest things. Congratulations and thank you!

We also have a ton of new features added to Castle Game Engine lately. In particular, thanks to Benedikt Magnus we now have:

Thousand thanks!

And I’ll be posting more about the new CGE features later.

Comment on this post ➤

Castle Game Engine is now Embarcadero Technology Partner

Posted on

Chinchilla model in X3D, based on high-poly version in "Big Buck Bunny"

We are now officially Embarcadero Technology Partner!

What this means, in simple terms, is that Michalis has full access to the latest Delphi version, with all the Delphi platforms (including Android and iOS), for free.

This should be great news for everyone waiting on Castle Game Engine + Delphi compatibility:) We have no more excuses now, Castle Game Engine will have to work perfectly with Delphi!

Thanks go to Embarcadero, and in particular Jim McKeeth, for making this possible.

(P.S. I curse myself for making this announcement on the one day of the year when everyone else is making jokes 🙂 Yes, this is very real, and is happening! Our supported compilers and IDEs page is already updated about it.)

Comment on this post (4 comments now) ➤