Tag Archives: lazarus

The GoldSrc BSP Loader

Last updated on August 15th, 2018

This project is a program to load GoldSrc BSP files. The GoldSrc BSP file format has been derived from the id’s Quake 2 file format by Valve Software for their Half-Life game series.

It has been realized with

  • Lazarus, Free Pascal
  • SDL2, OpenGL.

 

The BSP Loader powered by Lazarus.
Loading a WAD file and displaying a selected texture from it.
Textured rendering of a scene (estate). The blue colorkey is not interpreted to be transparent yet.
Scene: Oilrig.
Scene: Assault.

02/08/2018, v0.1 alpha

  • Capabilities
    • Load BSP files and show contents of data lumps (exception: VIS Lump)
    • Load WAD files and render contained textures
    • Load BSP file and all WAD files which are necessary to render the fully textured scene
    • Navigate by simple camera through scene
  • To-Do’s
    • lightmapping from lightmap data
    • VIS Lump: treat it at all
    • collision detection
    • face culling
    • have spaces between textures in atlas texture to prevent bleeding-effect (esp. in tiled textures recognizable)
    • make blue colorkey transparent
    • sky cube
    • release the source code (if beta stadium reached)

Important Sources

BSP and WAD File Formats

I cannot state how important these documents were in understanding the structure of the BSP and WAD file formats. Without them, this project wouldn’t have been possible.

Matrix and Vector Functions

I used the SupraEngine.Math Unit by Benjamin ‘BeRo’ Rosseaux (benjamin@rosseaux.com) for this.

Implementation Hints

Chapter 1a: Compilation and configuration of Lazarus (JEDI-SDL)

This is an SDL 1.2 chapter. SDL 1.2 is obsolete since it has been replaced by SDL 2.0. Unless you have good reasons to stay here you may prefer to go for the modern SDL 2.0 :-).

Before you start following the instructions given here to install Lazarus make sure you really need it. The Lazarus package is completly independent of SDL. If you are not interested in a DELPHI-like RAD (Rapid Application Development) tool skip this chapter. You could come back later after you finished all SDL chapters :). This chapter isn’t required to do the following chapters.

Otherwise the combination of Free Pascal together with the SDL Library and Lazarus’ abilities can lead to a very flexible and highly powerful development environment. The advantages of Free Pascal, like OS independence, open source code, a license which allows you to develop commercial programs (license: LGPL), and so on apply for Lazarus, too! Furthermore you gain all advantages modern OS and IDE provide. The DOS-like IDE of the Free Pascal compiler is legendary but nowadays not too comfortable anymore. The Lazarus environment provides a flexible and comfortable IDE.

The following description on how to compile/install and configure Lazarus is for WINDOWS ONLY. I am sorry that I am currently not able to make such a description to linux users. Any reader is welcome to send me one, so I could publish it here (you would get full credit of course). Futhermore it is necessary that you have installed Free Pascal.

The following table describes what software you will need additionally to the Free Pascal compiler:

Software Version Size, MB Source Description
Lazarus source files Latest revision depends directly through SVN How to get them will be described next!
TortoiseSVN 1.4.7 ~2 http://tortoisesvn.net/ Download the latest version of SVN client (except you already have such a client).
fpcbuild-2.2.0.zip 2.2.0 ~38 http://www.Free Pascal.org Download the latest source files of the Free Pascal compiler. Go to “Download” and scroll down to “Source”.

Now let’s begin. First of all I want you to know that there are some binaries downloadable from the official Lazarus page. These binaries shouldn’t be used because they are very old and the resulting Lazarus environment is terribly unstable! The environment is much more improved and gets improved daily. So I advise you to get the latest development state through SVN (it’s like the outdated CVS). If you neither know SVN nor CVS here a short description: SVN provides the latest state of development and ensures that any of several hundreds developers of a project (like Lazarus) is working on the latest version. Whenever a developer is changing anything at the project SVN generates a new revision number. Today the revision number of Lazarus is 13688.

How to get the latest development state (revision) of lazarus then? – That is described very clearly and easy here: http://wiki.lazarus.FreePascal.org/index.php/Getting_Lazarus. Therefore I will just describe short how to get it.

1) get the mentioned SVN client (TortoiseSVN) for Windows and install it

2) create a directory where you want to have Lazarus installed later (e.g. C:\FPC\Lazarus)

3) right-click on the new created lazarus folder and chose “SVN Checkout…”; you get the following window

