added score counters/career stuff
[fishladder.git] / fontcomp.c
1 // Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
2
3 #define VG_TOOLS
4 #include "vg/vg.h"
5
6 // Super basic model compiler
7 int main( int argc, char *argv[] )
8 {
9 if( argc < 3 )
10 {
11 vg_error( "Need input/output files\n" );
12 return 0;
13 }
14
15 FILE *output;
16
17 int x,y,n;
18 unsigned char *data = stbi_load( argv[1], &x, &y, &n, 4 );
19
20 if( data )
21 {
22 output = fopen( argv[2], "w" );
23 if( !output )
24 {
25 vg_error( "couldn't open output for writing\n" );
26 free(data);
27 return 0;
28 }
29
30 fprintf( output, "/* Font buffer generated from source file: '%s' */\n", argv[1] );
31
32 u32 pixel_max = x*y;
33 u32 pixel = 0, chars = 0;
34 while(pixel_max)
35 {
36 u32 buff = 0;
37 for( int b = 31; b >= 0; b-- )
38 {
39 buff |= data[pixel*4+3]>128?0x1<<b:0;
40 pixel++;
41
42 if( pixel >= pixel_max )
43 {
44 pixel_max = 0;
45 break;
46 }
47 }
48
49 fprintf( output, "%#x,", buff );
50 if( (++chars) % 8 == 0 )
51 fprintf( output, "\n" );
52 }
53
54 free(data);
55 fclose(output);
56 }
57 else
58 {
59 vg_error( "Couldn't open source file\n" );
60 return 0;
61 }
62 }