【发布时间】:2013-04-24 20:13:51
【问题描述】:
Windows 8 应用商店不想在我的应用程序中看到d3dx9,这是用DirectX 9 编写的。但我需要D3DXCreateTexture 功能。我被发现DirectXTex,但它想要DirectX 11。有什么办法可以避免DirectX 11中的全部重写?
【问题讨论】:
标签: directx windows-store-apps
Windows 8 应用商店不想在我的应用程序中看到d3dx9,这是用DirectX 9 编写的。但我需要D3DXCreateTexture 功能。我被发现DirectXTex,但它想要DirectX 11。有什么办法可以避免DirectX 11中的全部重写?
【问题讨论】:
标签: directx windows-store-apps
首先您必须加载原始位图数据。方法有很多:
然后您必须通过D3DXCreateTextureFromFileInMemory 或D3DXCreateTextureFromFileInMemoryEx 创建IDirect3DTexture9,然后您就可以开始了=)
更新:
好的。我们不能使用它D3DXCreateTextureFromFileInMemory。所以...我们可以实现它。
如前所述,我们必须以某种方式将位图加载到内存中(我更喜欢使用 FreeImage)。然后我们通过 CreateTexture() 方法创建 empty IDirect3DTexture9*。然后我们使用LockRect()/UnlockRect() 将位图的内容复制到该纹理。那个时候我们肯定准备好了,因为我已经测试过了! =) 测试包含 FreeType 的 VS2012 解决方案:link(又脏又乱,请重写并封装在一个类中)
核心功能:
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);
}
希望对你有帮助。
附:其实还有一个问题:投影矩阵。您将需要手动创建它或使用一些数学库,因为您无法使用 D3DXMatrix..() 函数。
【讨论】:
d3dx9.lib,我不能使用它
似乎DirectX 9 代码必须用DirectX 11 重写,因为DirectXTK、DirectXTex、DirectXMath 库仅适用于DX11。我在http://social.msdn.microsoft.com/Forums/en-US/wingameswithdirectx/thread/c082b208-0d95-4c41-852f-9450340093f4/找到了更多信息
【讨论】: