Getting started with D3D9

Posts 1–5 of 5 · Page 1 of 1
Getting started with D3D9
Hey guys.

Can anyone recommend some good and thorough tutorials on programming some Direct X 9 stuff (in c++). I've searched around the internet and can't find any decent ones that are tutorials on drawing stuff over a game.

I would like to start by drawing text over a game. Literally "Hello world!" in the top right corner of the screen when in game or something.

I would be using GTA: San Andreas which used Direct X 9.

Thanks guys!
just look at other menu sources or something, this should work:

drawing text:
Code:
//top of your project:
LPD3DXFONT Directx_Font;

VOID DrawText(LPDIRECT3DDEVICE9 Device, INT x, INT y, DWORD color, CHAR *text)
{
	RECT rect;
	SetRect(&rect, x, y, x + 100, y);
	Directx_Font->DrawText(NULL, text, -1, &rect, DT_CENTER | DT_NOCLIP, color);
}

//in endscene:
if (Directx_Font == NULL)
D3DXCreateFontA(Device, 14, 0, FW_BOLD, 0, 0, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &Directx_Font);

if (Directx_Font)
DrawText(Device, 10, 10, D3DCOLOR_ARGB(255, 255, 255, 249), "Hello world!");


//in reset:
if (Directx_Font)
Directx_Font->OnLostDevice();

HRESULT iReturnValue = OrigReset(Device, Params);

if (iReturnValue == D3D_OK)
{
	if (Directx_Font)
	Directx_Font->OnResetDevice();
}
drawing sprites:
Code:
bool SpriteCreated0 = NULL;
LPDIRECT3DTEXTURE9 IMAGE0;
LPD3DXSPRITE SPRITE0;
D3DXVECTOR3 ImagePos0;

//in endscene:
if (SpriteCreated0 == FALSE)
{
	D3DXCreateTextureFromFile(Device, "yourpng.png", &IMAGE0); //place png in game dir
	SpriteCreated0 = TRUE;
}
	D3DXCreateSprite(Device, &SPRITE0);

	ImagePos0.x = 100; //(int)ModelInfo[i]->Position2D.x;
	ImagePos0.y = 100 //(int)ModelInfo[i]->Position2D.y;
	ImagePos0.z = 0.0f;

	SPRITE0->Begin(D3DXSPRITE_ALPHABLEND);
	SPRITE0->Draw(IMAGE0, NULL, NULL, &ImagePos0, 0xFFFFFFFF);
	SPRITE0->End();
	if (SPRITE0 != NULL){SPRITE0->Release();}SPRITE0 = NULL ;
Thanks for your reply Ivous. The reason I wanted tutorials was because I'm not familiar with Direct X 9 code; I don't know how to get the device of the game or anything.

When I followed your code I understood that I need I possiblly need to hook the endscene and reset functions (Which I assumed because of "in endscene:" etc and I can do that) but I'm getting errors on the device pointer here:

Code:
//in endscene:
if (Directx_Font == NULL)
D3DXCreateFontA(Device, 14, 0, FW_BOLD, 0, 0, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &Directx_Font);

	if (Directx_Font)
	DrawText(Device, 10, 10, D3DCOLOR_ARGB(255, 255, 255, 249), "Hello world!");
and here:

Code:
HRESULT iReturnValue = Reset(Device, Params);
Because I don't know how to get the device in the first place then I can't point to it and as for the params parameter in:

Code:
Reset(Device, Params);
I have no idea what to pass it.

Thanks again.
can't give you a tutorial but you can use findpattern to find the d3d device, there is a d3d hook example in my signature
Code:
hD3D = (DWORD)GetModuleHandleA("d3d9.dll");
..
FindPattern(hD3D, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx");
..
Thanks again Ivous but I think I'm going to just step away from D3D all together, what's the point if I don't understand any of it, I didn't have a clue what to do after using the snippet you posted last.

I really don't understand why there isn't a tutorial for what I'm wanting to learn. All the tutorials I've seen have been about creating a windows form and displaying graphics in that not about hooking a game and displaying text over it and what not.

Ugh the internet is a weird place. You get people thata waltz on in and ask for everything to be done for them and they get told to RTFM and then you get the people who actually want to learn but can't find any good, thorough tutorials on what they want to learn.

Thanks again.
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us