less..
#include "spft.h"
cSPFT::cSPFT()
{
FT_Error error = FT_Init_FreeType( &library );
if ( error )
{
// ¿¡·¯
MessageBox(spGetHWND(), "FT_Init_FreeType","error", MB_OK);
}
//error = FT_New_Face( library, "jbfont2.ttf", 0, &face );
error = FT_New_Face( library, "¾Æ¸®µûSB.ttf", 0, &face );
if ( error == FT_Err_Unknown_File_Format )
{
// ¿¡·¯
MessageBox(spGetHWND(), "FT_New_Face : FT_Err_Unknown_File_Format","error", MB_OK);
}
else if (error)
{
// ¿¡·¯
MessageBox(spGetHWND(), "unknown","error", MB_OK);
}
error = FT_Set_Pixel_Sizes( face, /* handle to face object */
15, /* pixel_width */
15 ); /* pixel_height */
}
void cSPFT::Print(float x, float y, char *Text)
{
FT_GlyphSlot slot = face->glyph; /* a small shortcut */
int pen_x, pen_y, n;
FT_Error error ;
pen_x = 0;
pen_y = 0;
BYTE tBuffer[64*64*4];
int i,j;
memset(tBuffer, 0, 64*64*4);
// TextÀ̶õ ANSI ¹®ÀÚ¿À» bstrÀ̶õ À̸§ÀÇ À¯´ÏÄÚµå(BSTR ŸÀÔ) º¯¼ö·Î º¯È¯
wchar_t *bstr;
// TextÀ» À¯´ÏÄÚµå·Î º¯È¯Çϱ⿡ ¾Õ¼ ¸ÕÀú ±× ±æÀ̸¦ ¾Ë¾Æ¾ß ÇÑ´Ù.
int nLen = MultiByteToWideChar(CP_ACP, 0, Text, lstrlen(Text), NULL, NULL);
// ¾ò¾î³½ ±æÀ̸¸Å ¸Þ¸ð¸®¸¦ ÇÒ´çÇÑ´Ù.
bstr = SysAllocStringLen(NULL, nLen);
// ÀÌÁ¦ º¯È¯À» ¼öÇàÇÑ´Ù.
MultiByteToWideChar(CP_ACP, 0, Text, lstrlen(Text), bstr, nLen);
for ( n = 0; n < nLen; n++ )
{
error = FT_Load_Char( face, bstr[n], FT_LOAD_RENDER );
if ( error ) continue; /* ignore errors */
memset(tBuffer, 0, 64*64*4);
for(i=0;i<slot->bitmap.width;i++)
{
for(j=0;j<slot->bitmap.rows;j++)
{
tBuffer[(j*64+i)*4+0]=255;
tBuffer[(j*64+i)*4+1]=255;
tBuffer[(j*64+i)*4+2]=255;
tBuffer[(j*64+i)*4+3]=slot->bitmap.buffer[j*slot->bitmap.pitch+i];
}
}
LPDIRECT3DTEXTURE9 f=spCreateTexture(tBuffer, 64, 64, 4 );
spPutImg(f, pen_x+ x + slot->bitmap_left, y - slot->bitmap_top, 64, 64);
f->Release();
pen_x += slot->advance.x >> 6;
}
}