så har jeg endnu et problem
er igang med en bog om programmering i directx. men har et problem.
jeg har 3 includes
d3d9.h
d3dx9.h
time.h
den siger den ikke kan finde d3dx9.h
og har sat projectet op til at lede i d3d9.lib og d3dx9.lib
her er koden
det tyder på det er noget med d3dx9.h og d3dx9.lib som er problemet, da tidligere programmer jeg har compilet virkede og de brugte kun d3d9.h / d3d9.lib
grunden til jeg skal bruge det extended library er til LoadSurfaceFromFile funktionen.
nogen der kan fortælle mig hvorfor den af en eller anden grund ikke kan finde den header
på forhånd tak
// Beginning game programming second edition
// chapter 6
// Load_bitmap program
// header includes
#include <d3d9.h>
#include <D3dx9d.h>
#include <time.h>
// Define app title
#define APPTITLE "Load Bitmap"
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
// macros to use escape key
#define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1: 0)
// function prototyping
LRESULT WINAPI WinProc(HWND, UINT, WPARAM, LPARAM);
ATOM MyRegisterClass(HINSTANCE);
int Game_Init(HWND);
void Game_Run(HWND);
void Game_End(HWND);
// initializing Direct3D
LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;
LPDIRECT3DSURFACE9 backbuffer = NULL;
LPDIRECT3DSURFACE9 surface = NULL;
LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
Game_end(hWnd);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
// fill the struct
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszClassName = APPTITLE;
wc.lpszMenuName = NULL;
wc.hIconSm = NULL;
// setup the window with the class info
return RegisterClassEx(&wc);
}
// entry point for a windows program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
MyRegisterClass(hInstance);
HWND hWnd;
hWnd = CreateWindow(
APPTITLE, // window class
APPTITLE, // Titlebar
WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP,
CW_USEDEFAULT,
CW_USEDEFAULT,
SCREEN_WIDTH,
SCREEN_HEIGHT, // Height and width of window
NULL, // Parent window
NULL, // menu
hInstace, // application instance
NULL;) // window parameters
// was there an error creating window
if(!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// initialize the game
if(!Game_Init(hWnd))
return 0;
// main Messageloop
int done = 0;
while(!done)
{
if(PeekMessage(&msg, NULL, 0,0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
done = 1;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
Game_Run(hWnd);
}
return msg.wParam;
}
// Game init function
int Game_Init(hWnd);
{
HRESULT result;
// initialize direct3d
d3d = Direct3DCreate9(D3D_SDK_VERSION);
if(d3d == NULL)
{
MessageBox(hWnd, "Error initializing direct3d", "Error!", MB_OK);
return 0;
}
// set direct3d parameters
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
d3dpp.hDeviceWindow = hWnd;
// create direct3d device
d3d = CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
if(d3ddev == NULL)
{
MessageBox(hWnd, "Error Creating direct3d device", "Error!", MB_OK);
return 0;
}
// set random number seed
srand(time(NULL));
// Clear Backbuffer to black
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
// create pointer to backbuffer
d3ddev->GetBackBuffer(0,0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
// create surface
result = d3ddev->CreateOffscreenPlainSurface(
640,
480,
D3DFMT_X8R8G8B8,
D3DPOOL_DEFAULT,
&surface,
NULL);
if(result != D3D_OK)
return 1;
result = D3DXLoadSurfaceFromFile(
surface, // destination surface
NULL, // destination palette
NULL, // destination rectangle
"legotron.bmp", // source filename
NULL, // source rectange
D3DX_DEFAULT, // controls how image is filtered
0, // transparancy, 0 for none
NULL); // source image info
if(result != D3D_OK)
return 1;
// draw surface to backbuffer
d3ddev->StretchRect(surface, NULL, backbuffer, NULL, D3DTEXF_NONE);
// return okay
return 1;
}
void Game_Run(hWnd)
{
RECT rect;
int r, g, b;
// make sure the direct3d device is still valid
if(d3ddev == NULL)
return;
// start rendering
if(d3ddev->BeginScene())
// create pointer to backbuffer
d3ddev->GetBackBuffer(0,0, D3DBACKBUFFER_TYPE_MONO,&backbuffer);
// draw surface to the backbuffer
d3ddev->StretchRect(surface, NULL,backbuffer, NULL, D3DTEXF_NONE);
// stop rendering
d3ddev->EndScene();
}
// Game end
void Game_End(hWnd)
{
// free the surface
surface->Release();
// release the directt 3d device
if(d3ddev != NULL)
d3ddev->Release();
// release the direct 3d object
if(d3d != NULL)
d3d->Release();
}