Reputation: 363
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
?
Upvotes: 1
Views: 3939
Reputation: 13003
First you must load raw bitmap data. There are many ways:
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.
Upvotes: 3
Reputation: 363
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/
Upvotes: -1