user3213103
user3213103

Reputation: 133

C++ DirectX - Load texture

I'm using how-to 1 source DX9 from http://www.mikoweb.eu/index.php?node=28

Everything works fine on that example, but now I'd like to use PNG (or any format with alpha and better compression) rather than BMP.

Function call is:

 D3DXCreateTextureFromResourceEx(m_pD3DDevice,
                               gl_hThisInstance,
                               MAKEINTRESOURCE(IDB_BITMAP1),
                               256,
                               128,
                               0,
                               NULL,
                               D3DFMT_UNKNOWN,
                               D3DPOOL_MANAGED,
                               D3DX_FILTER_NONE,
                               D3DX_FILTER_NONE,
                               0xFF000000,
                               NULL,
                               NULL,
                               &m_pBackgroundTexture);

Resource file:

IDB_BITMAP1             BITMAP                  "background.bmp"

I change resource to:

IDB_BITMAP1             RC_DATA                  "pic.png"

After my change D3DXCreateTextureFromResourceEx return D3D_OK, however there is nothing displayed on screen. After seeing documentation my quick thought was that I should specify format in D3DXIMAGE_INFO structure (and left rest as 0, still nothing.

My final goal is to load texture from file, so I tried:

D3DXCreateTextureFromFileEx(m_pD3DDevice, "pic.png", 200, 200, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, D3DCOLOR_ARGB(150,100,100,100), NULL, NULL, &m_pBackgroundTexture);

But it didn't worked.

Upvotes: 1

Views: 1600

Answers (1)

user3213103
user3213103

Reputation: 133

Problem was because there were specified Height and Width in D3DXCreateTextureFromFileEx, leaving both parameters as 0 loaded texture correctly on all formats.

But that didn't make my textures appear as alpha on screen.

By googling I found:

m_pBackgroundSprite->Begin(D3DXSPRITE_ALPHABLEND);

which solved the problem.

Upvotes: 1

Related Questions