Using OpenGL “core” profile by default on macOS

Posted on

fps_game example on mac
System Information with OpenGL 4.1 on mac
shadow maps on mac
shadow volumes on mac
shaders on mac
view3dscene on mac with OpenGL 4.1

Thanks to recent rendering code improvements, we can finally request “core” profile on macOS, to get latest OpenGL version (4.1 in my case) instead of being stuck with legacy OpenGL 2.1 on mac.

We request now a modern context on mac, both with TCastleWindow and TCastleControl. This applies to all our software — CGE editor, view3dscene, all your applications you build with CGE.

Comments on the forum ➀

Shadow volumes and shadow maps work on mobile (OpenGL ES) and we have a new TCastleRenderUnlitMesh utility class

Posted on

Shadow maps on OpenGLES
Shadow volumes on OpenGLES
Debug visualization of octree in view3dscene

You can use the new TCastleRenderUnlitMesh utility class to render unlit 3D objects easily. It has a nice API when you want to render a set of vertexes and then forget about them — sometimes this is easier than setting up the shapes in TCastleScene. It may be especially useful for rendering debug 3D geometry, in fact view3dscene is already using it for this purpose.

An example usage is in test_rendering_opengl_capabilities example, in unit gamemymesh.pas.

Moreover, thanks to this class (and some other improvements I’ll describe in subsequent posts) we have upgraded our shadow volumes code, making it simpler and working with mobile OpenGL ES, without losing any performance. You can test shadow volumes on OpenGLES e.g. using examples/viewport_and_scenes/shadows or by creating a new project from “3D FPS Game” template.

And while we’re at it, our shadow maps code was also fixed. It now works on OpenGLES in much the same way it does on desktop OpenGL.

Note: This is not the end of shadow maps upgrades. They are still not as straightforward to activate as they should be, and they don’t cast shadows on multiple scenes. More work on shadow maps is coming πŸ™‚

Comments on the forum ➀

Watch my DelphiCon 2023 presentation in 3 hours, watch my GIC 2022 presentation now :)

Posted on

GIC 2022

First, a reminder that our DelphiCon presentation is in ~3 hours, 2:00 PM in Central Standard Time. See DelphiCon 2023 to register, you can also just watch the live stream on Embarcadero YouTube. I hope you will enjoy it! I will be of course present during the presentation, go ahead and fire questions at me:) See also more talk information here.

Second: Game Industry Conference recently published a recording of my presentation there, from October 2022. It’s just 30 minutes, and it’s really a very different talk from DelphiCon, I talk about the engine high-level decisions (like glTF, X3D), motivation, thoughts on making open-source game engines (declarative, evangelism). The slides from GIC presentation are also available. So, if you can’t wait to see me :), I encourage to watch GIC 2022 talk now:

Comments on the forum ➀

Join DelphiCon 2023 and watch Castle Game Engine presentation this Thursday

Posted on

Michalis at DelphiCon 2023

I have a lot of pending news from recent engine developments (big refactor to rendering, lots of OpenGLES improvements, Tiled improvements) but for today, the most important thing:

Join Embarcadero DelphiCon 2023, an event celebrating 28 Years of Delphi, and listen to our talk “Getting Physical in Your Games with Castle Game Engine” on Thursday (February 16, 2:00 PM in Central Standard Time). As always be careful to recalculate timezones, personally I found it easiest to register and then add particular event to the calendar by clicking on the appropriate link, and then I can let my calendar software do all timezone calculations πŸ™‚

You can also just watch the event on Embarcadero YouTube, they stream it live.

My talk focuses on new features coming in 7.0-alpha.3, with a special emphasis on physics. I spend a significant part of this talk doing funny things with physics :), there is also a nice overview of CGE usage for 3D in general, I also fall in love with a particular sound effect. My talk is prerecorded this time, and as such I can already spoil that it was impossible to fit everything into my 1-hour slot, and I will be releasing some “bonus” videos afterwards, if you can’t get enough of my rambling and will want more after DelphiCon πŸ™‚

And while I show there everything in Delphi, since it’s DelphiCon, it is really all the same if you’re an FPC/Lazarus user!

My talk description:

