sdl_ttf등의 외부 라이브러리와 별도폰트를 쓰지않고 기기내에 포함되어있는 기본 비트맵 폰트로 문자를 출력하는 방법입니다.
비트맵이기때문에 가독성이 좋다는 장점이 있지만 크기가 고정적이라는 단점도 있지요.
기본프로그램인 이북뷰어에서와 같은 폰트를 사용합니다.
간단하게 사용할 수 있으니 디버깅출력용으로도 쓸만합니다.^^
sprintH 같은거 만들어 쓰시면 되겠죠.

먼저 프로젝트 설정>매개변수>링커 에다 -lunicodefont 추가합니다.

다음 리스트에서 실제로 쓰는 함수는 printH 입니다.

->printH( screen, 100, 10, "가나다라마바사", 0xffff );




한글을 유니코드로 변환하고 이에 맞는 내장비트맵폰트를 이용해 출력하는 기능입니다.
아래 소스에는 클리핑 관련 기능은 빠져있으니 필요하신대로 추가하시면 되겠습니다.

#include < UnicodeFont.h>
#include < iconv.h >

void printH( SDL_Surface *surface, int x, int y, char *str, int col );
void print( SDL_Surface *surface, int x, int y, Uint16 *str, int col );

void printH( SDL_Surface *surface, int x, int y, char *str, int col )
{
char ustr[1024];
char *ustrp = ustr;
size_t len=strlen(str), nLen=200;
iconv_t cd;

cd = iconv_open("UNICODELITTLE", "UHC");

#ifdefGP2X
iconv( cd, &str, &len, (char **)&ustrp, &nLen );
#else
iconv( cd, (const char**)&str, &len, (char **)&ustrp, &nLen );
#endif
ustrp[0] = ustrp[1] = 0;
iconv_close(cd);

print( surface, x, y, (Uint16 *)ustr, col );
}

void print( SDL_Surface *surface, int x, int y, Uint16 *str, int col )
{
unsigned short *pixel = (unsigned short *)surface->pixels;
unsigned short font[16];
Uint16 code;
int h, w;
int j, k;
int ptr;
int pitch = surface->pitch >> 1;
int i = 0;

while(str[i])
{
code = str[i++];
if( code==0xFEFF )
continue;
GetFont(code, font, &h, &w);
ptr = (pitch * y) + x;
for( j = 0;j < h;j++ )
{
if(font[j] != 0)
for(k = 0;k < w;k++)
if( x+k >= 0 )
if(font[j] & (0x8000 >> k))
*(pixel + ptr + k) = col;
ptr += pitch;
}
x += w;
}
} <div class="post_footer_conte
Posted by YoungMoon
: