从RGBA(const char *)缓冲区创建DirectX9Texture

时间:2015-01-15 18:24:37

标签: c++ directx awesomium

我有一个RGBA格式的图像缓冲区,我需要将它转换为DirectX9Texture,我已经多次搜索过互联网,但没有任何实质内容。

我正在尝试将Awesomium集成到我的DirectX9应用程序中。换句话说,尝试在DirectX表面上显示网页。是的,我尝试创建自己的表面类,没有成功。

我知道冬天不能太长,所以如果你有怜悯,也许你可以将我链接到一些正确的地方?

1 个答案:

答案 0 :(得分:0)

您不能直接创建曲面,必须创建纹理,然后使用其曲面。虽然,为了您的目的,您不需要直接访问表面。

IDirect3DDevice9* device = ...;
// Create a texture: http://msdn.microsoft.com/en-us/library/windows/desktop/bb174363(v=vs.85).aspx
// parameters should be fairly obvious from your input data.
IDirect3DTexture9* tex;
device->CreateTexture(w, h, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, 0);
// Lock the texture for writing: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205913(v=vs.85).aspx
D3DLOCKED_RECT rect;
tex->LockRect(0, &rect, 0, D3DLOCK_DISCARD);
// Write your image data to rect.pBits here. Note that each scanline of the locked surface 
// may have padding, the rect.Pitch will tell you how many bytes each scanline expects. You
// should know what the pitch of your input data is. Also, if your image data is in RGBA, you
// will have to swizzle it to ARGB, as D3D9 does not have a RGBA format.

// Unlock the texture so it can be used.
tex->UnlockRect(0);

此代码还会忽略由于这些函数调用而可能发生的任何错误。在生产代码中,您应该检查是否存在任何可能的错误(例如,来自CreateTexture和LockRect)。