This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

 

  DirectX8 Graphics Wrapper
  Submitted by



So I've written a little C++ DirectX8 Graphics Wrapper which load dynamicaly the D3D8.dll file and allow to initialise both FullScreen and Windowed modes easily. The example use the Alias25 Game Library but you can use the wrapper without it.

I've written a big README file with all explantion about the functions so I belive that's not necessary to describe it here. =)

Friendly Pierre.

Currently browsing [dx8wrapper.zip] (20,160 bytes) - [dx8wrapper/src/DX8.cpp] - (4,943 bytes)

//***************************************************************************
//**
//** Alias25 (C) 2000
//**
//** File: DX8.CPP
//**
//** Date: 25/11/2000
//**
//** Author: Pierre Renaux
//**
//** Desc: DirectX8 Graphics Wrapper Test 
//**
//***************************************************************************
//===========================================================================
//    IMPLEMENTATION HEADERS
//===========================================================================
#include "CDX8Graphics.h"

//=========================================================================== // IMPLEMENTATION PRIVATE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS //=========================================================================== //=========================================================================== // IMPLEMENTATION PRIVATE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES //=========================================================================== //=========================================================================== // IMPLEMENTATION PRIVATE STRUCTURES / UTILITY CLASSES //=========================================================================== //=========================================================================== // IMPLEMENTATION REQUIRED EXTERNAL REFERENCES (AVOID) //=========================================================================== //=========================================================================== // IMPLEMENTATION PRIVATE FUNCTION PROTOTYPES //=========================================================================== static int osmsg_close(void);

//=========================================================================== // IMPLEMENTATION PRIVATE DATA //=========================================================================== static int done = 0;

CDX8Graphics *DX8 = NULL;

//=========================================================================== // IMPLEMENTATION PRIVATE FUNCTIONS //=========================================================================== //--------------------------------------------------------------------------- // Name: osmsg_close() // Desc: answer to the OSMSG_CLOSE message. //--------------------------------------------------------------------------- static int osmsg_close(void) { done = 1; return 1; }

//=========================================================================== // INTERFACE DATA //=========================================================================== //=========================================================================== // INTERFACE FUNCTIONS //=========================================================================== //--------------------------------------------------------------------------- // Name: main() // Desc: The main function. //--------------------------------------------------------------------------- AGL_MAIN int main(int argc, char **argv) { set_window_title("DirectX 8 Test");

set_log_file("DX8.log");

// Add the OSMSG callbacks set_osmsg_callback(OSMSG_CLOSE, osmsg_close);

// We don't need to enumerate the DirectX device because we recreate // all these functions for DirectX 8 if(!init_agl(AGL_WINDOWED)) sys_error("Unable to init the AGL !");

// Install the keyboard manager if(!install_keyboard()) sys_error("Unable to install keyboard !");

// Create the DX8 object DX8 = new CDX8Graphics(0, 640, 480); if(!DX8) sys_error("Unable to create the DX8 object !");

if(!DX8->AllOk()) sys_error("Error during the DX8 object creation !");

// Main loop while(!done) { // Poll timer and keyboard. poll_timer_func(); poll_keyboard();

// If the escape key is pressed quit the program if(key[KEY_ESC]) done = 1;

if(keypressed()) { switch(readkey(NULL)) { case KEY_SPACE: DX8->Switch(); break; } }

