Castle Game Engine is an open-source, cross-platform 3D and 2D game engine designed for developers who need a powerful visual editor and native performance using modern Object Pascal. It solves the challenge of building high-performance games for multiple targets—Windows, Linux, macOS, iOS, Android, Nintendo Switch, and web—without sacrificing tooling flexibility or code quality. The engine provides a complete pipeline from visual scene design to command-line builds, with deep integration into popular IDEs like Lazarus, Delphi, and VS Code.
Built on Free Pascal and Lazarus, it leverages modern Pascal features for clean, object-oriented code. The engine supports industry-standard formats like glTF and X3D, includes a visual editor for scene composition, and offers tooling compatible with CI/CD systems like GitHub Actions and Docker. Its LGPL license with static linking exception allows commercial and proprietary game development without forcing open-source releases of your game code.
What You Get
- Visual Editor - A full-featured WYSIWYG editor for designing 3D and 2D scenes with cameras, lights, primitives, and UI components like buttons and labels, with automatic scaling and anchor-based layout.
- glTF and X3D Support - Native import and rendering of glTF 2.0 and X3D 3D models, enabling seamless integration with Blender, Sketchfab, and other authoring tools.
- Spine 2D Animation Support - Direct import and playback of Spine skeletal animations for high-quality 2D character animation without manual frame-by-frame work.
- Composable Shader Effects - Programmable shaders with support for physically based rendering (PBR), shadows, mirrors, bump mapping, and gamma correction for professional-grade visuals.
- Cross-Platform Deployment - Build and deploy the same project to Windows, Linux, macOS, FreeBSD, Raspberry Pi, iOS, Android, Nintendo Switch, and web browsers with minimal changes.
- IDE Integrations - Deep integration with Visual Studio Code (via extension), Lazarus (TCastleControl component and package registration), and Delphi (custom menu and engine path configuration).
Common Use Cases
- Developing cross-platform mobile games - A indie developer uses Castle Game Engine to build a 2D puzzle game with Spine animations and deploys it simultaneously to iOS and Android using the same codebase.
- Creating educational 3D simulations - A university professor designs interactive 3D physics demos using X3D models and the visual editor, then compiles them to run on student laptops and Raspberry Pi classrooms.
- Building console games with open standards - A small studio imports high-fidelity glTF assets from Blender into Castle Engine to develop a Nintendo Switch title with PBR lighting and custom shaders.
- Integrating game engines into existing Pascal codebases - A legacy Delphi developer adds 3D visualization to a scientific application using TCastleControl and the engine’s Delphi package integration.
Under The Hood
Architecture
- Follows a layered, component-based design with clear separation between scene graph, rendering backends, and X3D node implementations, enforced through abstract base classes and encapsulation.
- Implements constructor-based dependency injection to decouple core systems and enable seamless platform abstraction across VCL, Lazarus, and Delphi.
- Uses code generation to automate X3D node property implementations, ensuring type safety and consistency while reducing boilerplate.
- Isolates platform-specific integrations (OpenGL, VCL, Delphi) into separate units with conditional compilation, eliminating runtime overhead and preserving portability.
- Employs an event-driven architecture with publish-subscribe patterns to coordinate scene updates and state changes without tight coupling.
- Decouples the build system from core engine logic using external configuration files to maintain compatibility across multiple compilers and IDEs.
Tech Stack
- Built on Free Pascal Compiler with version-specific configuration files to optimize compilation and suppress warnings.
- Uses GNU Make and fpmake as primary build tools, with platform-aware detection for Linux, macOS, and Windows.
- Integrates deeply with Lazarus and Delphi IDEs through native project files and automatic manifest-driven project regeneration.
- Features a command-line build tool that abstracts compiler details and manages dependencies via a declarative manifest file.
- Entirely focused on native 2D/3D game development with no external databases or web frameworks, relying on minimal, self-contained dependencies.
Code Quality
- Organized into modular units with clear separation between engine logic, tests, and assets, following Pascal conventions consistently.
- Leverages strong static typing and explicit memory management to ensure type safety and prevent common runtime errors.
- Includes comprehensive unit tests covering core functionality like X3D parsing, image handling, and data compression.
- Employs robust exception handling and resource cleanup patterns, though without custom exception classes.
- Maintains consistent naming conventions and descriptive identifiers across the codebase.
- Features automated testing and asset validation, though lacks explicit static analysis or linting tooling.
What Makes It Unique
- Embeds 3D gizmo data directly as compiled Pascal arrays, enabling runtime access to interactive tools without external file dependencies.
- Automates X3D node generation from declarative specs, creating a dynamic, type-safe scene graph that evolves with the X3D standard.
- Provides native iOS/Android integration via build-tool plugins, exposing platform-specific services (Game Center, OpenAL, DBus) through unified Pascal APIs.
- Implements dynamic DBus and OpenAL-Soft EAX support on Android with runtime library loading and type-safe bitfield operators for advanced spatial audio.
- Embeds texture fonts as compiled arrays to eliminate runtime font loading and preserve visual quality across platforms.
- Automates the entire asset pipeline, converting external design assets into compiled code to enable single-binary deployment and zero-runtime asset dependencies.