Castle Game Engine is an open-source cross-platform 3D and 2D game engine. We’re aiming at a huge engine release “7.0” shortly after Delphicon 2023. As such, I’d like to show the latest juicy stuff we’ve been working on: physics, shadows, rendering huge maps, using engine as part of VCL or FMX form. The session will start with an introduction to using the engine with Delphi. Everyone interested in making games using Delphi is welcome!

Comments on the forum ➀

Support us on Patreon (and get stickers!), Ethereum, Open Collective and other options

Posted on

Castle Game Engine stickers

While technically I’m busy on shadow-volumes-new branch (despite the name, it has spiraled into a number of generally useful rendering code refactors; rendering on both modern and ancient GPUs will benefit, as various things are improved and the code gets simpler too)…

…let me make a non-technical post πŸ™‚

We really appreciate your donations and, going forward, this is ideally the way to fund the development of the engine, The main goal of donations is simply to cover the cost of people, so that they can work on the engine full-time, which in turn just translates to more features, faster. Right now we have 1/2 developer on a payroll (Andrzej KilijaΕ„ski, paid from Michalis Kamburelis own pocket) and hiring him was a great decision β€” having Andrzej made a big difference, the engine progress in recent years owes much to his work. Imagine we can have 10x of that πŸ™‚

Our recommended way to donate is a monthly subscription on Patreon. Patreon offers a number of traditional payment methods.

On top of making things easy, Patreon also offers a unique reward for donors: 4 physical sticker with CGE logo that you receive after 3 monthly donations at 10 USD tier. See the photo πŸ™‚ They ship worldwide, I tested πŸ™‚

But there are other options, always listed here. These include:

  1. If crypto-currencies are your thing, you can donate using:

    Ethereum: send to this address: 0x0b0e37c7391C7268DEc9c0De63bA5A3b1B42baCe

    Bitcoin: send to this address: 1FuJkCsKpHLL3E5nCQ4Y99bFprYPytd9HN

  2. GitHub Sponsors

  3. Open Collective

Whichever option, whichever tier you choose — big thank you!

I’m serious about developing the engine, I’m serious about making something that enables you to develop great games with open-source software. We are doing it… wow, I just found the oldest news post from 2004. So 18+ years now. The engine is now old enough to drink and do other adult stuff πŸ™‚ And you can see at our regular news, for so many years that we don’t stop and we don’t plan to stop. I hope you enjoy this journey and want to support us along the way. Financial funding is, in the long-term, something that allows to work on the engine just as a regular thing, with as much people and time we can afford. Your support really changes what we can achieve and how fast we can do it.

Enjoy creating games with Castle Game Engine!

Comments on the forum ➀

“Eye of the Beholder” example

Posted on

"Eye of the Beholder" CGE demo
"Eye of the Beholder"
"Eye of the Beholder" demo in editor

To start the weekend, I added a new example to Castle Game Engine showing the navigation in games like “Eye of the Beholder”: moving on a grid, rotating by 90 degrees, crawling a dungeon with a group of heroes πŸ™‚

The example is in examples/eye_of_beholder directory of engine sources. Just open with CGE editor and run. The level has been designed in Blender.

You can move and rotate using keys or by clicking on buttons (so it also works on mobile).

See the screenshots on the side — can you tell which one is the original β€œEye of the Beholder” game and which is our example? πŸ™‚

Comments on the forum ➀

Big improvements and optimizations for Tiled maps handling in TCastleScene

Posted on

Tiled isometric map in CGE editor in TCastleScene
Tiled hexagonal map in TCastleScene
Tiled map with extra objects in TCastleScene
Big Tiled map (400x400) in TCastleScene
Tiled map in view3dscene
Tiled map in view3dscene in 3D

This post somewhat retracts yesterday’s post, because I had a busy sleepless night and fixed some issues with loading Tiled in TCastleScene that I mentioned yesterday πŸ™‚ I did a significant refactor of how it works.

I’m proud to say that loading Tiled maps into TCastleScene is now our recommended approach to using Tiled maps. The big benefit of this approach is that you can place additional objects, like sprite sheets in TCastleScene, over the map easily (and specialized API to place/move units on map will appear soon too). TCastleTiledMapControl will soon be deprecated, in light of this.