LPDIRECT3DDEVICE8 Dev = DX8->Dev(); if(Dev) { // Clear the backbuffer to a blue color Dev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0); // Begin the scene Dev->BeginScene(); // Rendering of scene objects can happen here // End the scene Dev->EndScene(); // Present the backbuffer contents to the display Dev->Present(NULL, NULL, NULL, NULL); } }

// Destroy the DX8 object delete DX8;

// Close all and exit. close_agl(); return 0; }

//=========================================================================== // INTERFACE CLASS BODIES //=========================================================================== //*************************************************************************** //** //** END MODULE DX8.CPP //** //***************************************************************************

Currently browsing [dx8wrapper.zip] (20,160 bytes) - [dx8wrapper/src/CDX8Graphics.cpp] - (19,979 bytes)

//***************************************************************************
//**
//** Alias25 (C) 2000
//**
//** File: CDX8GRAPHICS.CPP
//**
//** Date: 25/11/2000
//**
//** Author: Pierre Renaux
//**
//** Desc: DirectX8 Graphics Wrapper Functions
//**
//***************************************************************************
//===========================================================================
//    IMPLEMENTATION HEADERS
//===========================================================================
#include "CDX8Graphics.h"

//=========================================================================== // IMPLEMENTATION PRIVATE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS //=========================================================================== #ifndef __AGAMELIB_H__ #include <stdio.h> #include <stdarg.h>

static void write_error(char *str, ...) { va_list ap; char buf[1024];

va_start(ap, str); vsprintf((char*)buf, (char*)str, ap); va_end(ap);

OutputDebugString(buf); } #endif

//=========================================================================== // IMPLEMENTATION PRIVATE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES //=========================================================================== //=========================================================================== // IMPLEMENTATION PRIVATE STRUCTURES / UTILITY CLASSES //=========================================================================== // Structure used to represent an adpater typedef struct DX8GRAPHIC_ADAPTER { // Gfx Modes U32 num_mode; D3DDISPLAYMODE *modes; // Identifier structure D3DADAPTER_IDENTIFIER8 id; // Device Caps D3DCAPS8 caps; } DX8GRAPHIC_ADAPTER;

//=========================================================================== // IMPLEMENTATION REQUIRED EXTERNAL REFERENCES (AVOID) //=========================================================================== /* Game Library reference */ #ifdef __AGAMELIB_H__ extern "C" { extern HWND agl_wnd; extern int wnd_windowed; extern BOOL wnd_paint_back; } #endif

//=========================================================================== // IMPLEMENTATION PRIVATE FUNCTION PROTOTYPES //=========================================================================== //=========================================================================== // IMPLEMENTATION PRIVATE DATA //=========================================================================== //=========================================================================== // IMPLEMENTATION PRIVATE FUNCTIONS //=========================================================================== //=========================================================================== // INTERFACE DATA //=========================================================================== //=========================================================================== // INTERFACE FUNCTIONS //=========================================================================== //=========================================================================== // INTERFACE CLASS BODIES //=========================================================================== //--------------------------------------------------------------------------- // Name: CDX8Graphics::CDX8Graphics() // Desc: Constructor, load the D3D8.DLL file. //--------------------------------------------------------------------------- CDX8Graphics::CDX8Graphics(HWND wnd) { Initialise(wnd); }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::CDX8Graphics() // Desc: Constructor which allow you to specify directly a gfx mode to // initialise and the window to use. //--------------------------------------------------------------------------- CDX8Graphics::CDX8Graphics(HWND wnd, U32 adapter, int w, int h, D3DFORMAT pixformat, U32 behavior) { Initialise(wnd); if(AllOk()) { mp_all_ok = Gfx(adapter, w, h, pixformat, behavior); } }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::CDX8Graphics() // Desc: Constructor which allow you to specify directly a gfx mode to // initialise. //--------------------------------------------------------------------------- CDX8Graphics::CDX8Graphics(U32 adapter, int w, int h, D3DFORMAT pixformat, U32 behavior) { Initialise(); if(AllOk()) { mp_all_ok = Gfx(adapter, w, h, pixformat, behavior); } }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::~CDX8Graphics() // Desc: Destructor, destroy all created objects, devices and unload the DLL. //--------------------------------------------------------------------------- CDX8Graphics::~CDX8Graphics() { Uninitialise(); }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::Initialise() // Desc: Initialise the class. //--------------------------------------------------------------------------- void CDX8Graphics::Initialise(HWND wnd) { // Set the default values of all members mp_all_ok = FALSE; mpUpdateInfo();

mp_d3d_obj = NULL; mp_d3d_dev = NULL;

mp_num_adapter = 0; mp_adapters = NULL;

// Load the D3D8 Dll mp_d3d8_dll = LoadLibrary("D3D8.DLL"); if(!mp_d3d8_dll) { write_error("CDX8Graphics::Initialise() - Unable to load D3D8.DLL !"); return; }

// Get the needed address functions mpDirect3DCreate8 = (LPDIRECT3D8(WINAPI*)(UINT))GetProcAddress(mp_d3d8_dll, "Direct3DCreate8"); if(!mpDirect3DCreate8) { write_error("CDX8Graphics::Initialise() - Unable to get the Direct3DCreate8 procedure address !"); return; }

// Create the Direct3D object mp_d3d_obj = mpDirect3DCreate8(D3D_SDK_VERSION); if(!mp_d3d_obj) { write_error("CDX8Graphics::Initialise() - Unable to create the IDirect3D8 object !"); return; }

// Enumerate hardware if(!mpEnumerateHardware()) { write_error("CDX8Graphics::Initialise() - Unable to enumerate hardware !"); return; }

// Set the current HWND to use #ifdef __AGAMELIB_H__ mp_wnd = wnd ? wnd : agl_wnd; #else if(!wnd) { write_error("CDX8Graphics::Initialise() - No Window passed to the initialiser !"); return; } mp_wnd = wnd; #endif

// All is ok so put the state variable at TRUE. mp_all_ok = TRUE; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::Uninitialise() // Desc: Initialise the class. //--------------------------------------------------------------------------- void CDX8Graphics::Uninitialise() { // Free the adpater list if(mp_adapters) { for(U32 i = 0; i < mp_num_adapter; i++) { if(mp_adapters[i].modes) { delete mp_adapters[i].modes; mp_adapters[i].modes = NULL; } } delete mp_adapters; }

// Free the D3D device if(mp_d3d_dev) { mp_d3d_dev->Release(); mp_d3d_dev = NULL; }

// Free the D3D object if(mp_d3d_obj) { mp_d3d_obj->Release(); mp_d3d_obj = NULL; } // Free the DLL if(mp_d3d8_dll) { FreeLibrary(mp_d3d8_dll); mp_d3d8_dll = NULL; mpDirect3DCreate8 = NULL; }

// Set the window ptr to NULL mp_wnd = NULL;

// All is not yet ok ;) mp_all_ok = FALSE; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::Gfx(U32 adapter, int w, int h, D3DFORMAT pixformat) // Desc: Setup the gfx mode. //--------------------------------------------------------------------------- BOOL CDX8Graphics::Gfx(U32 adapter, int w, int h, D3DFORMAT pixformat, U32 behavior) { if(!AdapterCapsWindowed(adapter)) pixformat = mpDesktopMode();

if(pixformat == D3DFMT_UNKNOWN) { return mpWindowedInit(adapter, w, h, behavior); } return mpFullScreenInit(adapter, w, h, pixformat, behavior); }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::Switch() // Desc: Switch between fullscreen and windowed mode.s //--------------------------------------------------------------------------- BOOL CDX8Graphics::Switch(BOOL fullscreen) { if(!AdapterCapsWindowed(mp_current_adapter)) return FALSE;

if(fullscreen == 2) fullscreen = mp_fullscreen ? FALSE : TRUE;

if(fullscreen) return Gfx(mp_current_adapter, mp_w, mp_h, mp_pixformat); else return Gfx(mp_current_adapter, mp_w, mp_h); }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::NumAdapter() // Desc: Return the number of D3D adapter. //--------------------------------------------------------------------------- U32 CDX8Graphics::NumAdapter() { return mp_num_adapter; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::AdapterInfo() // Desc: Return informations about an adapter. //--------------------------------------------------------------------------- BOOL CDX8Graphics::AdapterInfo(U32 i, D3DCAPS8 *caps, char *name, char *desc) { if(i >= mp_num_adapter) return FALSE;

if(name) strncpy(name, mp_adapters[i].id.Driver, MAX_DEVICE_IDENTIFIER_STRING); if(desc) strncpy(desc, mp_adapters[i].id.Description, MAX_DEVICE_IDENTIFIER_STRING); if(caps) memcpy(caps, &mp_adapters[i].caps, sizeof(D3DCAPS8));

return TRUE; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::AdapterNumMode() // Desc: Return the number of gfx mode of an adpater. //--------------------------------------------------------------------------- U32 CDX8Graphics::AdapterNumMode(U32 i) { if(i >= mp_num_adapter) return 0;

