A Direct3D Version of TdemoThe Tdemo example brings together many 3D capabilities in a single program. We can link Tdemo with Fastgraph's DirectX libraries to build a Direct3D version through conditional compilation. We do this by defining the symbol DIRECT3D when compiling each Tdemo source code file. All of the Tdemo conditional compilation sequences are identical or very similar to those in the TMcubeX example, with one notable exception. The textures stored in Tdemo.tmf use the normal 5/6/5 high color pixel format. When Tdemo is compiled as a Direct3D program, its _LevelData:ReadTextures() function calls fg_gethcbpp() to obtain the DirectX high color bit depth. If fg_gethcbpp() returns 15, it means DirectX expects high color pixels to use the 5/5/5 format, so we must call fg_transdcb() to translate each texture bitmap from 5/6/5 to 5/5/5 immediately after reading it from the Tdemo.tmf file. Another interesting feature of Tdemo shows something that might be desirable if we want to run the program on systems where DirectX isn't available. The batch files in the Tdemo directory create both a native Win32 executable and a Direct3D executable through conditional compilation. Because we can easily create both versions from the same source code, you could distribute both executables as part of a product distribution. If the Direct3D version determines that DirectX is not available on the user's system, it launches the native version and exits.
|
 
copyright 2001 Ted Gruber Software, Inc.