0

I want to create a GUI system using Direct3D (not Direct2D) for my C++ game engine. I created a D3DXSprite, assigned a D3DXTexture, drawing it using another color than the background's... still it's not showing. What am I doing wrong here?

#include <d3dx9.h>

_Obst_PanelDx9::_Obst_PanelDx9( _Obst_Gui* owner, _Obst_Vector2& size ) : _Obst_Panel(owner)
{
    m_position = _Obst_Vector2( 0, 0 );
    m_size     = size;
    m_color    = _Obst_Vector4( 1, 1, 1, 1 );

    D3DXCreateSprite( ((_Obst_Gui*) owner)->getDisplayContext()->getD3Ddevice(), &m_sprite );
    D3DXCreateTexture( ((_Obst_Gui*) owner)->getDisplayContext()->getD3Ddevice(), m_size.x, m_size.y, 0, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_texture );
}

_Obst_PanelDx9::~_Obst_PanelDx9()
{
    if ( m_sprite )  m_sprite->Release();
    if ( m_texture ) m_texture->Release();
}

void _Obst_PanelDx9::render()
{
    m_sprite->Begin( D3DXSPRITE_ALPHABLEND );

    //m_sprite->Draw( m_texture, 0, 0, &D3DXVECTOR3(m_position.x, m_position.y, 0), D3DCOLOR_ARGB((int) (m_color.w * 255), (int) (m_color.x * 255), (int) (m_color.y * 255), (int) (m_color.z * 255)));

    // In order: ID3DXTexture* t, RECT* srcRect, D3DXVECTOR3* center, D3DXVECTOR3* position, D3DCOLOR color
    m_sprite->Draw( m_texture, 0, 0, &D3DXVECTOR3(0, 0, 0), 0xFFFFFFFF);

    m_sprite->End();
}

On the following image, there should be, if I'm not wrong, a white square on the top left corner of the window.

I tried tweaking alpha value, colors, tweaking D3DUSAGE, D3DPOOL and D3DFORMAT enums, setting the sprite's transform matrix, setting the center point and the srcRect param...

EDIT: Forgot to mention, my goal is not to display an image, the sprite is like a panel widget (a colored rectangle). It is just that the ID3DXTexture contains the size values.

Dave
  • 41
  • 8
  • If you pass ``D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_ALPHABLEND`` to ``ID3DXSprite::Begin``, does it become visible? – Asesh Mar 24 '19 at 07:01
  • No, it does not. I also forgot to precise that the texture object isn't actually used to display an image, it is used to size the sprite, because a texture contains the size values. Basically I want my sprite to act like a panel. – Dave Mar 24 '19 at 07:07
  • Why are you using legacy Direct3D at all? – Chuck Walbourn Mar 24 '19 at 20:21
  • For compatibility reasons. I want my game engine to run on those (now getting old) home windows 7 computers. I know windows 7 has support for directx 11, but I still wanna get a nostalgic feel in my code, and maybe extend my windows support to xp. This sounds really dumb actually, cause Microsoft's xp support has already ended. – Dave Mar 25 '19 at 15:51
  • D3DX9 is deprecated, closed-source, and hasn't been updated in ages. My recommendation is use DirectX 11 with [DirectX Tool Kit](https://github.com/Microsoft/DirectXTK/wiki/Getting-Started)'s ``SpriteBatch``. Windows 7 is pretty "nostalgic" at this point :) – Chuck Walbourn Apr 04 '19 at 04:48

0 Answers0