return mp_adapters[i].num_mode; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::AdapterMode() // Desc: Enumerate a gfx mode of an adapter. //--------------------------------------------------------------------------- BOOL CDX8Graphics::AdapterMode(U32 i, U32 imode, int *w, int *h, D3DFORMAT *format) { if(i >= mp_num_adapter) goto error;

if(imode >= mp_adapters[i].num_mode) goto error;

if(w) *w = mp_adapters[i].modes[imode].Width; if(h) *h = mp_adapters[i].modes[imode].Height; if(format) *format = mp_adapters[i].modes[imode].Format;

return TRUE;

error:; if(w) *w = 0; if(h) *h = 0; if(format) *format = D3DFMT_UNKNOWN; return FALSE; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::AdapterCapsWindowed() // Desc: Return TRUE if the specifed adapter can render in windowed // mode. //--------------------------------------------------------------------------- BOOL CDX8Graphics::AdapterCapsWindowed(U32 i) { D3DCAPS8 caps;

if(AdapterInfo(i, &caps)) { if((caps.Caps2 & D3DCAPS2_CANRENDERWINDOWED) == D3DCAPS2_CANRENDERWINDOWED) return TRUE; }

return FALSE; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::mpEnumerateHardware() // Desc: Enumerate present harware. //--------------------------------------------------------------------------- BOOL CDX8Graphics::mpEnumerateHardware() { U32 i, j, num_hal;

if(!mp_d3d_obj) return FALSE;

// Get the number of adpaters mp_num_adapter = mp_d3d_obj->GetAdapterCount(); if(mp_num_adapter < 1) { write_error("CDX8Graphics::mpEnumerateHardware() - No adapter detected !"); return FALSE; }

// Alloc the adapters array mp_adapters = new DX8GRAPHIC_ADAPTER[mp_num_adapter]; if(!mp_adapters) { write_error("CDX8Graphics::mpEnumerateHardware() - Unable to alloc mp_adapters !"); return FALSE; }

// Gets Adapter identifier and gfx modes for(i = 0, num_hal = 0; i < mp_num_adapter; i++) { if(FAILED(mp_d3d_obj->GetAdapterIdentifier(i, D3DENUM_NO_WHQL_LEVEL, &mp_adapters[num_hal].id))) { write_error("CDX8Graphics::mpEnumerateHardware() - Unable to adapter identifier [%d] !", i); return FALSE; }

if(FAILED(mp_d3d_obj->GetDeviceCaps(i, D3DDEVTYPE_HAL, &mp_adapters[num_hal].caps))) { write_error("CDX8Graphics::mpEnumerateHardware() - Unable to get HAL caps of an adapter [%d] !", i); continue; }

mp_adapters[num_hal].num_mode = mp_d3d_obj->GetAdapterModeCount(i); mp_adapters[num_hal].modes = new D3DDISPLAYMODE[mp_adapters[num_hal].num_mode]; if(!mp_adapters[num_hal].modes) { write_error("CDX8Graphics::mpEnumerateHardware() - Unable to alloc mp_adapters[%d].modes !", i); return FALSE; }

for(j = 0; j < mp_adapters[num_hal].num_mode; j++) { mp_d3d_obj->EnumAdapterModes(i, j, &mp_adapters[num_hal].modes[j]); }

num_hal++; }

if(num_hal < 1) { write_error("CDX8Graphics::mpEnumerateHardware() - No HAL device detected !", i); return FALSE; }

