Author: David Rager
Date: March 6, 2012
Version 0.1 of DjDoom has been released and can be downloaded from here.
DjDoom is a reference implementation for the original Doom game engine that I have been working on for a little while. The purpose of this project is to build a playable Doom engine from the original Linux source code with minimal changes necessary to build and run in a Windows environment.
This was created as a learning tool for me and I’m publishing this so it can be a learning tool for others. It is intended that this be a base for others to build and expand on.
I deliberately chose to not use any third party libraries to handle sound, input and graphics and instead used only what is usually available on a typical Windows platform. I use DirectX 8 for graphics and input (including keyboard, mouse and joystick).
The sound utilities took the most effort to write since Windows does not make it easy to play MIDI music and sound effects. Learning to use the Windows Multimedia APIs to play MIDI resulted in a few other articles on this blog.
The game engine is built on Windows using MinGW. You will also need the DirectX 8 SDK. Newer DirectX no longer includes Direct Draw and won’t work for this code. DirectX 8 SDK comes with Windows Game Programming for Dummies, Second Edition
which is where I got it from.
The original DooM code was released by iD Software under the GPL. The additions I made are released under a more permissive MIT license.
Author: David Rager
Date: October 25, 2011
Building a small DirectX application with MinGW I ran into this error (again):
C:/DXSDK/include/dmdls.h:81: error: declaration of `WLOOP _DMUS_REGION::WLOOP[1]'
C:/DXSDK/include/dls1.h:264: error: changes meaning of `WLOOP' from `typedef struct _rloop WLOOP'
I encountered this a few years ago (and completely forgot about it… almost). It took me a while to dig up the forum post where I had originally posted the solution to this problem. I’m bringing it back here so I can find it more easily. WLOOP
is typedef’ed in dls1.h
as:
typedef struct _rloop {
ULONG cbSize;
ULONG ulType; /* Loop Type */
ULONG ulStart; /* Start of loop in samples */
ULONG ulLength; /* Length of loop in samples */
} WLOOP, FAR *LPWLOOP;
The WLOOP
type is used in a struct in dmdls.h
:
typedef struct _DMUS_REGION
{
RGNRANGE RangeKey;
RGNRANGE RangeVelocity;
USHORT fusOptions;
USHORT usKeyGroup;
ULONG ulRegionArtIdx;
ULONG ulNextRegionIdx; /* If zero no more regions */
ULONG ulFirstExtCkIdx;
WAVELINK WaveLink;
WSMPL WSMP;
WLOOP WLOOP[1];
} DMUS_REGION;
It seems MinGW doesn’t like the member variable with the same name as its type. I changed the definition of the WLOOP
member variable to use the actual type rather than the typedef’ed alias:
typedef struct _DMUS_REGION
{
...
// WLOOP WLOOP[1];
struct _rloop WLOOP[1];
} DMUS_REGION;
Hope this helps.]]>
Author: David Rager
Date: August 11, 2011
Set up MinGW
This article will show you how to set up a MinGW DirectX development environment. First, you need to get the latest and greatest MinGW development environment. The easiest way to do this is to download and run the latest mingw-get-inst GUI installer. Select the directory to install MinGW. Make sure that this path contains no spaces. Select the C++ and MSYS optional components.
This will download and run the Command line installer. You will see a console window open while it downloads and installs the selected components. Once the installation completes you must add the MinGW bin/
directory to your path, for example C:\MinGW\bin
.
Start the MSYS shell by running C:\MinGW\MSYS1.0\msys.bat
. In this MinGW shell, run the /postinstall/pi.sh
script to establish bindings between the MinGW and MSYS installations. Just say yes.
Other packages may be installed manually following the manual install instructions found here.
Set up the DirextX SDK
Download the latest DirectX SDK. Microsoft likes to keep moving things around but as of this writing it can be found at this link https://msdn.microsoft.com/en-us/directx/. Run the installer and install to a directory without spaces, for example C:\DirectXSDK
.
The latest DirectX SDK is installed but it is not yet visible from within the MSYS environment. In the root directory /
, create an empty /dxsdk
subdirectory. This will be used as a mount point for the DX SDK. Edit the file /etc/fstab
and add the line “C:/DirectXSDK /dxsdk
“. The hard drive path and the mount point may be separated by any number of spaces or tab characters. Go to /dxsdk
and list the directory contents. If it is empty you probably have a typo in fstab
. Also, older MinGW versions did not automatically reload the mount points when fstab
was modified. You may need to exit your shell and restart it.
Build and run the test application
I borrowed the following test application from DirectX Tutorial.com. If everything was set up properly it should build and run with no modifications.
dxtest.cpp
Build the DirectX test application with the following command:
g++ dxtest.cpp -o dxtest.exe -I/dxsdk/include -L/dxsdk/lib -DUNICODE -ld3d9
The options are:
-o dxtest.exe
– specifies the output file
-I/dxsdk/include
– specifies additional include directories to search
-L/dxsdk/lib
– specifies additional library directories to search
-DUNICODE
– defines the UNICODE preprocessor symbol for unicode strings
-ld3d9
– link to the d3d9.dll
You can run the DirectX test application by typing:
./dxtest.exe
Note that if you try to run this program outside the MinGW environment, for example double clicking it in explorer, you may get a dialog box complaining about not being able to find libgcc_s_dw2-1.dll
. This is probably because you didn’t close explorer and open it again after you added MinGW to your path. Ensure that C:\MinGW\bin
is in your path. Explorer “should” pick up the change immediately but for some reason it doesn’t always. Close and reopen your explorer window.
This brings up an interesting point however. Our application is dependent on a dll shipped with the MinGW environment. If we are to redistribute our executable, we must also redistribute the dll or our users will not be able to run our application. One way to fix this is to link the gcc run time statically:
g++ dxtest.cpp -o dxtest.exe -I/dxsdk/include -L/dxsdk/lib -DUNICODE -ld3d9
-static-libgcc
This does however have the drawback that it has the potential to dramatically increase the size of our executable. Choose what works best for your situation.
Also note, now that we are able to run our application outside the MinGW shell, a console window opens up along with our application. This is ugly and not something we really want. To get rid of this console window we need to specify that we are building a windows application using the -mwindows
option:
g++ dxtest.cpp -o dxtest.exe -I/dxsdk/include -L/dxsdk/lib -DUNICODE -ld3d9
-static-libgcc -mwindows
Thats it! Have fun with DirectX and MinGW! These are the exact steps I’ve taken and they worked for me today. Tomorrow a new version of something might break things. Let me know what issues you uncover and I’ll try to keep this up to date.
Useful resources:
]]>