|
|
发表于 2007-7-28 20:02:00
|
显示全部楼层
Re:Direct3D中关于纹理的问题
基本上只要有了纹理的内存指针就能干很多事了吧~
我自己用的写字是用freetype2的,代码大约就是下面这样,因为没怎么用过,
所以写的不是很严谨,还有些问题没解决~就大概看下意思吧
- void CslothFTfreetype2::SetText(STEXTURE texture, char* text, DWORD color,int offsetx,int offsety)
- {
- m_slot = m_face->glyph;
- IslothGX* gxDriver=m_ownDevice->GetGXDriver();
- int tex_width=gxDriver->GetTextureWidth(texture);
- DWORD* color_arr=gxDriver->LockTexture(texture);
- m_matrix.xx = (FT_Fixed)( 0x10000L );
- m_matrix.xy = (FT_Fixed)( 0 * 0x10000L);
- m_matrix.yx = (FT_Fixed)( 0 * 0x10000L);
- m_matrix.yy = (FT_Fixed)( 0x10000L );
- m_pen.x = 0;
- m_pen.y = 0;
- int src_length=strlen(text);
- u16* uni_text=new u16[src_length];
- memset(uni_text,0,sizeof(u16)*src_length);
- GBToUnicode(text,uni_text);
- int dest_length=wcslen(uni_text);
- for(int n=0;n<dest_length;n++)
- {
- if(uni_text[n]==0xfdfd)
- break;
- FT_Set_Transform( m_face, &m_matrix, &m_pen );
- m_error = FT_Load_Char( m_face,uni_text[n], FT_LOAD_RENDER );
- if ( m_error )
- continue;
- if(n==0)
- {
- offsety+=m_slot->bitmap_top;
- offsetx+=m_slot->bitmap_left;
- }
- for (int i=offsetx;i<offsetx+m_slot->bitmap.width;i++)
- for(int j=offsety;j<offsety+m_slot->bitmap.rows;j++)
- {
- int alpha=m_slot->bitmap.buffer[(j-offsety)*m_slot->bitmap.width+i-offsetx];
- color=SETA(color,alpha);
- color_arr[tex_width*(j-m_slot->bitmap_top)+(i+m_slot->bitmap_left)]=color;
- }
- if(uni_text[n]<128)
- m_pen.x += m_slot->advance.x;
- else
- m_pen.x += m_slot->advance.x;
- m_pen.y += m_slot->advance.y;
- }
- gxDriver->UnlockTexture(texture);
- delete []uni_text;
- }
复制代码
这东西对ttf字体有效~~~
楼主如果想方便的话就用asc和hzk的点阵字库吧~只要把数据读出来打点就可以了
网上一片这东西的教程和代码,比如:http://www.61ic.com/bbs/read.php?tid=2465&page=e
好象也可以用别的软件把字体文件转成点阵格式的用...
|
|