#ifndef _DXGRAPHICS_H
#define _DXGRAPHICS_H
//function prototypes
int Init_Direct3D(HWND, int, int, int);
LPDIRECT3DSURFACE9 LoadSurface(char *, D3DCOLOR);
LPDIRECT3DTEXTURE9 LoadTexture(char *, D3DCOLOR);
//variable declarations
extern LPDIRECT3D9 d3d;
extern LPDIRECT3DDEVICE9 d3ddev;
extern LPD3DXSPRITE sprite_handler;
#endif
#include <d3d9.h>
#include <d3dx9.h>
#include "dxgraphics.h"
#include "game.h"
//variable declarations
LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;
LPD3DXSPRITE sprite_handler = NULL;
int Init_Direct3D(HWND hwnd, int width, int height, int fullscreen)
{
//initialize Direct3D
d3d = Direct3DCreate9(D3D_SDK_VERSION);
if (d3d == NULL)
{
MessageBox(hwnd, "Error initializing Direct3D", "Error", MB_OK);
return 0;
}
//set Direct3D presentation parameters
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
if (FULLSCREEN)
{d3dpp.Windowed = FALSE;}else{d3dpp.Windowed = TRUE;}
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
d3dpp.hDeviceWindow = hwnd;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
//create Direct3D device
d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
if (d3ddev == NULL)
{
MessageBox(hwnd, "Error creating Direct3D device", "Error", MB_OK);
return 0;
}
//clear the backbuffer to black
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
//create pointer to the back buffer
// d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
worldmap = new Spriteclass("worldmap.png", 0, 0, 1280, 1024, false);
button_strike = new Spriteclass("Buttonwar.png", 120, 1024, 200, 100, false);
button_build = new Spriteclass("Buttonbuild.png", 120, 1024, 200, 100, false);
build_window = new Spriteclass("Buildbackground.png", 350, 10, 500, 500, false);
inventory_window = new Spriteclass("Inventorybackground.png", 350, 390, 500, 500, false);
spriteICBMbig = new Spriteclass("icbmbig.png", 300, 500, 25, 200, false);
spriteICBMmedium = new Spriteclass("icbmmedium.png", 0, 0, 25, 200, false);
spriteICBMsmall = new Spriteclass("icbmsmall.png", 0, 0, 25, 200, false);
city = new Spriteclass("city.png", 0, 0, 100, 150, false);
warheadbox = new Spriteclass("warheadbox.png", 0, 0, 200, 200, false);
carrierbox = new Spriteclass("carrierbox.png", 0, 0, 200, 300, false);
okbutton = new Spriteclass("okbutton.png", 600, 500, 200, 100, false);
bullseye = new Spriteclass("bullseye.png", 0, 0, 200, 200, false);
worldmap->init();
button_strike->init();
button_build->init();
build_window->init();
inventory_window->init();
spriteICBMbig->init();
spriteICBMmedium->init();
spriteICBMsmall->init();
city->init();
warheadbox->init();
carrierbox->init();
okbutton->init();
bullseye->init();
return 1;
}
LPDIRECT3DSURFACE9 LoadSurface(char *filename, D3DCOLOR transcolor)
{
LPDIRECT3DSURFACE9 image = NULL;
D3DXIMAGE_INFO info;
HRESULT result;
//get width and height from bitmap file
result = D3DXGetImageInfoFromFile(filename, &info);
if (result != D3D_OK)
return NULL;
//create surface
result = d3ddev->CreateOffscreenPlainSurface(
info.Width, //width of the surface
info.Height, //height of the surface
D3DFMT_X8R8G8B8, //surface format
D3DPOOL_DEFAULT, //memory pool to use
ℑ, //pointer to the surface
NULL); //reserved (always NULL)
if (result != D3D_OK)
return NULL;
//load surface from file into newly created surface
result = D3DXLoadSurfaceFromFile(
image, //destination surface
NULL, //destination palette
NULL, //destination rectangle
filename, //source filename
NULL, //source rectangle
D3DX_DEFAULT, //controls how image is filtered
transcolor, //for transparency (0 for none)
NULL); //source image info (usually NULL)
//make sure file was loaded okay
if (result != D3D_OK)
return NULL;
return image;
}
LPDIRECT3DTEXTURE9 LoadTexture(char *filename, D3DCOLOR transcolor)
{
//the texture pointer
LPDIRECT3DTEXTURE9 texture = NULL;
//the struct for reading bitmap file info
D3DXIMAGE_INFO info;
//standard Windows return value
HRESULT result;
//get width and height from bitmap file
result = D3DXGetImageInfoFromFile(filename, &info);
if (result != D3D_OK)
return NULL;
//create the new texture by loading a bitmap image file
D3DXCreateTextureFromFileEx(
d3ddev, //Direct3D device object
filename, //bitmap filename
info.Width, //bitmap image width
info.Height, //bitmap image height
1, //mip-map levels (1 for no chain)
D3DPOOL_DEFAULT, //the type of surface (standard)
D3DFMT_UNKNOWN, //surface format (default)
D3DPOOL_DEFAULT, //memory class for the texture
D3DX_DEFAULT, //image filter
D3DX_DEFAULT, //mip filter
transcolor, //color key for transparency
&info, //bitmap file info (from loaded file)
NULL, //color palette
&texture ); //destination texture
//make sure the bitmap texture was loaded correctly
if (result != D3D_OK)
return NULL;
return texture;
}
#ifndef SPRITECLASS_H
#define SPRITECLASS_H
#include <d3d9.h>
#include <d3dx9.h>
#include <string>
#include "dxgraphics.h"
#include "game.h"
class Spriteclass
{
public:
Spriteclass();
~Spriteclass();
Spriteclass( char *imageName, float, float, int, int, bool );
void init( );
void draw( );
RECT GetPos( );
void SetPos( float, float );
void buttonmove( bool, float);
bool active;
DWORD displaytime;
float xposition;
private:
//sprite structure
typedef struct {
float x,y;
int width,height;
int movex,movey;
int curframe,lastframe;
int animdelay,animcount;
int scalex, scaley;
int rotation, rotaterate;
DWORD spriteTickCount, movespeed;
} SPRITE;
bool bAnimated;
char *privImagename;
LPDIRECT3DTEXTURE9 sprite_image;
SPRITE thesprite;
HRESULT result;
};
#endif // SPRITECLASS_H
void Spriteclass::init ( )
{
char buf[2048];
//create sprite handler object
result = D3DXCreateSprite(d3ddev, &sprite_handler);
if (FAILED(result))
{
sprintf_s(buf, "Error: %s error description: %s\n",DXGetErrorString9(result),DXGetErrorDescription9(result));
OutputDebugString(buf);
}
if (FAILED(D3DXCreateSprite(d3ddev, &sprite_handler)))
{
MessageBox(NULL, buf, "Error", MB_OK);
}
//load texture with "pink" as the transparent color
sprite_image = LoadTexture(privImagename, D3DCOLOR_XRGB(255,0,255));
if (sprite_image == NULL)
{
MessageBox(NULL, "sprite_image error", "Error", MB_OK);
}
}
void Game_End(HWND hwnd)
{
delete worldmap;
delete button_strike;
delete button_build;
delete build_window;
delete inventory_window;
delete spriteICBMbig;
delete spriteICBMmedium;
delete spriteICBMsmall;
delete bullseye;
delete okbutton;
int i;
for (i=3; i > -1; i--)
{
delete nations;
}
delete city;
delete warheadbox;
delete carrierbox;
if (sprite_handler != NULL)
sprite_handler->Release();
if (d3d != NULL)
d3d->Release();
if (d3ddev != NULL)
d3ddev->Release();
}
Quote:A lot of errors like the last ones, and finally:
Direct3D9: :====> ENTER: DLLMAIN(00d5d6e0): Process Detach 00000ae4, tid=00000f30 Direct3D9: (INFO) :MemFini! Direct3D9: (WARN) :Memory still allocated! Alloc count = 208 Direct3D9: (WARN) :Current Process (pid) = 00000ae4 Direct3D9: (WARN) :Memory Address: 003a5060 lAllocID=1 dwSize=000047f8, (pid=00000ae4) Direct3D9: (WARN) : Stack Back Trace Direct3D9: (ERROR) : [0] : Address 00D5D4CB Direct3D9: (ERROR) : [1] : Address 00D5D59B Direct3D9: (ERROR) : [2] : Address 00D5D440 Direct3D9: (ERROR) : [3] : Address 00D51D44 Direct3D9: (ERROR) : [4] : Address 4FE4AF2E Direct3D9: (ERROR) : [5] : Address 00421377 Direct3D9: (ERROR) : [6] : Address 00423916 Direct3D9: (ERROR) : [7] : Address 00458C46 Direct3D9: (ERROR) : [8] : Address 004589AD Direct3D9: (ERROR) : [9] : Address 7C816D4F Direct3D9: (ERROR) : [10] : Address 00000000 Direct3D9: (ERROR) : [11] : Address 00000000 Direct3D9: (ERROR) : [12] : Address 00000000 Direct3D9: (ERROR) : [13] : Address 00000000 Direct3D9: (ERROR) : [14] : Address 00000000 Direct3D9: (ERROR) : [15] : Address 00000000
Quote:Can anyone help me point out what is not being released/destroyed?
Direct3D9: (WARN) :Total Memory Unfreed From Current Process = 400878 bytes Direct3D9: :====> EXIT: DLLMAIN(00d5d6e0): Process Detach 00000ae4

