我现在正在获得双字母,尽管从通过加载单个字符创建的缓冲区复制如下:
[复制角色’a’的尝试]
以下是我目前的代码:
void TexFont::freeTypeSave() { static FT_Library library; /* handle to library */ static FT_Face face; /* handle to face object */ if (FT_Init_FreeType(&library)) { NHelper::OutputDebugStringN("error"); } if (FT_New_Face(library,TEXT("Fonts\\arial.ttf"),&face)) { NHelper::OutputDebugStringN("font load failed\n"); } else { //NHelper::OutputDebugStringN("font faces: %d \n",face->num_faces); } static int error; static UINT width,height; static int mTtfSize = 64; static int mTtfResolution = 96; static IDirect3DTexture9* mTexture; static unsigned int mPixelBytes = 2; static unsigned int mDataSize = width * height * mPixelBytes; // size settings (convert font size to *64) FT_F26Dot6 ftSize = (FT_F26Dot6)(mTtfSize * (1 << 6)); error=FT_Set_Char_Size(face,ftSize,mTtfResolution,mTtfResolution); // load glyph + render error = FT_Load_Char( face,L'a',FT_LOAD_RENDER ); if (error) NHelper::OutputDebugStringN("could not load char"); // start copy procedure width = face->glyph->bitmap.width; height = face->glyph->bitmap.rows; D3DXCreateTexture( g_engine->getDevice(),width,height,1,D3DFMT_A8L8,D3DPOOL_MANAGED,&mTexture); D3DLOCKED_RECT lockedRect; mTexture->LockRect(0,&lockedRect,0); unsigned char* pSrcPixels = face->glyph->bitmap.buffer; unsigned char* pDestPixels = (unsigned char*)lockedRect.pBits; for(UINT i = 0; i < height; ++i) { //copy a row memcpy(pDestPixels,pSrcPixels,width * 2); //2 bytes per pixel (1byte alpha,1byte greyscale) //advance row pointers pSrcPixels += face->glyph->bitmap.pitch; pDestPixels += lockedRect.Pitch; } NHelper::OutputDebugStringN("char width: %d,height: %d \n",height); mTexture->UnlockRect(0); D3DXSaveTextureToFileA("test.png",D3DXIFF_PNG,mTexture,0); // release face FT_Done_Face(face); // library shutdown FT_Done_FreeType(library); }
关于发生了什么以及如何解决这个问题的任何想法?
注意:更改字体大小只会创建更大的图像.我仍然得到相同的结果.
–update–
尝试Drop的建议,我尝试更改我的memcpy(pDestPixels,width * 2);
memcpy(pDestPixels,width * 1);它返回以下内容:
一个字形打包在图像的左侧,但图像保持相同的大小.
(字形只占用图像空间的一半)
解决方法
FT_Load_Char(face,L’a’,FT_LOAD_RENDER);
这意味着that
By default,the glyph is rendered in FT_RENDER_MODE_NORMAL mode
和
07001 This is the default render mode; it corresponds to 8-bit anti-aliased bitmaps.
但你复制为16位:
memcpy(pDestPixels,width * 2); //每像素2个字节(1字节alpha,1字节灰度)
你真的不需要在任何角色中使用灰度组件来进行正确的渲染(你只需要知道必须为这个像素应用颜色和多少).因此,在加载时将所有字符设为8位掩码.
然后在渲染之前转换为32位图像:在RGB组件中应用颜色并将掩码设置为A组件.我在着色器中做到了.
希望能帮助到你.快乐的编码!
更新1
由于现在你正在复制8位源,每个像素记忆8位,显然你还需要将你的目标(mTexture)调整为每像素相同的位:D3DFMT_A8(8位)而不是D3DFMT_A8L8(8 8 = 16位) ).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。