return TRUE; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::mpDesktopMode() // Desc: Return the Dektop gfx mode. //--------------------------------------------------------------------------- D3DFORMAT CDX8Graphics::mpDesktopMode(int *w, int *h) { D3DDISPLAYMODE dm; // Used to get the current gfx mode. // First, get the desktop display mode if(FAILED(mp_d3d_obj->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm))) { write_error("CDX8Graphics::mpDesktopMode() - Unable to get the current display mode !"); return D3DFMT_UNKNOWN; }

if(w) *w = dm.Width; if(h) *h = dm.Height;

return dm.Format; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::mpCheckUpBeforeGfxInitialisation() // Desc: Reset all variables that need to be, before a gfx mode // initialisation. //--------------------------------------------------------------------------- void CDX8Graphics::mpCheckUpBeforeGfxInitialisation() { // Free the D3D device if(mp_d3d_dev) { mp_d3d_dev->Release(); mp_d3d_dev = NULL; }

// Reset the info vars. mpUpdateInfo(); }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::mpWindowedStyle() // Desc: Change the style and the size of the window to use a windowed gfx // mode. //--------------------------------------------------------------------------- void CDX8Graphics::mpWindowedStyle(int w, int h) { RECT r; int style;

#ifdef __AGAMELIB_H__ wnd_paint_back = 0; wnd_windowed = 1; #endif

style = GetWindowLong(mp_wnd, GWL_STYLE); style &= ~(WS_BORDER | WS_SIZEBOX); style |= WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU; SetWindowLong(mp_wnd, GWL_STYLE, style);

SetRect(&r, 0, 0, w, h); AdjustWindowRectEx(&r, GetWindowLong(mp_wnd,GWL_STYLE), GetMenu(mp_wnd) != NULL, GetWindowLong(mp_wnd,GWL_EXSTYLE));

SetWindowPos(mp_wnd, HWND_NOTOPMOST, (GetSystemMetrics(SM_CXSCREEN)-w)/2, (GetSystemMetrics(SM_CYSCREEN)-h)/2, r.right-r.left, r.bottom-r.top, 0); }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::mpFullScreenStyle() // Desc: Change the style and the size of the window to use a fullscreen gfx // mode. //--------------------------------------------------------------------------- void CDX8Graphics::mpFullScreenStyle(int w, int h) { RECT r; int style;

#ifdef __AGAMELIB_H__ wnd_paint_back = 0; wnd_windowed = 0; #endif

style = GetWindowLong(mp_wnd, GWL_STYLE); style &= ~(WS_BORDER | WS_MINIMIZEBOX | WS_SYSMENU | WS_SIZEBOX | WS_CAPTION); SetWindowLong(mp_wnd, GWL_STYLE, style);

SetRect(&r, 0, 0, w, h); AdjustWindowRectEx(&r, GetWindowLong(mp_wnd,GWL_STYLE), GetMenu(mp_wnd) != NULL, GetWindowLong(mp_wnd,GWL_EXSTYLE));

SetWindowPos(mp_wnd, HWND_NOTOPMOST, (GetSystemMetrics(SM_CXSCREEN)-w)/2, (GetSystemMetrics(SM_CYSCREEN)-h)/2, r.right-r.left, r.bottom-r.top, 0);

}

//--------------------------------------------------------------------------- // Name: CDX8Graphics::mpWindowedInit() // Desc: Initialise a windowed gfx mode. Return FALSE if failed, // otherwise TRUE. //--------------------------------------------------------------------------- BOOL CDX8Graphics::mpWindowedInit(U32 adapter, int w, int h, U32 behavior) { D3DFORMAT pixformat; D3DPRESENT_PARAMETERS pp; // Used to create the D3D device. mpCheckUpBeforeGfxInitialisation();

// Change the window size and style to match with the requested mode mpWindowedStyle(w, h);

// Get the Desktop color format pixformat = mpDesktopMode();

