众所周知,DX11不再支持将文本写入屏幕。我想通过使用DX11创建纹理并为DX10共享纹理来做到这一点,这样它就可以通过ID3DX10Font接口来绘制纹理了。然后混合所有与DX11着色器。我在尝试打开Dx11创建的Dx10纹理时出错了。以下是代码:
D3D11_TEXTURE2D_DESC desc;
ZeroMemory(&desc,sizeof(D3D11_TEXTURE2D_DESC));
desc.ArraySize = 1;
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.Height = 480;
desc.Width = 640;
desc.MipLevels = 1;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
Globals::hr = D3D10CreateDevice(0,D3D10_DRIVER_TYPE_HARDWARE,0,0,D3D10_SDK_VERSION,&Globals::pD3D10Device);
Globals::hr = Globals::pD3D11Device->CreateTexture2D(&desc,0,&Globals::backBuffer10);
//keyed mutex for DX11 device
Globals::hr = Globals::backBuffer10->QueryInterface(__uuidof(IDXGIKeyedMutex),(void**)(&Globals::mutex11));
//Get the shared handle so that DX10 can render on texture
IDXGIResource *sharedResource10;
Globals::hr = Globals::backBuffer10->QueryInterface(__uuidof(IDXGIResource),(void**)(&sharedResource10));
Globals::hr = sharedResource10->GetSharedHandle(&Globals::sharedHandle);
sharedResource10->Release();
//open texture for DX10
IDXGISurface *sharedSurface10;
ID3D10Texture2D *sharedTexture10;
Globals::hr = Globals::pD3D10Device->OpenSharedResource(Globals::sharedHandle,__uuidof(IDXGISurface),(void**)(&sharedSurface10));我从代码的最后一行得到了一个E_INVALIDARGS。有什么想法吗?DX11和DX10设备都是使用DRIVER_TYPE_HARDWARE标志创建的,并且都使用R8G8B8A8_UNORM作为back缓冲区格式。
发布于 2013-11-09 04:20:58
你不需要对付这些邪恶的黑客,因为:
ID3DX10Font和ID3DX10Sprite真的很慢很烂- [DirectX Tool Kit](https://directxtk.codeplex.com/)'s `SpriteFont` from Microsoft folks
- [FW1FontWrapper](http://fw1.codeplex.com/) - superfast one
- Tons for OpenGL (you can adapt them easily)
- make your own: [click](http://rastertek.com/dx11tut12.html), [click](http://www.braynzarsoft.net/index.php?p=D3D11FONT). [FreeType](http://www.freetype.org/) will make it easy.
https://stackoverflow.com/questions/19868677
复制相似问题