Start: Display a window

You need to initialize a rectangular area on the screen that will be able to display 3D content. There are two ways of doing this:

  1. Integration inside Lazarus form: Use our TCastleControl inside normal Lazarus form. You should choose this method if you want to integrate 3D area with normal GUI (Lazarus forms, controls) or if you're just more comfortable with dropping components on a Lazarus form.

    • Create new project (using Lazarus "New Project" menu item). Choose "Application".
    • Pick TCastleControl from the component palette (tab "Castle") and drop it on a regular Lazarus form.
    • Press "Run" :)

    There is no example code to show here, as you don't need to write any code to make this work :) In the following manual chapters we will show some code to run your game. You will usually want to place it inside the OnCreate event of the Lazarus form.

  2. Without using Lazarus forms: Use our own CastleWindow unit, that defines window class TCastleWindow. This avoids some problems with Lazarus application loop (for example, mouse look is smooth) and is suitable for desktops as well as Android/iOS.

    You can develop such programs using Lazarus, or any other text editor. The only real requirement is having a Free Pascal Compiler installed.

    To create an application using TCastleWindow in Lazarus:

    • Create new project using Lazarus "New Project" menu item.
    • Choose "Project->Simple Program" (or "Custom Application" in older Lazarus versions).
    • Using "Project->Project Inspector" window add a "New Requirement" and choose castle_base package.
    • Then add another requirement and choose castle_window package.
    • In this approach, you will not design your forms visually using Lazarus. But you will still use Lazarus as a powerful Object Pascal IDE, to edit and compile and debug your programs.

    If you don't use Lazarus, see the getting started for a description how to compile your project, so that FPC can find our units like CastleWindow.

    Place this source code in your program file (lpr).

    {$mode objfpc}{$H+} // you can also set ObjFpc and long strings in project compiler options
    uses CastleWindow;
      Window: TCastleWindow;
      Window := TCastleWindow.Create(Application);

    Compile and run this program and behold, a black window :)