0

I have spent the afternoon looking over the documentation on the contexts / surfaces and followed quite a few guides but I just do not understand how this is done.

All I want is to use a bitmap (already loaded) and to put it into my scene as the background.

I heard that I have to use a surface and draw it first but I have absolutely no idea how to obtain the surface or how to assign the bitmap to it.

Any help is appreciated.

3
  • 1
    As you are new to DirectX 11, you should take a look at DirectX Tool Kit. You can easily use the SpriteBatch class to render a texture loaded with the DDSTextureLoader or WICTextureLoader classes. See the Sprites and textures lesson in particular. Commented Jan 26, 2016 at 6:19
  • Will do. I am actually being taught in DirectX 9 but just would not for the life of me install on my machine so I have to try and work backwards using 11. Commented Jan 26, 2016 at 6:31
  • The legacy DirectX SDK (June 2010) should install on modern versions of Windows, but requires some workarounds. There are also aspects of it that do not work with DirectX 11.1 Runtime or later (i.e. Windows 8 or later, and Windows 7 SP1 with the KB2670838 update). See DirectX 11.1 and Windows 7. There are also important differences when working with VS 2012 or later. Commented Jan 26, 2016 at 6:43

1 Answer 1

1

Yes one method is to use Surface, however I would recommend this method

I am not sure how you have loaded bitmap, anyhow you can use bitmap as background in this way

//Make texture object LPDIRECT3DTEXTURE9 m_myBitmapTexture; // During Initialization, Load texture from file if(FAILED(D3DXCREATETEXTUREFROMFILE(device,"filepath\\file.bmp", 0, 0, 0, D3DMFT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFULT, D3DX_DEFAULT, 0x00000000, NULL, NULL, *m_myBitmapTexture))) return E_FAIL; // During Rendering, set texture device->SetTexture(0, m_myBitmapTexture); device->SetStreamSource(0, yourBuffer, 0, size(YourBufferStruct)); device->SetFVF(yourTextureFVF); // Setting flexible vertex format device->DrawPrimitive(topologyType, startindex, totalIndex); 

You just need to make sure, your buffer should have texture coordinates and your shader too

struct YourBufferStruct { D3DXVECTOR3 position; D3DXVECTOR2 textureCoord; } // Define your flexible vertex format, i am just adding position and texture, //well you can add color, normal whatever extra you want #define yourTextureFVF (D3DFVF_XYZ | D3DFVF_TEX1) 

Now add texture coordinates to shader too

For more details you can consult this link https://msdn.microsoft.com/en-us/library/windows/desktop/bb153262(v=vs.85).aspx

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much! I believe this is what I needed.
Note this was a great answer 10 years ago. Direct3D 9 is deprecated with little to no debugging support on modern versions of Windows. All versions of D3DX including D3DX9, D3DX10, and D3DX11 are deprecated, only available in the legacy DirectX SDK, which itself is deprecated, and deployed by the legacy DirectSetup package which is also deprecated. See MSDN
Still many organizations are using DirectX SDK, Now a days DirectX SDK is part of Windows SDK and most of the methods are almost same in both.
Am I able to use LPDIRECT3DTEXTURE9 m_myBitmapTexture; in DirectX 11?
The methods are the same in the Windows SDK with respect to the Direct3D 9 API, but not D3DX9. D3DXCREATETEXTUREFROMFILE is only in the legacy DirectX SDK. And no, none of this code will work for DirectX 11.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.