Thursday, 5 March 2015

Building TRueView in Visual Studio 2013

TRueView is a level viewer for Tomb Raider level files, *.PHD (TR1), *.TR2 (TR2/TR3) and *.TR4 (TR4).


It was written by Dr Yuri Zhivago and the C source code was released in 2000.

The program and its source code can be downloaded from, .

Download TRueView

To execute the program you either drag and drop a Tomb Raider level file onto TRueView.exe in windows explorer or run the program from a command prompt with a level file name or full path as an argument.

Drag and drop level onto TRueView

Run TrueView with level as commandline argument

See the readme included with the download for further instructions.

I will use the freeware Visual Studio 2013 Community Edition with the NuGet Package Manager extension installed to build TRueView.

Details about downloading Visual Studio and installing the NuGet Package Manager extension can be found in this post [link].

In Visual Studio go to File>New>Project from Existing Code to start the project wizard.
Select Visual C++ as the project type.

Visual C   project from existing code

Choose the “source” folder in the TRueView download as the project location and specify TRueView as the project name.

Set project location and name

Use Visual Studio to build the project and be sure to select “Console application project” as the Project type.

Create Console application

Use the default settings for the Debug and Release configuration settings.

Debug Configuration Settings

Release Configuration Settings

The project is opened in Visual Studio.

Project open in Visual Studio

TRueView uses the OpenGL Utility Toolkit (GLUT) which is an old toolkit for OpenGL but can still be found on the internet.

Instead of using GLUT I will use FreeGLUT which is a modern replacement for GLUT.

To use FreeGLUT in the project I will use the NuGet Package Manager to install it but because the NuGet FreeGLUT package doesn’t install correctly (the linker cannot find freeglut.lib) I will install the NuGet NupenGL Core package which includes FreeGLUT and some other toolkits (GLFW and GLEW) for OpenGL.

Install NupenGL package using NuGet

TRueView also needs the zlib library to decompress the data in Tomb Raider IV *.TR4 files so also use NuGet to install zlib for the project.

Install zlib package using NuGet

TRueView builds successfully with lots of warnings but running TRueView from Visual Studio only opens and closes TRueView’s console window because we didn’t provide a level file.

Go to Project>Properties and for All Configurations set Configuration Properties> Debugging>Command Arguments to the level filename.

If the level file is not in the Working Directory which by default is the directory containing the project file, change the Working Directory to the directory of the level file.

Since in my case the level file is in the project folder’s parent directory I change the Working Directory to two dots.

Debugging Command Arguments and Working Directory

When I opened karnak.TR4 from the Tomb Raider Level Editor (TRLE) distribution the level was incorrectly textured.

TR4 files incorrectly textured

To fix this, some code in TR2io.c needs to be changed.

Change line 1284 found in the ReadTR2Level function to “bitu16 Tile, flags;”.

Line 1284 original code

Line 1284 new code

Build and run TRueView again and this time the TR4 level is textured correctly.

TR4 file textured correctly

When you right click on TRueView’s 3D viewer a menu pops up with many options.

Context menu

Unfortunately this menu does not work correctly with FreeGLUT and the viewer closes when a menu item is clicked. You can, however, use the menu to see the shortcut keys for the options.

I do not yet know how to change the code so the menu works with FreeGLUT but will update this post when I do. (See update at end of post.)

One thing to note is that there are some limits in TRueView that may prevent it opening large levels.

In OpenGL.h the maximum number of room meshes is 250 and the maximum number of meshes is 768.

max num rooms

Increase these limits to open large levels although the best option would be to change the code so dynamic arrays are used.

When distributing TRueView be sure to include freeglut.dll and zlib.dll.

Output folder

Note in this case that glew32.dll and glfw3.dll and some other exes are present in the output folder because we installed the NupenGL package but these are not needed for TRueView.


To stop freeGLUT closing TRueView when the menu is used we need to register a glutMenuStatusFunc function.

We can use this function to update the menu when it is not in use.

The function is shown below.

And the function is registered in opengl_init.

Be sure to comment out UpdateMenuSelections in Menu_Base.

Even with these changes the menu does not behave as well as the original. Doesn't look as good and sometimes doesn't show permanently on a right click.

It may be better to use GLUT instead of freeGLUT.

Download the GLUT binaries and headers from here [link].

Use instructions for setting up GLUT found here [link] and remove the NupenGL Core package from the project using the TOOLS>NuGet Package Manager>Manage NuGet Packages for Solution>Installed Packages>Manage button.

Keep the code for updating the menu when the menu is not in use.

No comments:

Post a Comment