// Initialise the pp structure ZeroMemory(&pp, sizeof(D3DPRESENT_PARAMETERS)); pp.Windowed = TRUE; // Use windowed mode pp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Use DISCARD swapping method pp.BackBufferFormat = pixformat; // Use the same pixel format as the // current display mode. // Now create the D3D device with the same value as in the DX8Doc tutorial. // Will be modified ! if(FAILED(mp_d3d_obj->CreateDevice(adapter, D3DDEVTYPE_HAL, mp_wnd, behavior, &pp, &mp_d3d_dev))) { write_error("CDX8Graphics::mpWindowedInit() - Unable to create the D3D device !"); return FALSE; }

// Finally update the gfx mode informations mpUpdateInfo(adapter, w, h, pixformat, FALSE);

return TRUE; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::mpFullScreenInit() // Desc: Initialise a fullscreen gfx mode. Return FALSE if failed, // otherwise TRUE. //--------------------------------------------------------------------------- BOOL CDX8Graphics::mpFullScreenInit(U32 adapter, int w, int h, D3DFORMAT pixformat, U32 behavior) { D3DPRESENT_PARAMETERS pp; // Used to create the D3D device. mpCheckUpBeforeGfxInitialisation();

// Change the window size and style to match with the requested mode mpFullScreenStyle(w, h);

// Initialise the pp structure ZeroMemory(&pp, sizeof(D3DPRESENT_PARAMETERS)); pp.Windowed = FALSE; // Use fullscreen mode pp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Use DISCARD swapping method pp.BackBufferWidth = w; pp.BackBufferHeight = h; pp.BackBufferFormat = pixformat; // Use the same pixel format as the // current display mode. // Now create the D3D device with the same value as in the DX8Doc tutorial. // Will be modified ! if(FAILED(mp_d3d_obj->CreateDevice(adapter, D3DDEVTYPE_HAL, mp_wnd, behavior, &pp, &mp_d3d_dev))) { write_error("CDX8Graphics::mpWindowedInit() - Unable to create the D3D device !"); return FALSE; }

// Finally update the gfx mode informations mpUpdateInfo(adapter, w, h, pixformat, TRUE);

return TRUE; }

//--------------------------------------------------------------------------- // Name: CDX8Graphics::mpUpdateInfo() // Desc: Update the info variables. //--------------------------------------------------------------------------- void CDX8Graphics::mpUpdateInfo(U32 adapter, int w, int h, D3DFORMAT pixformat, BOOL fullscreen) { mp_current_adapter = adapter; mp_w = w; mp_h = h; mp_pixformat = pixformat; mp_fullscreen = fullscreen; }

//*************************************************************************** //** //** END MODULE CDX8GRAPHICS.CPP //** //***************************************************************************

Currently browsing [dx8wrapper.zip] (20,160 bytes) - [dx8wrapper/src/CDX8Graphics.h] - (6,108 bytes)

#ifndef __CDX8Graphics_H__
#define __CDX8Graphics_H__
//***************************************************************************
//**
//** Alias25 (C) 2000
//**
//** File: CDX8Graphics.h
//**
//** Date: 25/11/2000
//**
//** Author: Pierre Renaux
//**
//** Desc: DirectX8 Graphics Wrapper
//**
//***************************************************************************
//===========================================================================
//    INTERFACE REQUIRED HEADERS
//===========================================================================
#include "agamelib.h"     // Comment it if you don't want to use
                          // the game library.
#include <windows.h>
#include <d3d8.h>

//=========================================================================== // INTERFACE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS //=========================================================================== #ifndef __AGAMELIB_H__ #define U32 unsigned long #endif

//=========================================================================== // INTERFACE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES //=========================================================================== //=========================================================================== // INTERFACE STRUCTURES / UTILITY CLASSES //=========================================================================== //=========================================================================== // INTERFACE DATA DECLARATIONS //=========================================================================== //=========================================================================== // INTERFACE FUNCTION PROTOTYPES //=========================================================================== //=========================================================================== // INTERFACE OBJECT CLASS DEFINITIONS //=========================================================================== // CDX8Graphics class CDX8Graphics { // Public functions ///////////////////////////////////////////////////////// public: CDX8Graphics(HWND wnd = NULL); CDX8Graphics(HWND wnd, U32 adapter, int w, int h, D3DFORMAT pixformat = D3DFMT_UNKNOWN, U32 behavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING); CDX8Graphics(U32 adapter, int w, int h, D3DFORMAT pixformat = D3DFMT_UNKNOWN, U32 behavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING); ~CDX8Graphics();

