directx programmering
er igang med at lære directx programmeringog har lavet et program der opretter directx, og skal animere en kat der løber. men er selv løbet ind i et problem.
får denne fejl ved runtime
Unhandled exception at 0x00411596 in Anim_Sprite.exe: 0xC0000005: Access violation reading location 0x00000000.
og den kommer i min init direct3d funktion
helt præcis når jeg når til
d3d->CreateDevice()
her er koden. nogle der kan hjælpe mig
ps. alle steder hvor der står ">" er faktisk en ">" men hjemmesiden laver det om af en grund
[code]
// Beginning game programming, second edition
// Chapter 7
// dxgraphics.cpp - Direct3D frameword source code file
#include <d3d9.h>
#include <d3dx9.h>
#include "dxgraphics.h"
// variable declarations
LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;
LPDIRECT3DSURFACE9 backbuffer = NULL;
int Init_Direct3D(HWND hWnd, int width, int height, int fullscreen)
{
// initialize the 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));
d3dpp.Windowed = (!fullscreen);
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = width;
d3dpp.BackBufferHeight = height;
d3dpp.hDeviceWindow = hWnd;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
// create Direct3D device
d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_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 backbuffer
d3ddev->GetBackBuffer(0,0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
return 1;
}
LPDIRECT3DSURFACE9 LoadSurface(char *filename, D3DCOLOR transcolor)
{
LPDIRECT3DSURFACE9 image = NULL;
D3DXIMAGE_INFO info;
HRESULT result;
// get width and height from bitmapfile
result = D3DXGetImageInfoFromFile(filename, &info);
if(result != D3D_OK)
return NULL;
// create surface
result = d3ddev->CreateOffscreenPlainSurface(
info.Width, // width of surface
info.Height, // height of 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, // destinationsurface
NULL, // destination palette
NULL, // destination rectange
filename, // source filename
NULL, // source rectangle
D3DX_DEFAULT, // controls how image is filtered
transcolor, // for transparency(90 for none
NULL); // source image info (usually NULL)
// make sure the file was loaded ok
if(result != D3D_OK)
return NULL;
return image;
}
[/code]