A Direct3D Retained Mode Example in BCB4

Par: Charles Calvert

Résumé: This example shows how to convert one of the more complex examples from the Microsoft DirectX 6.0 SDK into a C++ Builder project.

A Direct3D Retained Mode Example in BCB4

Download Project Source

This example shows how to convert one of the more complex examples from the Microsoft DirectX 6.0 SDK into a C++ Builder project. The only change I made to the code of the project itself was to add a few #pragma argsused to suppress at least some of warnings emitted by the Microsoft code.

To use the code shown in this example you must have a copy of the Microsoft DirectX SDK on your system. As of June, 1999, you could purchase the DirectX SDK from the www.microsoft.com/DirectX site for under $10. If you have a T1 or faster line, you can also download all 80+ MB of the SDK.


Figure 1: The FlyFS example from DirectX 6.0 SDK is a full screen Direct3D program that compiles unchanged in C++Builder 4.0.

The FlyFS Direct3D example from the DirectX SDK shows a rocketship traveling over a mountainous landscape. In windowed mode, the program, compiled under BCB, performed at about 180 frames per second, and in full screen exclusive mode, it ran at about 60 frames per second. This was on a Dell 266 with a RIVA TNT card. The Microsoft version that shipped with DirectX SDK ran at nearly identical frame rates.

The FlyFS example does not ship with a standard Microsoft project file, so it cannot be converted automatically into a standard Borland IDE project. Instead, you must take about 2 or 3 minutes to convert the project to yourself. The point of this article is to show you the steps you need to take to convert the project.

I got started by creating a BCB 4.0 console application for a Windows GUI by choosing File | New | Console | Windows GUI. I saved this project under the name FlyFS.bpr in the FlyFS directory created by the Microsoft DirectX 6.0 SDK install. I pasted in the code from the main Microsoft CPP file into my main project file. The Microsoft CPP file I block copied the code from was called rmfull.cpp. I choose this file as my main file because it contained the WinMain proceedure.

I then deleted any of the DirectDraw headers that shipped in the Borland C++Builder include directory. To delete the files, I opened up the Microsoft DirectX SDK include directory in a DOS box and piped a dir of the directory into a file called DelDraw.bat: dir > deldraw.bat. Then I edited the file so that it looked like this:


del  d3d.h
del  d3dcaps.h
del  d3drm.h
del  d3drmdef.h
del  d3drmobj.h
del  d3drmwin.h
del  d3dtypes.h
del  d3dvec.inl
del  ddraw.h
del  dinput.h
del  dls1.h
del  dmusicc.h
del  dmusicf.h
del  dmusici.h
del  dplay.h
del  dplobby.h
del  dsetup.h
del  dsound.h
del  dvp.h
del  dxfile.h
del  dxsdk.inc
del  foo.bat
del  multimon.h
del  rmxfguid.h
del  rmxftmpl.h
del  rmxftmpl.x

I saved this file in the BCB4/Include directory and ran it, so that I could delete any DirectX headers we shipped with BCB4. The headers we shipped may be out of date, and I wanted to use the most recent headers from Microsoft. So I first deleted all the headers we shipped with the product.

I then selected Project | Options | Directories/Conditionals and put the include directory for the Microsoft DirectX sdk on my include path. I also added the DXGuid.lib file from the Microsoft DirectX lib directory to my project. Finally, I added all the CPP, C and rc files from the FlyFS directory of the Microsoft SDK to my project, being careful to omit the rmfull.cpp file, since I had already copied its contents into my main cpp file.

At that stage, I was ready to go. I did a quick compile and link, then was able to run the project with no trouble. The point of the exercise was to show both that you can compile the Microsoft DirectX SDK in BCB4, and also to demonstrate the great work the BCB team has done in making sure our compiler handles a wide variety of Microsoft specific code.

I personally do not have time to answers questions about this technology, but if you want to make suggests, or you have bug reports on this article that you want to submit, then you can send mail to Charlie Calvert


Réponse serveur de: ETNASC02