I'm new in DirectX technologies and I'm studing the book INTRODUCTION TO 3D GAME PROGRAMMING WITH DIRECTX 9.0 by Frank D.Luna.
Ok my doubt is about the initialization of DirectX. I placed the code d3Utiliy.h (above):
#include <d3dx9.h>
namespace d3d
{
bool InitD3D(
HINSTANCE hInstance,
int width, int height,
bool windowed,
D3DDEVTYPE deviceType,
IDirect3DDevice9** device);
int EnterMsgLoop(
bool (*ptr_display)(float timeDelta));
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);
template<class T> void Release(T t)
{
if (t) {
t->Release();
t = 0;
}
}
template<class T> void Delete(T t)
{
if (t) {
delete t;
t = 0;
}
}
}
int d3d::EnterMsgLoop(bool (*ptr_display)(float timeDelta))
{
MSG msg;
::ZeroMemory(&msg, sizeof(MSG));
static float lastTime = (float)timeGetTime();
while(msg.message != WM_QUIT) {
if (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else {
float currTime = (float)timeGetTime();
float timeDelta = (currTime = lastTime) * 0.001f;
ptr_display(timeDelta); // call display function
lastTime = currTime;
}
}
return msg.wParam;
}
and the d3dUtility.cpp (above)
#include "d3dUtility.h"
IDirect3DDevice9* Device = 0;
bool Setup()
{
return true;
}
void Cleanup()
{
}
bool Display(float timeDelta)
{
if (Device) {
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
0x00000000, 1.0f, 0);
Device->Present(0, 0, 0, 0);// present backbuffer
}
return true;
}
HRESULT IDirect3DDevice9::Clear(
DWORD Count,
const D3DRECT* pRects,
DWORD Flags,
D3DCOLOR Color,
float Z,
DWORD Stencil
);
LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_DESTROY:
::PostQuitMessage(0);
break;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
::DestroyWindow(hwnd);
break;
}
return ::DefWindowProc(hwnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE prevInstance,
LPSTR cmdLine,
int showCmd)
{
if (!d3d::InitD3D(hinstance, 800, 600, true, D3DDEVTYPE_HAL, &Device)) {
::MessageBox(0, "InitD3D() - FALIED", 0, 0);
return 0;
}
if (!Setup()) {
::MessageBox(0, "Setup() - FALLED", 0, 0);
return 0;
}
d3d::EnterMsgLoop(Display);
Cleanup();
Device->Release();
return 0;
}
Ok it compiled well, but Visual C++ 6.0 generated three Link Errors:
Compiling...
d3dUtility.cpp
Linking...
d3dUtility.obj : error LNK2001: unresolved external symbol "bool __cdecl d3d::InitD3D(struct HINSTANCE__ *,int,int,bool,enum _D3DDEVTYPE,struct IDirect3DDevice9 * *)" (?InitD3D@d3d@@YA_NPAUHINSTANCE__@@HH_NW4_D3DDEVTYPE@@PAPAUIDirect3 DDevice9@@@Z)
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/D3DEx.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Please people I'm trying to understand and program in DirectX...
Edited by Coder: Use source tags for large locks of code. Check
GDNet Forums FAQ
[Edited by - Coder on August 18, 2004 10:21:13 AM]