开发者

DirectX 10 Draw Text to texture

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). Aft开发者_如何学Cer 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