Brad Bell - Union University Implementing a Computer Game Using

5 downloads 135504 Views 2MB Size Report
Implementing a Computer Game Using. Page 2. What is DirectX? An Application Programming Interface(API) that provides low ... Windows Game Programming.
Implementing a Computer Game Using

Brad Bell - Union University

What is DirectX? An Application Programming Interface(API) that provides low level access to multimedia hardware in a device independent manner Hardware Abstraction Layer (HAL) Hardware Emulation Layer (HEL)

DirectX Components

What do you need to develop a DirectX application? DirectX Software Developer’s Kit (SDK) http://www.microsoft.com/directx/ Win32 compiler Language? A little creativity!

What I am using to develop “Die, Rock, Die.” Microsoft DirectX SDK v. 5.2 Microsoft Visual C++ 5.0 Professional Edition Corel Draw Suite 7.0 Windows 98 Sound Forge XP 4.0 Microsoft Force-Feedback Pro Digital Joystick

Direct Draw Initialization LPDIRECTDRAW extern HWND LPDIRECTDRAWSURFACE LPDIRECTDRAWSURFACE DDSURFACEDESC

lpdd = NULL; hWnd; lpddsprimary = NULL; lpddsback = NULL; ddsd;

// // // // //

DD object The window handle DD primary surface DD back surface DD surface description struct

if (DirectDrawCreate(NULL,&lpdd,NULL) != DD_OK) return(0);

// Create the DirectDraw // Object

if (lpdd->SetCooperativeLevel(hWnd, | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)!=DD_OK) return(0);

// Set cooperation level

if (lpdd->SetDisplayMode(width,height,bpp)!=DD_OK) // Set the display mode return(0);

Direct Draw Initialization (cont’d.)

ddsd.dwSize = sizeof(ddsd);

// Set the dwSize field

ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; // Specify the DD // surface capabilities ddsd.dwBackBufferCount = 1; // How many backbuffers? lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL);

// Create the primary surface

ddscaps.dwCaps = DDSCAPS_BACKBUFFER;

// Looking at backbuffer

lpddsprimary->GetAttachedSurface(&ddscaps,&lpddsback); // Query for the backbuffer while(lpddsprimary->Flip(NULL, DDFLIP_WAIT) != DD_OK); // Flip the surfaces

References Inside DirectX Bradley Bargen and Peter Donnelly Microsoft Press: 1998 Win32 Programming API Bible Richard Simon The Waite Group: 1996 Windows Game Programming Andre LaMothe IDG Books: 1998 Sprite Library - Ari Feldman Sound Library - Union University Angelic Coders www.angelic-coders.com