Results 1 to 5 of 5
  1. #1
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful

    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!

  2. #2
    lvous's Avatar
    Join Date
    Dec 2013
    Gender
    male
    Posts
    63
    Reputation
    10
    Thanks
    348
    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 ;
    Last edited by lvous; 08-25-2014 at 03:05 PM.

  3. #3
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful
    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.
    Last edited by K^2; 08-26-2014 at 09:46 AM.

  4. #4
    lvous's Avatar
    Join Date
    Dec 2013
    Gender
    male
    Posts
    63
    Reputation
    10
    Thanks
    348
    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");
    ..

  5. #5
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful
    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.

Similar Threads

  1. [C/C++ Tutorial] Getting Started With Visual C++/CLI
    By Hassan in forum Programming Tutorials
    Replies: 44
    Last Post: 04-02-2021, 07:16 PM
  2. [Help] Getting Started With C++ [Solved]
    By Cehk! in forum C++/C Programming
    Replies: 6
    Last Post: 11-29-2011, 04:39 AM
  3. [Help] Getting started with Uniform Spatial Subdivision.
    By bubblesppf in forum C++/C Programming
    Replies: 0
    Last Post: 07-25-2011, 01:49 PM
  4. Getting started with Mw 2 MPGH
    By lolbie in forum Call of Duty Modern Warfare 2 Private Servers
    Replies: 27
    Last Post: 07-31-2010, 08:51 PM
  5. [Tutorial] Getting Started With a On Screen KeyBoard
    By CoderNever in forum Visual Basic Programming
    Replies: 11
    Last Post: 12-02-2009, 05:02 PM

Tags for this Thread