// Initialise void Initialise(HWND wnd = NULL);

// Uninitialise void Uninitialise(void);

// Return true if the object has been well initialised by the constructor // and Initialise. BOOL AllOk() { return mp_all_ok; }

// Change the current video mode BOOL Gfx(U32 adapter, int w, int h, D3DFORMAT pixformat = D3DFMT_UNKNOWN, U32 behavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING);

// Switch between fullscreen and windowed mode BOOL Switch(BOOL fullscreen = 2);

// Return the D3DDevice8 object LPDIRECT3DDEVICE8 Dev() { return mp_d3d_dev; }

// Enumeration functions U32 NumAdapter(); BOOL AdapterInfo(U32 i, D3DCAPS8 *caps, char *name = NULL, char *desc = NULL); U32 AdapterNumMode(U32 i); BOOL AdapterMode(U32 i, U32 imode, int *w, int *h, D3DFORMAT *format);

// Quick Caps test functions BOOL AdapterCapsWindowed(U32 i);

// Return the informations about the current gfx mode U32 W() { return mp_w; } U32 H() { return mp_h; } D3DFORMAT PixelFormat() { return mp_pixformat; } BOOL FullScreen() { return mp_fullscreen; } U32 CurrentAdapter() { return mp_current_adapter; }

// Virtual Member to deal with window's focus lost/gain virtual int SwitchIn(void) { return 1; } virtual int SwitchOut(void) { return 1; }

// Private functions //////////////////////////////////////////////////////// private: // Enumerate present hardware. BOOL mpEnumerateHardware();

// Return the desktop display mode D3DFORMAT mpDesktopMode(int *w = NULL, int *h = NULL);

// Change the style and the size of the window to use a windowed gfx mode. void mpWindowedStyle(int w, int h);

// Change the style and the size of the window to use a fullscreen gfx mode. void mpFullScreenStyle(int w, int h);

// Reset all variables that need to be, before a gfx mode initialisation. void mpCheckUpBeforeGfxInitialisation();

// Initialise a windowed gfx mode and show the window BOOL mpWindowedInit(U32 adapter, int w, int h, U32 behavior);

// Initialise a fullscreen gfx BOOL mpFullScreenInit(U32 adapter, int w, int h, D3DFORMAT pixformat, U32 behavior);

// Update the info variables void mpUpdateInfo(U32 adapter=0, int w=0, int h=0, D3DFORMAT pixformat=D3DFMT_UNKNOWN, BOOL fullscreen=FALSE);

// Public data ////////////////////////////////////////////////////////////// public: // Private Data ///////////////////////////////////////////////////////////// private: BOOL mp_all_ok; // To be sure that all is ok HWND mp_wnd; // The used window HINSTANCE mp_d3d8_dll; // The D3D8 DLL // Informations about the current gfx mode. U32 mp_w; U32 mp_h; D3DFORMAT mp_pixformat; BOOL mp_fullscreen;

// Current adapter index U32 mp_current_adapter;

// Adapter array U32 mp_num_adapter; struct DX8GRAPHIC_ADAPTER *mp_adapters;

// Dynamicaly loaded DX8 functions IDirect3D8 *(WINAPI *mpDirect3DCreate8)(UINT SDKVersion);

// DirectX8 Objects LPDIRECT3D8 mp_d3d_obj; // Used to create the D3DDevice LPDIRECT3DDEVICE8 mp_d3d_dev; // Our rendering device };

//=========================================================================== // INTERFACE TRAILING HEADERS //=========================================================================== //*************************************************************************** //** //** END HEADER CDX8Graphics.h //** //*************************************************************************** #endif // __CDX8Graphics_H__

The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.