Frank Luna - DirectX 9.0 A Shader Approach

Started by
7 comments, last by marvel_magnum 12 years, 2 months ago
I have been looking through the above book copying the examples in, but they are not working. I don't if it is me or the technology I am using, and if its the latter I can save time not trying. I am using

Visual C++ 2010 Express edition
Windows XP (about to upgrade)
DirectX 9 SDK

I have a reasonable grounding in C++ and have figured out the configuration properties for the libraries to call d3d9.h etc. I'll give more specifics on the code that isnt working once I know the answer to this question.
Advertisement
DX9, WinXP and VS2K10 should work fine. The problem lies elsewhere. Could you provide more details about the error ? huh.png
starting to vs 2010 you should manually link the dxsdk library to the linker in the project proprieties... or manually editing the MSbuild profile..

fortunately the next DXSDK should be a part of the next windows sdk, so this problem will solved..

#if defined(DEBUG) | defined(_DEBUG)
#ifndef D3D_DEBUG_INFO
#define D3D_DEBUG_INFO
#endif
#endif

#include <iostream>
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dUtil.h>
#include <d3dApp.h>
#include <tchar.h>
#include <DxErr.h>
#include <crtdbg.h>

using namespace std;

#if defined(DEBUG) | defined(_DEBUG)
#ifndef HR
#define HR(x)
\
{
\
{
\
HRESULT hr = x;
\
if(FAILED(hr))
\
{
\
DXTrace(__FILE__, __LINE__, hr, #x, TRUE);
\
}
\
}
#endif
#else
#ifndef HR
#define HR(x) x;
#endif
#endif

HRESULT DXTrace(CHAR *strFile, DWORD dwline,
HRESULT hr, CHAR *strMsg, BOOL bPopMsgBox);

class HelloD3DApp : public D3DApp
{
public:
HelloD3DApp(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP);
~HelloD3DApp();

bool checkDeviceCaps();
void onLostDevice();
void onResetDevice();
void updateScene(float dt);
void drawScene();

private:
ID3DXFont* mFont;
};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)

{
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
// enable runtine memory chack for debug builds
#if defined(DEBUG) | defined(_DEBUG)_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

HelloD3DApp app(hInstance, "Hello Direct3D", D3DDEVTYPE_HAL, D3DCREATE_HARDWARE_VERTEXPROCESSING);
gd3dApp = &app;

return gd3dApp->run();
}



HelloD3DApp::HelloD3DApp(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
HRESULT DXTrace(CHAR *strFile, DWORD dwline, HRESULT hr, CHAR *strMsg, BOOL bPopMsgBox);
srand(time_t(0));

if(!checkDeviceCaps())
{
MessageBox(0, "checkDeviceCaps() Failed() Failed", 0, 0);
PostQuitMessage(0);
}

D3DXFONT_DESC fontDesc;
fontDesc.Height = 80;
fontDesc.Width = 40;
fontDesc.Weight = FW_BOLD;
fontDesc.MipLevels = 0;
fontDesc.Italic = true;
fontDesc.CharSet = DEFAULT_CHARSET;
fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
fontDesc.Quality = DEFAULT_QUALITY;
fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
_tcscpy(fontDesc.FaceName, _T("Times New Roman"));

HR(D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont));
}

HelloD3DApp::~HelloD3DApp()
{
ReleaseCOM(mFont);
}

#define ReleaseCOM(x) {if(x) {x->Release();x = 0; } }

bool HelloD3DApp::checkDeviceCaps()
{
return true;
}

void HelloD3DApp::updateScene(float dt)
{
}

void HelloD3DApp::onLostDevice()
{
HR(mFont->OnLostDevice());
}
void HelloD3DApp::onResetDevice()
{
HR(mFont->OnResetDevice());
}

void HelloD3DApp::drawScene()
{
HR(gd3dDevice->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0F, 0));

RECT formatRect;
GetClientRect(mhMainWnd, &formatRect);

HR(gd3dDevice->BeginScene());

mFont->DrawTextA(0, _T("Hello Direct3D"), -1, &formatRect, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(rand()% 256, rand() % 256, rand() % 256));

HR(gd3dDevice->EndScene());
HR(gd3dDevice->Present(0,0,0,0,));
}

HRESULT IDirect3DDevice9::Clear(
DWORD Count, const D3DRECT* pRects,
DWORD Flags, D3DCOLOR Color,
float Z,
DWORD Stencil);

INT ID3DXFont::DrawText(
LPD3DXSPRITE pSprite,
LPCTSTR pString,
INT Count,
LPRECT pRect,
DWORD Format,
D3DCOLOR Color);



is what I have so far. It doesn't recognise d3dx9.h, d3dUtil.h, d3dApp.h, DxErr.h. Looking through the includes library these are not present so I need a reliable way to get them.

I'm also dubious about the macros I have copied in as it is a little vague precisely where they go.
Are you able to locate the files d3dx9.h, d3dUtil.h, d3dApp.h, DxErr.h in your DX9 include path ? Are those files present ?

Which release of DX9 SDK are you using ? Sometimes when following old books, it happens that the latest SDK gets modified and some code mentioned in the book stops working. So if possible use the SDK version supplied with the book.

Sometimes when following old books, it happens that the latest SDK gets modified and some code mentioned in the book stops working. So if possible use the SDK version supplied with the book.


I think that's the long and short of it. I got June 2010 release, although Util and App are actually on his website which I couldn't get to before. I can use code from directxtutorial.com with no problems but Luna gives all sorts of char conversion problems etc.

...but Luna gives all sorts of char conversion problems etc.


Sounds like you have your project set to UNICODE, which is the default in VS. Go to Project, Properties, General and change Use Character Set to Multibyte.
Amazingly after a lot of frustration, googling, downloading this and that, banging head off walls etc. it is SOLVED. I downloaded an older SDK from about 2006 (year the book was published) which found the missing libraries, then googled to another post on here about the missing objbase.h problem where you need to add the windows SDK in the directories folder. Maybe I have the determination to be games developer after all.

It does make me realise how dated this software is but I need to upgrade to Windows 7 to use Directx 11 so this is a good start.

So if possible use the SDK version supplied with the book.


Like I said before. Anyways, its great that you finally got it. Welcome to the world of game development. happy.png

This topic is closed to new replies.

Advertisement