Getting DirectX 8.1 to Work with Dev-C++ 126.96.36.199
I have noticed that many people would like to know how to use DirectX with Dev-C++ because the beta version of Dev-C++ does not seem to work with DirectX very well until you do some tweaking and
the official Dev-C++ site itself does not provide much help. So, I will write about how to get the free Dev-C++ compiler to work with DirectX
8.1 and thus, provide the user with a major tool that is needed to code state-of-the-art games . Now, even my game engine (www.Sherman3D.net/download/files/VFVer1.zip) is fully compilable in Dev-C++
Want to know how? Then follow these easy steps (they might look simple now but it took a lot of trial and error):
- Install Dev-C++
- Use the "Check for Updates/Packages" option in the Tools menu.
- Download the Direct9 package (which also includes DirectX 8.1)
- Select the "Project Options" item from the Project menu. Click on the Parameters tab.
- In the "Linker" section, click on "Add Library or Object" and add the necessary library files for DirectX. Here is what my list looks like:
-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32../../../Dev-Cpp/lib/libdsound.a../../../Dev-Cpp/lib/libdxguid.a../../../Dev-Cpp/lib/libd3d8.a../../../Dev-Cpp/lib/libd3dx8d.a../../../Dev-Cpp/lib/libd3dxof.a../../../Dev-Cpp/lib/libdplayx.a../../../Dev-Cpp/lib/libwinmm.a../../../Dev-Cpp/lib/libdxapi.a../../../Dev-Cpp/lib/libwsock32.a../../../Dev-Cpp/lib/libdinput8.a../../../Dev-Cpp/lib/dinput.lib../../../Dev-Cpp/lib/strmiids.lib
As you can see, I am using Direct3D, DirectSound, DirectPlay, DirectInput and DirectShow. There are a few other necessary Windows libraries as well. I also added dinput.lib from the MicrosoftDirectX 8.1 SDK (download it from Microsoft's site) because the one included with Dev-C++ (libdinput.a) seems to be missing some required data formats. The strmiids.lib, a DirectShow library forplaying cutscenes, is not present in Dev-C++ so I added it from the DirectX 8.1 SDK as well.
- You are bound to run into compile time errors as the *.a DirectX library files that come with Dev-C++ have some typo errors in them. They are usually quite easy to fix though. Here is an example:
Error message: something or other already defined in example.hReason: #ifdef _EXAMPLE_Correction: #ifdef _EXAMPLE_H
I can't really remember the exact typos as I corrected all of them without keeping the original files.
In dxfile.h, delete the last line.
In dmdls.h, change #ifndef MAKE_FOURCC to #ifndef MAKEFOURCC
In dmdls.h, change WLOOP to Wloop;
In strmif.h, change #ifndef _WINGDI_ to #ifndef _WINGDI_H
- The biggest problem for me was getting DirectShow to work. First of all, comment out all the VMR stuff in strmif.h. I seem to get a GUID conflict if I don't. So just comment out lines20551-20556, 28733-28759, 28759 till 28945. It is going to be a tedious process as there are many /**/ in between and you need to do a // for each line lest you miss out one of those #endif's like Ioriginally did >_<.
- Another DirectShow problem is that you need to include atlbase.h to for automatic conversions from char to wchar but Dev-C++ doesn't come with atlbase.h. I did the filename conversion manuallyusing a Win32 function. Replace wcscpy(wFileName, lpszMedia); (the function that is used by the DirectShow examples in the SDK) with
MultiByteToWideChar(CP_ACP , // code pageMB_PRECOMPOSED, // character-type optionslpszMedia, // address of string to map-1, // number of characters in stringwFileName, // address of wide-character bufferMAX_PATH // size of buffer);
- Dev-C++ doesn't seem to support the allocation of memory space with the "new" command using a variable for the size of memory to allocate. So, if you have something like this:
m_Polygons = new sPolygon[m_NumPolygons]();
Replace it with:
(void*)m_Polygons = malloc(m_NumPolygons*sizeof(sPolygon));
- Dev-C++ uses the debug libraries of DirectX so please put d3dx8d.dll (which can be found in the DLL subdirectory of Dev-C++) in your program's directory when you distribute it.
- If you are using Windows resource files (*.rc), make sure to include "windows.h" in the resource file itself and remove any reference to "afxres.h". Open the resource header file, "resource.h"and write a definition for IDC_STATIC in the list.
There might be some other minor complications when using Dev-C++ with DirectX 8.1 so please post your questions at http://forum.Sherman3D.com and I will
try to help the best I can.