The following improvements are done:

  1. First of all, we have new example application examples/tiled/map_viewer_in_viewport where you can test everything I announce today. It is a simple Tiled map viewer, underneath loading Tiled map to TCastleScene.

    You can test that it is functionally just as good, if not better, than examples/tiled/map_viewer approach.

  2. Huge optimization, by internally using a single draw call for all consecutive tiles using the same tileset. This allows to effortlessly support our test map 400×400 in examples/tiled/map_viewer_in_viewport/data/maps/desert_big.tmx with 100 FPS, at whatever zoom.

  3. Support for all map types: Orthogonal, Isometric, IsometricStaggered, Hexagonal.

  4. Correct support for all flip combinations (diagonal, horizontal, vertical).

  5. Fixed layer Z ordering and offset application for all layer types.

  6. Fixed origin (map left-bottom corner is now at 0,0).

  7. Support for “Smooth Scaling Safe Border”, to fix rendering artifacts when using smooth scaling on tilesets without proper alpha bleeding.

  8. I’m proud that my refactor actually made the code over 2x smaller and simpler πŸ™‚ Line count dropped 1210 -> 510 for the x3dloadinternaltiledmap.pas unit.

If you like my sleepless nights’ work, please support us on Patreon πŸ™‚

Comments on the forum ➀

Almost-automatic batching for TDrawableImage, Tiled rendering incredibly faster (like 30x), ability to load Tiled into TCastleScene, new isometric game demos and the plan for 2D games based on maps

Posted on

isometric_game_3d designed in editor
isometric_game_3d with shadows
Rendering Tiled map using TCastleScene
Rendering Tiled map using TCastleScene with 3D rotation
isometric_game using scenes and viewport
Rendering big Tiled map (400x400) in map_viewer example
Editing big map (400x400) in Tiled

