3D Game Engine Programming Book's Contents and Errata
Unfortunately it seems that some file on the accompanying CD-ROM are broken or corrupted.
Furthermore there had been no compiled static or dynamic libraries provided which are
developed throughout the book. As a result you cannot just run each chapter's demo but
you have to build the libraries first. I apologize for any inconvinece caused.
On this website you will find all the answers and solutions that will make the demos
run. Additionally there is a small update to the code for chapter 6 to be able to
compile the font functions with the latest DirectX SDK because its interfaces were
changes from DirectX 9.0a to 9.0b.
If you have any comments or questions feel free to drop me a message by mail
Stefan.Zerbst@zfx.info or come to visit the
online game devloping learning place Gameversity
where I also offer courses on DirectX and game programming. Contents of this Website 1. Download Update Files (for the first print of the book) 2. How to Compile the Code from the accompanying CD-ROM
3. Changes to the D3DXFont interface in DirectX 9.0b (for the first print of the book) HRESULT ZFXD3D::CreateFont(const char *chType, int nWeight, bool bItalic, HRESULT ZFXD3D::DrawText( UINT nID, int x, int y, UCHAR r, 4. Download the Milkshape .ms3d to CBF Converter 5. Known issues (for the first print of the book)
Check out at Amazon: click me
1. Download Update Files
2. How to Compile the Code from the accompanying CD-ROM
3. Changes to the ID3DXFont Interfaces (chapter 6)
4. Download the Milkshape .ms3d to CBF converter (chapter 8)
5. Known issues
6. Editor Crash on Level Saving NEW
7. Reported Bugs NEW
Last Update: 9th September 2004 (Download Chap13 Data, Know Issues)
The following update download contains a replacement cpp file for chapter 6 as well as a new level file for use in chapter 14 and chapter 15. The source code file of chapter 6 had been updated to be compilable with the changed D3DXFont interface of the DirectX SDK version 9.0b or greater.
Download ZIP file (600 kb)
The second download contains a new model file alien.cbf and again the new level file. Both are meant for chapter 15 because the files on the CD-ROM seem to be broken. You can just copy the original chapter 15 directory from the CD-ROM and then copy the contents of this download to replace the ones copied from the CD-ROM. The download is fairly big because it also contains the compiled static libraries and dynamic libraries you wil lneed in this chapter. So you can just compile and start it after the update.
Download ZIP file (1.6 MB)
The third download contains the test data used in the space partitioning demo in Chapter 13 because it seems that the file is also broken on the CD-ROM. Just copy this one into the Chapter 13 folder to replace the original one.
br>
Download ZIP file (130 kb)
No source code.
No source code.
There are two directories called "Demo" and "ZFXRenderer". First go to the "ZFXRenderer" directory and open the ZFXRenderer.dsw work space with Visual Studio. It contains two projects named "ZFXD3D" and "ZFXRenderer". Compile both projects in arbitrary order.
Now you will find the "ZFXRenderer.lib" file in the subdirectory "ZFXRenderer/debug" or "ZFXRenderer/release" depending on the compilation version you choose. The subfolder "ZFXRenderer/ZFXD3D", which contains the DLL project, will contain a "/debug" or "/release" folder as well in which you can find the "ZFXD3D.dll" file.
You need to copy the "ZFXRenderer.lib" file and the "ZFXD3D.dll" file to the chapter's "demo" directory. Then you can open the "Demo.dsw" work space with Visual Studio and compile and run the demo application.
This is the math chapter that uses SSE assembler code. Please read the IDE / compiler setup descriptions in the chapter. Your compiler needs t obe able to compile SSE assembler codes which is true for Visual C++ 6.0 Pro / Enterprise with certain service and compiler packs installed or version 7.0 or greater. If your compiler does not support SSE assembler then you need to remove all SSE code paths from the concerned source files (namely zfxcpu.cpp, zfxvector.cpp, and zfxmatrix.cpp). Then you can open the "zfx3d.dsw" work space.
I used Visual C++ 7.0 Standard Edition to compile the SSE assembler sources, hence you will find the "zfx3d.sln" work space file. After compilation you will find the "zfx3d.lib" file in the compilation directory (called "zfx3d_Win32_Release" in this case). This is the engine's math library. There is no demo demonstrating the math functions, but you need to copy this library to all remaining projects using the engine.
No complete source code project.
In this chapter you will enhance the "ZFXRenderer.lib" and the "ZFXD3D.dll". Just follow the same instructions that applied to chapter 3. For the remainder of the book use the files from this chapter if the renderer is needed. Chapter 3 was only the introduction into this topic but its libraries are not used except for the chapter 3 demo itself. Now you also have to copy the math library "zfx3d.lib" to the "ZFXRenderer" directory in this chapter or otherwise you will get a linker error.
Note that the new DirectX SDK releases (summer update) use a slightly different way of creating the fonts so you need to change the original code in order to compile the "ZFXD3D.dll". Check the according section of this document.
After compiling the renderer lib and dll copy boths files to the "/demo" directory of this chapter. Additionally, you also have to copy the "zfx3d.lib" math library into this directory.
Now open the "demo.dsw" work space and compile it. If it fails to open the include file "#include "..\zfx3d.h" then change this line to "#include "zfx3d.h". Then you can compile and run the demo.
There are six subdirectories in this chapter's directory. Each of them containing one demo project with a certain vertex or pixel shader. You have to copy the engine's files "ZFXRenderer.lib", "ZFXD3D.dll", and "zfx3d.lib" into each of the subdirectories. Then you can go into each subdirectory, open the corresponding *.dsw work space, compile, and run the demo.
Note that there seems to be a problem with samples 2, 3, 4, and 6 which show nothing with the new DirectX SDK Summer Update. We're on it and an update on this will follow.
This chapter was written by the co-author hence there is a slightly changed project directory setup. You have to copy "ZFXRenderer.lib" and "zfx3d.lib" into the "/lib" subdirectory, the "ZFXD3D.dll" goes into the "/release" subdirectory. Then you can compile and run the program. If the program crashes during loading the model then the alien.cbf file on the CD-ROM might be broken. Then use the one from the download at the top of this page.
There are two directories called "Demo" and "ZFXInput". First go to the "ZFXInput" directory and open the ZFXInput.dsw work space with Visual Studio. It contains two projects named "ZFXDI" and "ZFXInput". Compile both projects in arbitrary order.
Now you will find the "ZFXInput.lib" file in the subdirectory "ZFXInput/debug" or "ZFXInput/release" depending on the compilation version you choose. The subfolder "ZFXInput/ZFXDI", which contains the DLL project, will contain a "/debug" or "/release" folder as well in which you can find the "ZFXDI.dll" file.
YOu need to copy the "ZFXInput.lib" file and the "ZFXDI.dll" file to the chapter's "demo" directory. Then you can open the "Demo.dsw" work space with Visual Studio and compile and run the demo application.
Note that there is a bug in the demos's ProgramStartup() function. While initializing the input device g_pDevice the second parameter must be a const pointer. Just add the "&" address operator: g_pDevice->Init(g_hWnd, &rcCage, true)
There are two directories called "Demo" and "ZFXAudio". First go to the "ZFXAudio" directory and open the ZFXAudio.dsw work space with Visual Studio. It contains two projects named "ZFXDA" and "ZFXAudio". Compile both projects in arbitrary order.
Now you will find the "ZFXAudio.lib" file in the subdirectory "ZFXAudio/debug" or "ZFXAudio/release" depending on the compilation version you choose. The subfolder "ZFXAudio/ZFXDA", which contains the DLL project, will contain a "/debug" or "/release" folder as well in which you can find the "ZFXDA.dll" file.
YOu need to copy the "ZFXAudio.lib" file and the "ZFXDA.dll" file to the chapter's "demo" directory. Then you can open the "Demo.dsw" work space with Visual Studio and compile and run the demo application.
Note that since the last SDK update release theire might come up an error saying that DWORD_PTR is an undefined symbol that is used in a DirectSound header. To avoid this you can just add a define at the top of the "ZFXDA.cpp" file like so:
#include
#ifndef DWORD_PTR
#define DWORD_PTR DWORD*
#endif
#include "ZFXDA.h" // class definition
There are two directories called "Demo" and "ZFXNetwork". First go to the "ZFXNetwork" directory and open the ZFXNetwork.dsw work space with Visual Studio. It contains two projects named "ZFXWS" and "ZFXNetwork". Compile both projects in arbitrary order.
Now you will find the "ZFXNetwork.lib" file in the subdirectory "ZFXNetwork/debug" or "ZFXNetwork/release" depending on the compilation version you choose. The subfolder "ZFXNetwork/ZFXWS", which contains the DLL project, will contain a "/debug" or "/release" folder as well in which you can find the "ZFXWS.dll" file.
YOu need to copy the "ZFXNetwork.lib" file and the "ZFXWS.dll" file to the chapter's "demo" and "demo2" directories. Then you can open the "Demo.dsw" work space with Visual Studio and compile and run the demo applications.
In this chapter there is only the small helper library "ZFXGeneral.lib" but no demo application. You can simply open the work space and compile the project. Then you will find the "ZFXGeneral.lib" in the "/debug" or "/release" subdirectory depending on the build settings. You need to copy this library for later chapters.
This chapter contains two subfolders named "zfx3d II" and "Space Partitioning Demo". The first one is an extended version of the chapter 4 math library. Compile it following the instructions given for chapter 4. From now on only use this new math library for later projects.
Then open the space partitioning demo work space and compile the project. In order to do so you have to copy the following libraries into the work space directory:
- ZFXD3D.dll
- ZFXRenderer.lib
- ZFXGeneral.lib
- zfx3d.lib (II)
This chapters contains several subdirectories to organize the project. Copy the following libraries to the "/lib" subdirectory:
- zfx3d.lib (II)
- ZFXGeneral.lib
- ZFXInput.lib
- ZFXRenderer.lib
Then copy the corresponding dynamic link libraries right into the chapters main directory containing the work space:
- ZFXDI.dll
- ZFXD3D.dll
Now open the work space "PanBox.dsw" and compile and run it. After opening a level file the views are not updated automatically. Just left click somewhere in the gui or the render views and the level will be displayed.
This chapters contains several subdirectories to organize the project. Copy the following libraries to the "/lib" subdirectory:
- zfx3d.lib (II)
- ZFXGeneral.lib
- ZFXInput.lib
- ZFXRenderer.lib
- ZFXAudio.lib
- ZFXNetwork.lib
Then copy the corresponding dynamic link libraries right into the chapters main directory containing the work space:
- ZFXDI.dll
- ZFXD3D.dll
- ZFXDA.dll
- ZFXWS.dll
Now open the work space "Pandoras Legacy.dsw" and compile and run it. After selecting "server" or entering the server's IP address and selecting "client" in the displayed dialog box the typically graphics selection dialog appears. But it might be that it is in the background behind your Visual Studio window so minimize all windows on the desktop if you cannot see this dialog. If you have a firewall active than turn it off or allow this application to access the network.
There must be an instance of the application running as server before a client can connect, of course.
bool bUnderline, bool bStrike, DWORD dwSize,
UINT *pID)
{
HRESULT hr;
HDC hDC;
int nHeight;
if (!pID) return ZFX_INVALIDPARAM;
hDC = GetDC( NULL );
nHeight = -MulDiv(dwSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
ReleaseDC(NULL, hDC);
m_pFont = (LPD3DXFONT*)realloc(m_pFont, sizeof(LPD3DXFONT)*(m_nNumFonts+1));
// build D3DX font from GDI font
hr = D3DXCreateFont( m_pDevice, // Direct3D device
nHeight, nHeight/2, // font height and width
nWeight, // thickness, 0=default, 700=bold
1, // mipmap levels
bItalic, // italic style
DEFAULT_CHARSET, // character set
OUT_DEFAULT_PRECIS, // precision
DEFAULT_QUALITY, // quality
DEFAULT_PITCH | FF_DONTCARE, // pitch and family
"Arial", // font face (=font type)
&m_pFont[m_nNumFonts]); // address for new font
if (SUCCEEDED(hr))
{
(*pID) = m_nNumFonts;
m_nNumFonts++;
return ZFX_OK;
}
else return ZFX_FAIL;
} // CreateFont
/*----------------------------------------------------------------*/
UCHAR g, UCHAR b, char *ch, ...)
{
RECT rc = { x, y, 0, 0 };
char cch[1024];
char *pArgs;
// put variables into the string
pArgs = (char*) &ch + sizeof(ch);
vsprintf(cch, ch, pArgs);
if (nID >= m_nNumFonts) return ZFX_INVALIDPARAM;
// calculate actual size of the text
m_pFont[nID]->DrawText(NULL, cch, -1, &rc, DT_SINGLELINE | DT_CALCRECT, 0);
// now draw the text
m_pFont[nID]->DrawText(NULL, cch, -1, &rc, DT_SINGLELINE,
D3DCOLOR_ARGB(255,r,g,b));
return ZFX_OK;
} // DrawText
/*----------------------------------------------------------------*/
It seems that using the latest video drivers solves this issue
- Chapter 13: Does not display anything with DirectX SDK summer update 2004
6. Editor Crash on Level Saving
While going back to the files supplied on the CD-ROM I found that there is indeed a problem while saving a level. There seems to be an old ZFXRenderDevice.h header used, causing a function call to the skin manager to hit the wrong function implementation because the library features one function that the old header does not know about.
The three functions ZFXDA:SetSoundPosition, ZFXDA:SetSoundDirection, and ZFXDA:SetSoundMaxDist use the counter m_NumSounds
to access the array of sounds. This is an error because the id passed in as parameter to the function has to be used. The
error occurs in the book (page 500, 501) as well as in the source code.