Windows 8 Store don't want to see d3dx9
in my app, that was written in DirectX 9
. But I need D3DXCreateTexture
function. I was found DirectXTex
, but it wants DirectX 11
. Is there any way to avoid rewriting all in DirectX 11
?

- 343
- 3
- 12
2 Answers
First you must load raw bitmap data. There are many ways:
- write your own loader ( not in 21st century oO )
- use library for a formats you need. Such as libpng, libjpeg, more on Google =)
- use multiformat library (C/C++ Image Loading). FreeImage is my favorite.
Then you must create IDirect3DTexture9 via D3DXCreateTextureFromFileInMemory or D3DXCreateTextureFromFileInMemoryEx and you are ready to go =)
Update:
Okay. We can't use it D3DXCreateTextureFromFileInMemory
. So... we can implement it.
As earlier, we must load bitmap to memory somehow (I prefer use FreeImage). Then we create empty IDirect3DTexture9* via CreateTexture() method. Then we copy contents of bitmap to that texture using LockRect()/UnlockRect(). That time we ready to go surely, because I've tested it! =) Test VS2012 solution including FreeType : link (messy and dirty, rewrite it please and wrap in a class )
The core function:
void CreateTexture(const wchar_t* filename)
{
unsigned int width(0), height(0);
std::vector<unsigned char> bitmap;
LoadBitmapFile(filename, bitmap, width, height); // Wrapped FreeImage
// Create empty IDirect3DTexture9*
pDevice->CreateTexture(width, height, 1, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture, 0);
if (!pTexture)
{
throw std::runtime_error( "CreateTexture failed");
}
D3DLOCKED_RECT rect;
pTexture->LockRect( 0, &rect, 0, D3DLOCK_DISCARD );
unsigned char* dest = static_cast<unsigned char*>(rect.pBits);
memcpy(dest, &bitmap[0], sizeof(unsigned char) * width * height * 4);
pTexture->UnlockRect(0);
}
Hope it helps.
P.S. Actually there was another problem: projection matrix. You will need to create it manually or use some math lib, because D3DXMatrix..() functions you can't use.

- 1
- 1

- 12,860
- 3
- 34
- 61
-
1D3DXCreateTextureFromFileInMemory is in `d3dx9.lib`, i can't use it – hoody Apr 24 '13 at 06:07
-
1I've updated my answer: we can create texture resources without D3DXCreateTextureFromFileInMemory. – Ivan Aksamentov - Drop Apr 24 '13 at 11:58
-
if it work's thats it) for matrix - DirectXMath using (#ifdef Win8). but will it be accepted by windows app store? i don't know after reading this http://social.msdn.microsoft.com/Forums/en-US/wingameswithdirectx/thread/c082b208-0d95-4c41-852f-9450340093f4/ – hoody Apr 24 '13 at 12:57
It seems the DirectX 9
code must be rewriten with DirectX 11
, cause DirectXTK
, DirectXTex
, DirectXMath
libs works only with DX11. More information I have found at http://social.msdn.microsoft.com/Forums/en-US/wingameswithdirectx/thread/c082b208-0d95-4c41-852f-9450340093f4/

- 343
- 3
- 12