OK, this post title is probably too long πŸ™‚ But I really want to announce a few related things, and talk about related plans. Bear with me, and read on if you’re developing 2D games using Castle Game Engine with something like a map underneath.

  1. I’m happy to announce a very powerful and easy to use optimization for TDrawableImage rendering: almost automatic batching. The way it works is really simple: if your rendering code is mostly just a sequence of calls to TDrawableImage.Draw, then you can surround it with TDrawableImage.BatchingBegin and TDrawableImage.BatchingEnd calls (these are class methods) to achieve a significant speedup.

    Underneath, batching for TDrawableImage means that rendering many times the same image gets grouped into a single OpenGL(ES) draw call, and so it’s much faster. It works because GPU has great performance if you tell it to render million quads with a single draw call, while it’s quite inefficient if you use million draw calls to render one quad each.

    E.g. this code actually does just 2 draw calls now, not 200:

    TDrawableImage.BatchingBegin;
    for I := 0 to 99 do
      MyDrawableImage1.Draw(100, 10 * I);
    for I := 0 to 99 do
      MyDrawableImage2.Draw(100, 10 * I);
    TDrawableImage.BatchingEnd;

    This should be a great tool for people doing lots of image rendering.

  2. Using the above batching, I have greatly optimized our 2D Tiled rendering control TCastleTiledMapControl, that now internally always activates this batching.

    As Tiled rendering uses TDrawableImage to render each tile, it benefits greatly from the new batching.

    Moreover, as another optimization, TCastleTiledMapControl no longer renders tiles that fall outside of its render rectangle. This rendering was useless, and it could cost significant time.

    I have also added a test map, examples/tiled/map_viewer/data/maps/desert_big.tmx, with 400×400 tiles, to demonstrate this optimization. Before optimization, it had 2.7 FPS on my system (yeah, less than 3 FPS…), clearly demonstrating that previous rendering was unoptimal. After adding batching, FPS increased to 24, and then avoiding rendering useless tiles gets us to nice 61 FPS. The FPS stay reasonable even at significant zoom out.

    You’re welcome to test it all yourself, just build and run examples/tiled/map_viewer/ yourself.

  3. In parallel to improving our simple 2D drawing (TDrawableImage, TCastleTiledMapControl) we also pursue another way to render 2D things in Castle Game Engine: render your whole 2D world as a number of objects (like TCastleScene and TCastleImageTransform) in a viewport.

    The approach to put things in scenes and viewports is in general much more feature-rich. Scenes can have physics, they can easily render sprite sheet animations, they can be designed visually in CGE editor (see e.g. Platformer demo done in editor this way), they also work in 3D (so a lot of work and optimizations benefits both 3D and 2D games).

    This means that in general, we advise you to use scenes and viewports for 2D games. Our new project template “2D Game” shows this approach.

    That said, the approach of “scenes and viewports” is admittedly not as efficient as (much simpler internally) rendering using TDrawableImage, TCastleTiledMapControl. This is especially visible if you try to design a big map for 2D game. Both memory (because of our X3D nodes memory usage) and performance suffers (because our DynamicBatching cannot yet handle some cases, and it doesn’t batch across scenes, so it’s worse than TDrawableImage.BatchingBegin and TDrawableImage.BatchingEnd in case of maps).

    There’s no single best solution (yet) to this “dualism”. We work on optimizing our scenes and viewports, and until it is perfect — I hope you can enjoy 2 methods of rendering 2D stuff. They are documented on How to render 2D games manual page.

  4. Pursuing the approach to render things using scenes, with many thanks to Matthias (from Free Pascal meets SDL) you can now load Tiled maps to TCastleScene. Simply point TCastleScene.URL to a Tiled map file (.tmx).

    This allows to render map inside a viewport, mix it with other viewport things (like scenes with sprite sheets) and use viewport camera (also at design-time) to pan and zoom the map. And you can even rotate map, even in 3D πŸ™‚

    The loading is not yet efficient, and doesn’t account for some map types (like isometric or hex). So TCastleTiledMapControl remains our recommended approach to render Tiled maps for now — but at some point in the future using TCastleScene should be fully efficient and functional and then it will be advised as more feature-packed.

  5. I have been playing with creating isometric games (without Tiled help) too.

    The result are new demos examples/isometric_game and examples/isometric_game_3d.

    They use TCastleViewport with items (like TCastleImageTransform and TCastleScene with sprite sheets) to express the map and objects on it.

    They show how it’s a feature-rich approach — e.g. isometric_game_3d has cool shadows πŸ™‚

    It is possible that in the future we could have a built-in tiled editor in CGE. I still haven’t decided when is the right time to pursue this — for now, relying on Tiled is great, but a built-in tiled editor remains an interesting option.

  6. Finally, the optimizations necessary for great performance when you use lots of small scenes and images to render maps are really in progress πŸ™‚

    I’m now working on branch shadow-volumes-new that, despite the name, includes a few useful renderer refactors. In particular it changes the way our shape renderer needs to be initialized / finalized, opening the door for cross-scene batching.

Thanks for reading! This was a complicated post, as admittedly what we do may be a bit confusing — we do pursue (and even document) 2 approaches for 2D maps, and we improve them both. But we also have a preference which one should “win” in the future (viewport and scenes!) but it will take time to get there with full performance. I hope what we do is clearer now and that you will enjoy the journey πŸ™‚

As always, please ask on our Discord or forum if anything is unclear.

And we appreciate supporting us on Patreon. We also opened the option to donate using Ethereum if crypto is your thing πŸ™‚

Comments on the forum ➀

Draw 2D geometry inside CGE editor using Castle Lines 2D components

Posted on

Castle Lines 2D demo
Castle Lines 2D demo
Castle Lines 2D demo
Castle Lines 2D demo
Castle Lines 2D - point details
Castle Lines 2D - points list

I’m thrilled to present Castle Lines 2D, a set of custom CGE components done by Korchazhkin Sergey (KumurTash on GitHub). They extend our Castle Game Engine editor functionality allowing you to draw 2D lines and polygons (possibly textured, possibly non-convex) right inside the editor!

The basic idea is that

  • You add a component TCastleLine2D or TCastlePolygon2D to a viewport,

  • You right click on the component in hierarchy and select “Edit Mode ON”,

  • Then you just click around to add / move / delete points (left mouse click adds/moves, right mouse click deletes).

  • The editor remains fully functional during this, so in particular e.g. zooming or panning the view works as always.

The components are open-source, on GitHub: https://github.com/KumurTash/CastleLines2D. In addition, a great usage documentation (with screenshots) and API reference are available. Go ahead, download it and test!

