raylib:util:raylib_loadbmfont_extender
raylib loadbmfont extender
차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판이전 판다음 판 | 이전 판 | ||
raylib:util:raylib_loadbmfont_extender [2023/11/12 23:11] – 이거니맨 | raylib:util:raylib_loadbmfont_extender [2023/11/21 23:16] (현재) – 이거니맨 | ||
---|---|---|---|
줄 21: | 줄 21: | ||
Bitmap Font Loader Extender | Bitmap Font Loader Extender | ||
- | Author : Dongkun Lee. | + | Author : Dongkun Lee. |
- | | + | |
- | | + | |
| | ||
+ | History : 2023. 11. 2. ver 1. 0. | ||
Description : | Description : | ||
This is helper utility to load bitmap font(fnt) that have multiple atlas. | This is helper utility to load bitmap font(fnt) that have multiple atlas. | ||
줄 43: | 줄 44: | ||
Font LoadBMFontEX(const char *fileName) | Font LoadBMFontEX(const char *fileName) | ||
{ | { | ||
- | | + | #define MAX_BUFFER_SIZE |
Font font = { 0 }; | Font font = { 0 }; | ||
줄 55: | 줄 56: | ||
int imWidth = 0; | int imWidth = 0; | ||
int imHeight = 0; | int imHeight = 0; | ||
- | int totalPage = 1; | + | int totalPage = 1; // page variable |
- | int curPage = 0; | + | char imFileName[10][129] = { 0 }; // up to ten png file. |
- | char imFileName[10][129] = { 0 }; | + | |
- | int base = 0; | + | int base = 0; |
+ | int readBytes = 0; // Data bytes read | ||
+ | int readVars = 0; // Variables filled by sscanf() | ||
char *fileText = LoadFileText(fileName); | char *fileText = LoadFileText(fileName); | ||
줄 68: | 줄 70: | ||
// NOTE: We skip first line, it contains no useful information | // NOTE: We skip first line, it contains no useful information | ||
- | | + | |
- | fileTextPtr += (lineBytes | + | fileTextPtr += (readBytes |
// Read line data | // Read line data | ||
- | | + | |
searchPoint = strstr(buffer, | searchPoint = strstr(buffer, | ||
- | sscanf(searchPoint, | + | |
- | fileTextPtr += (lineBytes | + | fileTextPtr += (readBytes |
- | + | ||
- | | + | |
- | | + | |
- | printf(" | + | |
- | printf(" | + | |
for (int i = 0; i < totalPage; i++) | for (int i = 0; i < totalPage; i++) | ||
{ | { | ||
- | | + | |
- | searchPoint = strstr(buffer, | + | searchPoint = strstr(buffer, |
- | sscanf(searchPoint, | + | |
- | + | | |
- | | + | |
- | printf(" | + | |
- | | + | |
} | } | ||
- | | + | |
searchPoint = strstr(buffer, | searchPoint = strstr(buffer, | ||
- | sscanf(searchPoint, | + | |
- | fileTextPtr += (lineBytes | + | fileTextPtr += (readBytes |
- | | + | |
- | printf(" | + | |
// Compose correct path using route of .fnt file (fileName) and imFileName | // Compose correct path using route of .fnt file (fileName) and imFileName | ||
- | char *imPath[10] = {0}; | + | char **imPath; |
char *lastSlash = NULL; | char *lastSlash = NULL; | ||
+ | imPath = malloc(sizeof(char) * 100); // imPath Initialization | ||
for (int i = 0; i< totalPage; i++) | for (int i = 0; i< totalPage; i++) | ||
줄 113: | 줄 110: | ||
if (lastSlash != NULL) | if (lastSlash != NULL) | ||
{ | { | ||
- | | + | |
- | imPath[i] = (char *)RL_CALLOC(TextLength(fileName) - TextLength(lastSlash) + TextLength(imFileName[i]) + 4, 1); | + | imPath[i] = (char *)RL_CALLOC(TextLength(fileName) - TextLength(lastSlash) + TextLength(imFileName[i]) + 4, 1); |
- | memcpy(imPath[i], | + | memcpy(imPath[i], |
- | memcpy(imPath[i] + TextLength(fileName) - TextLength(lastSlash) + 1, imFileName[i], | + | memcpy(imPath[i] + TextLength(fileName) - TextLength(lastSlash) + 1, imFileName[i], |
- | | + | } |
else imPath[i] = imFileName[i]; | else imPath[i] = imFileName[i]; | ||
- | // For debug | + | TRACELOGD(" |
- | printf(" | + | |
- | // TRACELOGD(" | + | |
} | } | ||
- | Image imFont[10]; | + | |
- | | + | Image fullFont = LoadImage(imPath[0]);; |
+ | |||
+ | | ||
for (int i = 0; i < totalPage; i++) | for (int i = 0; i < totalPage; i++) | ||
{ | { | ||
imFont[i] = LoadImage(imPath[i]); | imFont[i] = LoadImage(imPath[i]); | ||
- | // For debug | ||
- | printf(" | ||
- | |||
if (imFont[i].format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) | if (imFont[i].format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) | ||
줄 156: | 줄 151: | ||
if (lastSlash != NULL) RL_FREE(imPath[i]); | if (lastSlash != NULL) RL_FREE(imPath[i]); | ||
- | } | + | } |
- | | + | fullFont = imFont[0]; |
- | Image fullFont; | + | |
- | | + | |
// If multiple atlas, then merge atlas | // If multiple atlas, then merge atlas | ||
if (totalPage > 1) | if (totalPage > 1) | ||
{ | { | ||
+ | // Resize and ReDraw Font Image | ||
ImageResizeCanvas(& | ImageResizeCanvas(& | ||
줄 175: | 줄 169: | ||
} | } | ||
- | |||
- | // Image to Texure | ||
font.texture = LoadTextureFromImage(fullFont); | font.texture = LoadTextureFromImage(fullFont); | ||
+ | |||
+ | |||
// Fill font characters info data | // Fill font characters info data | ||
줄 190: | 줄 184: | ||
for (int i = 0; i < glyphCount; i++) | for (int i = 0; i < glyphCount; i++) | ||
{ | { | ||
- | | + | |
- | sscanf(buffer, | + | |
& | & | ||
- | fileTextPtr += (lineBytes | + | fileTextPtr += (readBytes |
+ | |||
+ | if (readVars == 9) // Make sure all char data has been properly read | ||
+ | { | ||
+ | // Get character rectangle in the font atlas texture | ||
+ | font.recs[i] = (Rectangle){ (float)charX, | ||
- | | + | |
- | font.recs[i] = (Rectangle){ (float)charX, | + | font.glyphs[i].value = charId; |
+ | font.glyphs[i].offsetX = charOffsetX; | ||
+ | font.glyphs[i].offsetY = charOffsetY; | ||
+ | font.glyphs[i].advanceX | ||
- | // Save data properly in sprite font | + | |
- | font.glyphs[i].value = charId; | + | font.glyphs[i].image = ImageFromImage(fullFont, |
- | font.glyphs[i].offsetX = charOffsetX; | + | } |
- | font.glyphs[i].offsetY = charOffsetY; | + | else TRACELOG(LOG_WARNING, |
- | font.glyphs[i].advanceX = charAdvanceX; | + | |
- | + | ||
- | | + | |
- | font.glyphs[i].image = ImageFromImage(fullFont, | + | |
} | } | ||
- | // Unload | ||
UnloadImage(fullFont); | UnloadImage(fullFont); | ||
UnloadFileText(fileText); | UnloadFileText(fileText); | ||
줄 216: | 줄 213: | ||
UnloadFont(font); | UnloadFont(font); | ||
font = GetFontDefault(); | font = GetFontDefault(); | ||
- | // | + | |
- | | + | |
} | } | ||
- | else // TRACELOG(LOG_INFO, | + | else TRACELOG(LOG_INFO, |
- | printf("FONT: [%s] Font loaded successfully (%i glyphs)", | + | |
+ | free(imPath); | ||
return font; | return font; | ||
} | } |
raylib/util/raylib_loadbmfont_extender.1699798289.txt.gz · 마지막으로 수정됨: 2023/11/12 23:11 저자 이거니맨