728x90
반응형
728x90
반응형
반응형

SFML 에서 리소스 임베드하여 사용하기

  • xxd 리눅스 명령어을 활용하여 리소스 파일을 임베드한다.
  • 윈도즈에서 사용하려면 git bash 등을 활용한다.

1) Sansation.ttf 파일로 Sansation.ttf.h 파일을 만든다.

$ xxd -i Sansation.ttf >  Sansation.ttf.h

2) Sansation.ttf.h 파일의 내용은 다음과 같다.

$ cat Sansation.ttf.h

unsigned char Sansation_ttf[] = {
  0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x10,
  ... ... 
  0x01, 0x02, 0x00, 0x00
};
unsigned int Sansation_ttf_len = 28912;

3) SFML 인 경우 loadFromMemory() 등의 함수를 이용하여 리소스 내용을 읽어서 활용한다.

  • Sansation_ttf 는 byte(char) array
  • Sansation_ttf_len 는 array 길이
	// font
	sf::Font mFont;
	if (!mFont.loadFromMemory( Sansation_ttf, Sansation_ttf_len ))
	{
		// Handle loading error
	}  
	
	// texture 
	sf::Texture mTexture;
	sf::IntRect eagleRect( 0, 0, 48, 64 );
	if (!mTexture.loadFromMemory( Eagle_png, Eagle_png_len, eagleRect ))
	{
		// Handle loading error
	}  
728x90
반응형

+ Recent posts