We have a forum thread open where you can certainly post comments and contact the author.

The polygon does not have to be convex (but it cannot be self-intersecting). It can be textured (and the texture may be repeated and scaled). The line can have non-trivial thickness and also be textured. The way line segments are connected (joints) is also configurable.

It’s really a complete code and documentation that adds to our editor something I personally never even dared to attempt. So seeing this makes my heart warm πŸ™‚ I have to say in general that seeing others adding custom extensions to CGE and just using CGE to make cool stuff is extremely rewarding. So please everyone share what you’re doing in Show Your Projects forum category or Discord channel #show_your_projects πŸ™‚

Comments on the forum ➀

Comfortable Windows installer of Castle Game Engine, plus notes how to integrate InnoSetup with Jenkins and into your own applications

Posted on

Castle Game Engine installer
Castle Game Engine installed on Windows
Castle Game Engine installer
Castle Game Engine installer

Our Castle Game Engine download page now recommends Windows users to download the engine as a self-extracting installer (EXE), which is a typical installation method on Windows.

The installer is done using excellent and popular Inno Setup. It will install CGE to a user directory, like C:\Users\USERNAME\AppData\Local\Programs\Castle Game Engine. The installer automatically creates menu and desktop shortcuts, shows you the license summary, runs CGE editor for the 1st time if you want and generally makes the whole process completely straightforward for Windows users.

This is similar to e.g. VS Code, that also uses InnoSetup and installs for the current user. Note that we don’t install VS Code with CGE (though we may in the future), and as always you have a choice which IDE to use — VS Code, Lazarus, Delphi, Emacs or really any text editor you find suitable to edit Pascal.

As a bonus, unpacking using the InnoSetup is also much faster than unpacking the zip using built-in Windows zip support.

TODO: Note that the installer right now does not make system-wide install. I have an option to activate system-wide installlation for CGE (and the setup can offer you a choice whether to install for current user or system-wide). But it is hidden for now, because system-wide installation means that examples are read-only, and it means you cannot easily explore + just build / tweak the examples. At some point in the future, we should allow you to open example by making a copy of it and then we’ll reenable the option for system-wide installation here. Note that everything else worked smoothly with system-wide installation, the CGE editor and build tool work as usual, our tools in general have always been written to handle the case when they are installed in read-only directory.

Since you know I love automation and CI / CI, of course the whole process of building the installer is automated, and thanks to InnoSetup it was really trivial to automate. So the installer is rebuild using Jenkins after every commit (that passes a number of automated checks) and you always have the installer for the latest CGE snapshot available.

  1. We keep a ISS file describing how to package CGE.

  2. Our pack_release.sh script has an option to, once it prepared the CGE distributable files, instead of zip it can create a setup. To do this, it calls iscc with parameters that define input, output directory, version etc. It looks like this (this is bash script):

    # Detect iscc location
    INNO_SETUP_CLI='iscc'
    if ! which "${INNO_SETUP_CLI}" > /dev/null; then
      # if not on $PATH, try default location
      INNO_SETUP_CLI='c:/Program Files (x86)/Inno Setup 6/iscc.exe'
    fi
     
    # See https://jrsoftware.org/ishelp/index.php?topic=compilercmdline
    # and https://jrsoftware.org/ispphelp/index.php?topic=isppcc (for preprocessor additional options).
    "${INNO_SETUP_CLI}" \
      "${ORIGINAL_CASTLE_ENGINE_PATH}/tools/internal/pack_release/cge-windows-setup.iss" \
      "/O${OUTPUT_DIRECTORY}" \
      "/F${ARCHIVE_NAME}" \
      "/DMyAppSrcDir=${TEMP_PATH}castle_game_engine" \
      "/DMyAppVersion=${CGE_VERSION}"
  3. And that’s it πŸ™‚ Jenkins archives the resulting exe, our scripts copy it to a GitHub release of the next snapshot, and we link to them.

The process was very straightforward I have to say, and in the future we will likely add an easy option to package your games into a self-extracting Windows installer too (using InnoSetup under the hood). For now, you can roll such setup on your own, using the output of CGE package in “directory” format as a start (input for Inno Setup) and following above notes and just Inno Setup documentation.

Comments on the forum (4) ➀