XNA Tutorial 1 translated to Delphi Prism

Posted by on in Blogs
There was a couple of interesting comments to my question regarding options for writing games in Delphi.

The XNA Game Studio 3.0 online documentation contains tutorial projects. I thought it would be cool to create a Delphi Prism version of "Tutorial 1: Displaying a 3D Model on the Screen". This means translating from C# to Oxygene, the programming language used by Delphi Prism, which is very similar, but in some respects different, from Delphi (or "Object Pascal") language used in Delphi 2009. The tutorial consists of the following four steps: "Downloading the Art Assets", "Creating the New Project", "Load the Model by Using the Content Pipeline", and "Display the Model on the Screen (and Make It Rotate)".

The objective of the tutorial is to create an application that displays a rotating space ship. The space ship and its texture were created in a separate environment for 3D modeling that generates *.fbx files that contain geometrical information and are available for download as part of the tutorial. I have installed Delphi Prism into VSShell 2008 (that comes with Delphi Prism) and then installed XNA Game Studio 3.0 which discovered Delphi Prism and installed into it. All the XNA .NET assemblies has been installed and "XNA Game Studio Device Centre" added to "Tools" menu.

The first step is to create a "Console Application" in Delphi Prism and add references to XNA assemblies that contain types that we are going to use in our code. The XNA application is basically a definition of a new game type that is derived from "Microsoft.Xna.Framework.Game" type that provides basic functionality to a new game. The "Game" type is defined in the same named .NET assembly that needs to be referenced in the project. Here is the Oxygene version of XNA Tutorial 1 project.

The main game is defined in the "Game1.pas" unit. Note that Oxygene is more like C# in handling namespaces. In Delphi the unit physical filename should be the same as the unit name in source code. In Oxygene that physical filename of the unit is only important to the build engine.

This code compiles fine but it fails to load a model at runtime. The reason is that the model file needs to be processed and compiled and located in a subfolder where our executable can find it.

The XNA 3 provides a concept of "Content Pipeline", which takes binary art assets and compile them into a format that XNA application can load and display. If you look into the contents of the tutorial zip file there is a subdirectory called "Content" that constains "content.contentproj" file. This is a special "content" sub-project that needs to be compiled before running our Oxygene application. The Delphi Prism does not know about this project format, however it is compatible with MSBuild and it is possible to build this project from command-line. On my XP machine "MSBuild.exe" can be found in "c:\WINDOWS\Microsoft.NET\Framework\v3.5" directory. You need to pass "content.contentproj" as a parameter to MSBuild and invoke it from command-line to compile art assets for our application. After the build is complete you will be able to find two .xnb files under the "Content" directory. This directory and its contents needs to be copied to a output directory of our Delphi game.

It is a manual process that could probably be easily automated, but I just want to see that spaceship rotating in my Delphi Prism XNA 3 application.

It was not initially obvious to me how to compile art assets and I found "stackoverflow.com" really helpful. It is really a great site where programmers are asking very specific questions and receive very specific answers. I "really" like it:-)
Gold User, Rank: 9, Points: 364
Crazy about Delphi Programming!
Comments are not available for public users. Please login first to view / add comments.