DirectX 10绘制文本到纹理 [英] DirectX 10 Draw Text to texture

查看:318
本文介绍了DirectX 10绘制文本到纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在等待绘制文本到纹理网格物体。网格基本上是一个已经粘贴到屏幕前面的立方体。 (总体来说我的目标是一个菜单系统)。经过一番谷歌搜索,我发现令人惊讶的很少有关如何绘制文本纹理的信息。我读过,它应该像制作纹理一样简单,将其设置为渲染源,然后绘制它,但我不能算出这一个。

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.

推荐答案

当需要渲染文本时,

创建字体和sprite

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);

并渲染

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);

请注意,sprite渲染更改混合状态,因此请务必将其设置为默认值。如果你只需要纯平表面上的文本(网格上没有纹理映射),你可以将sprite渲染为主场景而不是纹理。

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.

这篇关于DirectX 10绘制文本到纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