V
V
vlsnake2019-10-04 10:43:16
DirectX
vlsnake, 2019-10-04 10:43:16

How to display a png background image in DirectX 9 (10, 11, 12)?

Sobsno you need to add a background in the form of a picture to an existing project (the dimensions are taken from png).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vlsnake, 2019-10-04
@vlsnake

Problem in final code
- in general, I figured it out myself, but at a high level:
1. Step the texture itself - here a very unpleasant nuance came out with D3DXCreateTextureFromFile - you need to take D3DXCreateTextureFromFileEx:

extern "C" bool LoadTextureFromFile(const char* filename, void** out_texture, int* out_width, int* out_height)
{
    // Load texture from disk
    PDIRECT3DTEXTURE9 texture;
    D3DCOLOR color = 0xFFFFFFFF;

    HRESULT hr = D3DXCreateTextureFromFileExA(
    g_pd3dDevice, filename, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT, 0,
    D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, color, NULL, NULL,
    &texture);

    //HRESULT hr = D3DXCreateTextureFromFileA( &texture);
    if (hr != S_OK)
        return false;

    // Retrieve description of the texture surface so we can access its size
    D3DSURFACE_DESC my_image_desc;
    texture->GetLevelDesc(0, &my_image_desc);
    *out_texture = (void *)texture;
    *out_width = (int)my_image_desc.Width;
    *out_height = (int)my_image_desc.Height;
    return true;
}

2. The output was taken in pieces from
imgui_impl_dx9.cpp how to load data - stbi_load() - not a problem - but how to stuff it all into DIRECT3DTEXTURE9 is not high-level so that it can be modified - there is still to be thought about.
I also figured out the 11th version of DirectX, but the 12th maleh of the problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question