DirectX SDK 2D Examples With Borland C++.

Author : Joop Vossers
Date : 29 January 1997
Draft : 1.2

Disclaimer: This document is created as an aid for those who are experiencing difficulty using the DirectX SDK (version 2) with Borland C++. Although I have taken care to ensure that this document will resolve the technical issues at hand, I cannot be held responsible for losses or damages resulting from the use of this document.

This document covers the ddex1-ddex2, donut, fastfile, flip2d, foxbear, palette, stretch and wormhole examples which are part of the DirectX 2 SDK. Follow the next steps carefully to let the DirectX examples run with Borland C++. The examples where tested with the DirextX 2 SDK and Borland C++ Version 4.52, but it should work with newer releases of the SDK or the compiler.

Implib

Create directories:
  • md \dxsdk\sdk\binc (Borland Include)
  • md \dxsdk\sdk\blib (Borland Library)

    Copy Header File:

  • Copy \dxsdk\sdk\inc\*.h \dxsdk\sdk\binc

    Create import libraries.

  • cd \dxsdk\sdk\blib
  • implib d3drm.lib \windows\system\d3drm.dll (*)
  • implib ddraw.lib \windows\system\ddraw.dll
  • implib dplay.lib \windows\system\dplay.dll (*)
  • implib dsound.lib \windows\system\dsound.dll

    If you have created these four libraries without getting an error, you can skip the next section and goto the "ddraw.h" section.

    (*)My Implib utility give an error on d3drm.dll and dplay.dll. To create these two libraries put the following data into a .def file and run implib. These two libraries are not necessary for the following examples but you need them for the 3D examples.

    D3drm.def
    --------------------------cut here---------------------------------------
    LIBRARY     D3DRM.DLL
    
    EXPORTS
        D3DRMColorGetAlpha			@1
        D3DRMColorGetBlue                  	@2
        D3DRMColorGetGreen                 	@3
        D3DRMColorGetRed                   	@4
        D3DRMCreateColorRGB                	@5
        D3DRMCreateColorRGBA               	@6
        D3DRMMatrixFromQuaternion          	@7
        D3DRMQuaternionFromRotation        	@8
        D3DRMQuaternionMultiply            	@9
        D3DRMQuaternionSlerp               	@10
        D3DRMVectorAdd                     	@11
        D3DRMVectorCrossProduct            	@12
        D3DRMVectorDotProduct              	@13
        D3DRMVectorModulus                 	@14
        D3DRMVectorNormalize		@15
        D3DRMVectorRandom			@16
        D3DRMVectorReflect			@17
        D3DRMVectorRotate			@18
        D3DRMVectorScale			@19
        D3DRMVectorSubtract			@20
        Direct3DRMCreate			@21
    --------------------------cut here---------------------------------------
    

    Dplay.def
    --------------------------cut here---------------------------------------
    LIBRARY     DPLAY.DLL
    
    EXPORTS
        DirectPlayCreate              		@1   
        DirectPlayEnumerate           		@2   
    --------------------------cut here---------------------------------------
    

    Now run :
  • implib d3drm.lib d3drm.def
  • implib dplay.lib dplay.def

    Now you have these two import libraries.


    Ddraw.h

    This changed header file is only needed for the foxbear and the palette examples.
    For all the other examples you must use the DirectX header files
    There are anonymous unions in this header file.
    I.e. 
    union { char a[2]; short s; }; These unions are only supported in cpp mode. So you have to give these unions a name. I.e. union { char a[2]; short s; }u1;

    This means that the reference to a item in this union also must changed in the
    C program. See the foxbear description for more details.

    Now edit the \dxsdk\sdk\binc\ddraw.h file.
    	At line 	change '};' to
    	------------------------------
    	139		}u1;
    	145		}u2;
    	154		}u3;
    	160		}u4;
    	166		}u5;
    	262		}u6;
    	267		}u7;
    	272		}u8;
    	277		}u9;
    	282		}u10;
    	301		}u11;
    	307		}u12;
    	738		}u13;
    
    Save this file, so now we have a Borland C compatible header file.


    Project

    !!! Don't include any of the ".def" files in your project !!!.

  • New Project
  • Win32 (Platform)
  • Gui (Target Model)
  • Browse (Edit Project Name)
  • Advanced (no .def file)
  • Add files in project
  • Add library file(s) to the project
  • Add include directory to your project. (Options)
  • \dxsdk\sdk\inc;..\misc (cpp examples)
  • \dxsdk\sdk\binc;..\misc (c examples)
  • Example: e:\bc45\include;c:\dxsdk\sdk\inc;..\misc
  • Build All

    The "..\misc" I included is used by most of the examples.

    I have installed BC++ on "e:" and the DirectX SDK on "c:". So I'm using these
    drives in the next descriptions. You should change this to make it fit to your
    own environment. If you use the example name as your project name, the
    example.cpp and example.rc will be automatically added in the project.

    For all the examples see Project on how to create a project.

    And now it's time to compile and run the examples.

    Ddex1

    Add following files in project:
  • ddex1.cpp
  • ddex1.rc
  • c:\dxsdk\sdk\blib\ddraw.lib

    Ddex2

    Add following files in project:
  • ddex2.cpp
  • ddex2.rc
  • ..\misc\ddutil.cpp
  • c:\dxsdk\sdk\blib\ddraw.lib

    Ddex3

    Add following files in project:
  • ddex3.cpp
  • ddex3.rc
  • ..\misc\ddutil.cpp
  • c:\dxsdk\sdk\blib\ddraw.lib

    Ddex4

    Add following files in project:
  • ddex4.cpp
  • ddex4.rc
  • ..\misc\ddutil.cpp
  • c:\dxsdk\sdk\blib\ddraw.lib

    Ddex5

    Add following files in project:
  • ddex5.cpp
  • ddex5.rc
  • ..\misc\ddutil.cpp
  • c:\dxsdk\sdk\blib\ddraw.lib

    Donut

    Add following files in project:
  • donut.cpp
  • donut.rc
  • ..\misc\ddutil.cpp
  • c:\dxsdk\sdk\blib\ddraw.lib

    Fastfile

    Now we are going to create a library.

  • Choose Static Library (for .exe)(lib) in your project options.

    fastfile.c

  • Change lines 10-12
    #ifdef __WATCOMC__
    #define _stricmp stricmp
    #endif
  • to
    #ifdef __BORLANDC__
    #define _stricmp stricmp
    typedef int (*fptr)(const void *, const void *);
    #endif
  • Change Line 55
    int __cdecl Compare( LPFILEENTRY p1, LPFILEENTRY p2 )
  • to
    int Compare( LPFILEENTRY p1, LPFILEENTRY p2 )
  • Change line 195
    pfe = bsearch( &fe, pFE, dwFECnt, sizeof( FILEENTRY ), (LPVOID) Compare );
  • to
    pfe = bsearch( &fe, pFE, dwFECnt, sizeof( FILEENTRY ), (fptr) Compare );

    fastfile.h

  • Comment everything out in this header file,
    except: extern void FastFileFini( void );
  • At this moment I don't know how to handle this in another way.
  • Now run "Build All" to create the library.
  • Copy fastfile.lib to c:\dxsdk\sdk\blib

    Flip2d

    Add following files in project:

  • dumb3d.cpp
  • flipcube.cpp
  • flipcube.rc
  • tri.cpp
  • c:\dxsdk\sdk\blib\ddraw.lib

    Foxbear

    Did you change your "ddraw.h" header file in the c:\dxsdk\sdk\binc directory ?.

    You have to add the "binc" include directory into your project.

    ddraw.c

  • Line 11 insert
    #define DDRAW (just before #include "foxbear.h")

  • Line 14 insert
    struct {int w, h, bpp;} ModeList[100];
    int NumModes;

  • Line 359 change
    ddbltfx.dwFillColor = DDColorMatch(lpBackBuffer, RGB(0, 0, 200));
  • to
    ddbltfx.u5.dwFillColor = DDColorMatch(lpBackBuffer, RGB(0, 0, 200));

  • Line 575 change
    if (ddpf. dwRGBBitCount == 8)
  • to
    if (ddpf.u6.dwRGBBitCount == 8)

  • Line 578 change
    dwColorKey = ddpf.dwRBitMask | ddpf.dwGBitMask | ddpf.dwBBitMask;
  • to
    dwColorKey = ddpf.u7.dwRBitMask | ddpf.u8.dwGBitMask | ddpf.u9.dwBBitMask;

  • Line 671 change
    if(ddsd.ddpfPixelFormat. dwRGBBitCount != 32)
  • to
    if(ddsd.ddpfPixelFormat.u6.dwRGBBitCount != 32)

  • Line 672 change
    dw &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount)-1;
  • to
    dw &= (1 << ddsd.ddpfPixelFormat.u6.dwRGBBitCount)-1;

  • Line 840 change
    (ModeList[NumModes-1].bpp == (int)pddsd->ddpfPixelFormat.dwRGBBitCount)
  • to
    (ModeList[NumModes-1].bpp == (int)pddsd->ddpfPixelFormat.u6.dwRGBBitCount)

  • Line 845 change
    ModeList[NumModes].bpp = pddsd->ddpfPixelFormat.dwRGBBitCount;
  • to
    ModeList[NumModes].bpp = pddsd->ddpfPixelFormat.u6.dwRGBBitCount;

    gfx.c

  • Line 81 change
    ddbltfx.dwFillColor = pbm->dwColor;
  • to
    ddbltfx.u5.dwFillColor = pbm->dwColor;

  • Line 593 change
    ddbltfx.dwFillColor = dwColor;
  • to
    ddbltfx.u5.dwFillColor = dwColor;

    foxbear.h

  • Line 79-80 change
    struct {int w, h, bpp;} ModeList[100];
    int NumModes;
  • to
    #ifndef DDRAW
    extern struct {int w, h, bpp;} ModeList[100];
    extern int NumModes;
    #endif


    Add following files in project:

  • ..\misc\dsutil.c
  • bmp.c
  • ddraw.c
  • fbsound.c
  • gameproc.c
  • gfx.c
  • plane.c
  • sprite.c
  • tile.c
  • foxbear.c
  • foxbear.rc
  • c:\dxsdk\sdk\blib\ddraw.lib
  • c:\dxsdk\sdk\blib\dsound.lib
  • c:\dxsdk\sdk\blib\fastfile.lib


    Palette

    You have to add the "binc" include directory, because there's a C file in the
    project. See Project.

    Add following files in project:
  • palette.cpp
  • palette.rc
  • ..\misc\lbprintf.c
  • c:\dxsdk\sdk\blib\ddraw.lib

    Stretch

    Add following files in project:
  • stretch.cpp
  • stretch.rc
  • ..\misc\ddutil.cpp
  • c:\dxsdk\sdk\blib\ddraw.lib

    Wormhole

    Add following files in project:
  • wormhole.cpp
  • wormhole.rc
  • c:\dxsdk\sdk\blib\ddraw.lib

    Before you "Build All" some edit action is required.

    Step 1.
  • File
  • Open
  • wormhole.rc
  • Change
    wormhole.bmp BITMAP MOVEABLE PURE "wormhole.bmp"
  • to
    wormhole_bmp BITMAP MOVEABLE PURE "wormhole.bmp"
  • Save


    Step 2.
  • File
  • Open
  • wormhole.cpp
  • Change line 354
    hBMP=FindResource(NULL,"wormhole.bmp",RT_BITMAP);
  • to
    hBMP=FindResource(NULL,"wormhole_bmp",RT_BITMAP);
  • Save

    Now run "Build All" to compile this example.

    © 1997 jovo@hotmail.com
    1