complete rewrite
This commit is contained in:
parent
b60e3a0ef6
commit
8a717a2b2e
41 changed files with 2625 additions and 1255 deletions
9
engine/tools/CMakeLists.txt
Normal file
9
engine/tools/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
include(GNUInstallDirs)
|
||||
|
||||
macro(compile_tool name)
|
||||
file(GLOB ${name}_SRC ${name}/*.c)
|
||||
add_executable(${name} ${${name}_SRC})
|
||||
target_include_directories(${name} PRIVATE ../../external/stb)
|
||||
endmacro()
|
||||
|
||||
compile_tool(gb_dumpfont)
|
||||
72
engine/tools/gb_dumpfont/gb_dumpfont.c
Normal file
72
engine/tools/gb_dumpfont/gb_dumpfont.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stb_image_write.h>
|
||||
|
||||
#define CHECK(s) ((linelen > strlen(s)) && memcmp(line, s, strlen(s)) == 0)
|
||||
|
||||
int main() {
|
||||
char* line = NULL;
|
||||
size_t linesize;
|
||||
ssize_t linelen;
|
||||
int iw, ih;
|
||||
unsigned char* font = NULL;
|
||||
int c;
|
||||
int p = 0;
|
||||
int y = 0;
|
||||
int w, h;
|
||||
|
||||
while((linelen = getline(&line, &linesize, stdin)) != -1) {
|
||||
linelen--;
|
||||
|
||||
line[linelen] = 0;
|
||||
|
||||
if(CHECK("FONTBOUNDINGBOX ")) {
|
||||
sscanf(line, "FONTBOUNDINGBOX %d %d", &w, &h);
|
||||
printf("%dx%d font\n", w, h);
|
||||
|
||||
if(font != NULL) free(font);
|
||||
|
||||
iw = w * 16;
|
||||
ih = h * 16;
|
||||
font = malloc(iw * ih * 4);
|
||||
memset(font, 0, iw * ih * 4);
|
||||
} else if(CHECK("ENCODING ")) {
|
||||
sscanf(line, "ENCODING %d", &c);
|
||||
} else if(strcmp(line, "BITMAP") == 0) {
|
||||
p = 1;
|
||||
y = 0;
|
||||
} else if(strcmp(line, "ENDCHAR") == 0) {
|
||||
p = 0;
|
||||
} else if(p && y < h) {
|
||||
int bx = c % 16;
|
||||
int by = c / 16;
|
||||
int i;
|
||||
int n = 0;
|
||||
|
||||
for(i = 0; i < w; i++) {
|
||||
if((i % 4) == 0) {
|
||||
char buf[2];
|
||||
|
||||
buf[0] = line[i / 4];
|
||||
buf[1] = 0;
|
||||
|
||||
n = strtol(buf, NULL, 16);
|
||||
}
|
||||
|
||||
if(n & (1 << 3)) {
|
||||
unsigned char* px = &font[((by * h + y) * iw + bx * w + i) * 4];
|
||||
memset(px, 255, 4);
|
||||
}
|
||||
|
||||
n = n << 1;
|
||||
}
|
||||
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
if(font != NULL) stbi_write_png("font.png", iw, ih, 4, font, 0);
|
||||
return 0;
|
||||
}
|
||||
2
engine/tools/gb_dumpfont/stb_image_write.c
Normal file
2
engine/tools/gb_dumpfont/stb_image_write.c
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <stb_image_write.h>
|
||||
Loading…
Add table
Add a link
Reference in a new issue