Lazarus SVN Checkout window4) type in field URL of repository: “http://svn.Free Pascal.org/svn/lazarus/trunk” (without quotationmarks) as shown in the picture above; if you use a command line client (e.g. Subversion you have to type “svn co http://svn.Free Pascal.org/svn/lazarus/trunk lazarus” (without quotationmarks))

5) click “OK”

6) another window pops up called “trunk – SVN Checkout…”; now it will take some minutes; after all files got downloaded you receive a window similar to this:

Lazarus finished checkout(you can go on reading while waiting)

The files you download through SVN aren’t binaries. That means you have to compile them. The compiler you use to do so is the Free Pascal compiler of course (that is why you should have it installed already).

7) If the downloading is finished you have to go to the folder where all the files are placed, e.g. C:\FPC\lazarus\.

8) Now you have to run a command line tool like “cmd”. Choose “Start” and then “Run…” from Windows’ start menu.

9) Enter “cmd” or “command.com” (latter only if “cmd” doesn’t work) in the next pop-up window and click “OK”. Now a window like this should pop up:

Command window cmd.exe for make procedure10) Go to the directory where you downloaded the Lazarus files. (Use the DOS commands “cd [directory]” and “cd..” to enter or leave directory.)

11) When you entered the directory (C:\FPC\lazarus\) just type “make” and the make.exe of your Free Pascal compiler will compile Lazarus for you. Now relax and wait some minutes.

If this doesn’t work for you, you should try to copy the make.exe from your Free Pascal compiler (located in bin directory) to the Lazarus directory (or you could check if you set the environment variable/user variable PATH=C:\FPC\2.2.0\bin\i386-win32 in system control)

12) After successful compilation there should be a Lazarus.exe and a Startlazarus.exe right in the lazarus directory. Use Startlazarus.exe to run your brand new RAD tool :). After passing some error messeges you should get something similar to this:

Lazarus editor if installed successfully13) close Lazarus

The next steps describe how to configure Lazarus together with JEDI-SDL. This includes telling Lazarus where to find Free Pascal compiler, where to find Free Pascal source files and where to find JEDI-SDL units. ATTENTION: It is necessary to have the source files of Free Pascal, otherwise Lazarus won’t run properly. If you installed Free Pascal and JEDI-SDL as described in Chapter 1 you don’t have the source files because they are not included in the binary package. Fortunately this doesn’t matter because you can download them separately. If you already have the source files for some reason you can skip step 14 and 15.

14) Download the latest source files of the Free Pascal compiler (usually it doesn’t matter if the version of the source files differ slightly from the version of actual compiler).

15) Now extract the file. It doesn’t matter where the source files are located but you may prefer a folder like “C:\FPC\2.2.0\source\”.

16) The extraction generates a folder “fpcbuild-2.2.0”. The whole path should be “C:\FPC\2.2.0\source\fpcbuild-2.2.0\”.

17) Now run Lazarus and skip any error message. Go to “Environment” in the menu.

Lazarus editor environment options
Choose “Environment options” from the tab. The following window should come up.

Environment options window18) The text field “Lazarus directory (default for all projects)” should be filled with your Lazarus path, if not do so. The text field “Compiler path (ppc386.exe)” should be filled with your Free Pascal compiler path, if not do so.

19) The text field “FPC source directory” is probably empty. The sources are needed for Lazarus to compile projects successfully. Fill in the path where you extracted the source files in step 15. If you followed my suggestion the correct path would be “C:\FPC\2.2.0\source\fpcbuild-2.2.0\fpcsrc\”. Confirm by clicking “OK”.

20) If you haven’t done any mistakes there shouldn’t be any error anymore if you close and restart Lazarus.

21) If you didn’t install SDL manually you can skip steps 21 and 22, you are finished then! Now let’s tell Lazarus where to find the JEDI-SDL units. Go to “Project” in menu.

Lazarus compiler optionsChoose “Compiler Options…” from the tab. The following window should come up but without any entry in the text field “Other Unit Files (-Fu) (Delimiter is semicolon);”.

Lazarus compiler options window22) Enter the path to the JEDI-SDL units. If you installed JEDI-SDL as mentioned in Chapter 1 you should enter “C:\FPC\2.2.0\units\JEDI\SDL\Pas”. Now you are ready to write Free Pascal programs in Lazarus using JEDI-SDL. Note: The environment settings are saved for any project but the compiler settings (steps 20-22) are just related to the current project so you have to set the unit path to JEDI-SDL units separate for each project.

Now you have a brand new RAD tool installed. Well done! This tool you can use to write just plain Free Pascal or/and Free Pascal/SDL programs. You also can combine these programs with the features typical RAD kits provide but to learn how to use those features is described anywhere else. Have fun.