create font/ui text system
[fishladder.git] / fontcomp.c
diff --git a/fontcomp.c b/fontcomp.c
new file mode 100644 (file)
index 0000000..ea1fac9
--- /dev/null
@@ -0,0 +1,62 @@
+// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+
+#define VG_TOOLS
+#include "vg/vg.h"
+
+// Super basic model compiler
+int main( int argc, char *argv[] )
+{
+       if( argc < 3 )
+       {
+               vg_error( "Need input/output files\n" );
+               return 0;
+       }
+       
+       FILE *output;
+       
+       int x,y,n;
+       unsigned char *data = stbi_load( argv[1], &x, &y, &n, 4 );
+       
+       if( data ) 
+       {
+               output = fopen( argv[2], "w" );
+               if( !output )
+               {
+                       vg_error( "couldn't open output for writing\n" );
+                       free(data);
+                       return 0;
+               }
+               
+               fprintf( output, "/* Font buffer generated from source file: '%s' */\n", argv[1] );
+               
+               u32 pixel_max = x*y;
+               u32 pixel = 0, chars = 0;
+               while(pixel_max)
+               {
+                       u32 buff = 0;
+                       for( int b = 31; b >= 0; b-- )
+                       {
+                               buff |= data[pixel*4+3]>128?0x1<<b:0;
+                               pixel++;
+                               
+                               if( pixel >= pixel_max )
+                               {
+                                       pixel_max = 0;
+                                       break;
+                               }
+                       }
+                       
+                       fprintf( output, "%#x,", buff );
+                       if( (++chars) % 8 == 0 )
+                               fprintf( output, "\n" );
+               }
+               
+               free(data);
+               fclose(output);
+       }
+       else
+       {
+               vg_error( "Couldn't open source file\n" );
+               return 0;
+       }
+}