I'm working in C++ with DirectX 9 on a 3D game, but I want a 2D overlay for rendering a HUD.

I've heard that I could use D3DXMatrixOrthoLH, but I'm very confused on how to use it. I'm more familiar with OpenGL, where I could simply switch between 3D and 2D by initiating the view.

How can I do this in DirectX 9?


I was able to achieve this like (partial psudocode):

But I have a good feeling this is not the right way to do it.

void render()

    D3DXMATRIX matrix;

    D3DXMatrixTranslation(&matrix, 0, 0, 0);
    device->SetTransform(D3DTS_WORLD, &matrix);

    // Render 3D.


    device->SetTransform(D3DTS_WORLD, &matrix);
    device->SetTransform(D3DTS_VIEW, &matrix);

    device->SetTransform(D3DTS_PROJECTION, &matrix);

    // Render 2D.

  • \$\begingroup\$ Thanks for all the help guys. I've decided to scratch DirectX and go back to good old OpenGL, which I'm much more familiar with. \$\endgroup\$ Commented Nov 1, 2015 at 12:21

1 Answer 1


The simplest way to achieve this, is probably the ID3DXSprite interface.

The ID3DXSprite interface provides a set of methods that simplify the process of drawing sprites using Microsoft Direct3D.

The ID3DXSprite interface is obtained by calling the D3DXCreateSprite(...) function

This call requires a valid pointer to an IDirect3DDevice9 object.

To use this interface, simply call Draw for each texture you want to be rendered, between a call to Begin and End. Since Begin will alter the device state, you should make sure your other rendering happens before Begin, or after End, which restores the previous state.

To rotate or scale a texture, you can create a matrix and pass it to SetMatrix before your Draw call.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .