C++ Direct3D 9 : D3DXSprite not rendering

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.

c++
game-engine
direct3d9
asked on Stack Overflow Mar 24, 2019 by Dave • edited Mar 24, 2019 by Dave

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0