DirectX 10 Draw Text to texture

亡梦爱人 提交于 2019-12-24 10:27:11

问题


I am atempting to draw text to a textured mesh object. The mesh is basically a cube which has been pasted up to the front of the screen. (overall I'm aiming for a menu system). After a bit of googling I've found surprisingly little information on how to draw a text to a texture. I've read that it should be as simple as making a texture, setting it as a render source and then drawing to it, yet I cannot figure this one out.

Any ideas, suggestions or skeleton code with the necessary function calls to give me a jump start?


回答1:


When you need to render text into texture, you should setup rendering to texture as Adam suggested, to actually render some text you can do this

Create font and sprite

D3DX10CreateFont(device, 16, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Verdana", &font);
D3DX10CreateSprite(device, 256, &sprite);

and render

hr = sprite->Begin(0);
left = L"Some text to render";
RECT r;
r.top = 0;
r.bottom = window->height;
r.left = 0;
r.right = window->width;
hr = font->DrawTextW(sprite, left.c_str(), -1, &r, DT_LEFT | DT_TOP | DT_CALCRECT, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f));
hr = font->DrawTextW(sprite, left.c_str(), -1, &r, DT_LEFT | DT_TOP, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f));
//hr = sprite->Flush();
hr = sprite->End();
device->OMSetBlendState(NULL, 0, 0xffffffff);

Beware, sprite rendering changes blend state, so be sure to set it to default. If you need only "text on plain surface" (no texture mapping on mesh) you could render sprite into main scene instead of texture.




回答2:


See the section "Rendering to a texture" in Creating Texture Resources for some very helpful documentation. That provides several snippets of example code that should help you get on your way.



来源:https://stackoverflow.com/questions/4202010/directx-10-draw-text-to-texture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!