本帖最后由 solidji 于 2011-7-5 14:52 编辑 3 K# {: @" X' S$ M7 ^. q
3 q6 M X$ e4 O# ]; T( u重新做一张更方便
" u7 P5 K1 q' c; \如果非要加在后面,也可以自己实现( k( N$ T3 s. Q% Q1 N
我给你提供个思路。我们先假设原来的字库你已经找到,并且是纹理图片字库
, \4 b, X; J3 u" T. J$ q首先
3 Y% _0 j7 L& z; z! I9 c/ sCreateVertexBuffer(sizeof(CnFontVertex)*6*8192, D3DUSAGE_DYNAMIC, FVF, D3DPOOL_SYSTEMMEM, ppVertexBuffer,pSharedHandle);//创建一个包含8192个字符的足够大的字库缓存" g- e3 R9 E; ?! p9 j/ \
g_pFontVertexBuffer = *ppVertexBuffer;
: y: K3 q7 c* D5 ~, D9 A4 p, R) o4 |" y g_pFontVertexBuffer->Lock(0,Length,(void**)&mem,0);
8 m+ x2 n$ |: s( x7 k) m1 Q' W g_pFontVertexBuffer->Unlock();$ \' ^ S/ `' t
+ t1 V3 ]5 Y9 q$ pCString font = _T(".\\font.bmp");//这个是自己要添加的新的字库
, l4 y# \1 r; V3 {* L D3DXCreateTextureFromFileEx(7 ^% {$ i6 A. U( e3 B% x
m_device, s4 u0 e/ ?: m; K! B" \
font,
, t" ?0 l' [2 i6 K1 ] O: k/ S( d7 D D3DX_DEFAULT,2 E5 S6 C2 D, ^" F
D3DX_DEFAULT,6 J* h- C; W: w" H* d
D3DX_DEFAULT,
; L7 V5 D S3 k 0,
3 H, |# S$ Q8 W( t D3DFMT_A1R5G5B5,+ |8 l: h& L3 J
D3DPOOL_MANAGED,1 h; D9 x: ?& m ?
D3DX_FILTER_TRIANGLE,- d" s! q! ^8 P& Q1 R
D3DX_FILTER_TRIANGLE,
* k3 h( g- G1 E1 }5 k/ l6 W( q D3DCOLOR_RGBA(0, 0, 0, 255),- q8 X. _4 z+ ?% F$ O
NULL,, W" Q: L1 N0 r% X/ y) ]4 Z
NULL," e; L* ~. s3 m( t3 T8 j p
&Tex);
% p( j7 r( y3 S. P6 V2 X. {. O( M+ [& c$ C1 V
IDirect3DTexture9* in = Tex->Lock(0, pDesc.Size, &pbData, D3DLOCK_READONLY);
% {5 n- E. U% H: w/ K( O把Tex里的数据lock到pbData
2 b* T7 Y+ ?7 \$ \6 E4 n% U# z然后把pbData里的数据copy到mem接在原本的字库后面
. J$ n) K: q( V7 ~g_pFontVertexBuffer->Lock(0,Length,(void**)&mem,0);8 v! C! n S5 ?! @: s3 R* r
memcpy(pbData,mem,len);4 w/ j6 S: ], f
g_pFontVertexBuffer->Unlock();3 S& ?: p: i* g' o6 ~' h5 x4 _
; Z. ]1 J" e) m) @& K最后保存成TGA
4 Q) x$ }" w" A# ~& g1 x2 KD3DXSaveTextureToFileA(“new字库.tga”, D3DXIFF_TGA, ppVertexBuffer, NULL);: h- Z: x. c4 q: b
3 T. G0 ]( v7 U/ k! H" @" a# r
这个代码我没调试随手写的,表达下思路而已,不可照搬 |