1 //------------------------------------------------------------------------------ 2 // debugtext.d 3 // 4 // Test sokol_debugtext.h 5 //------------------------------------------------------------------------------ 6 module examples.debugtext; 7 8 import sg = sokol.gfx; 9 import sglue = sokol.glue; 10 import sapp = sokol.app; 11 import sdtx = sokol.debugtext; 12 import log = sokol.log; 13 14 extern (C): 15 @safe: 16 17 // Font slots 18 immutable FONT_KC853 = 0; 19 immutable FONT_KC854 = 1; 20 immutable FONT_KC85 = 1; 21 immutable FONT_Z1013 = 2; 22 immutable FONT_CPC = 3; 23 immutable FONT_C64 = 4; 24 immutable FONT_ORIC = 5; 25 26 struct State { 27 // background color 28 sg.PassAction passAction = { 29 colors: [ 30 { 31 load_action: sg.LoadAction.Clear, 32 clear_value: { r: 0.0, g: 0.125, b: 0.25, a: 1.0 } 33 } 34 ] 35 }; 36 } 37 static State state; 38 39 void init() { 40 sg.Desc gfx = { 41 environment: sglue.environment(), 42 logger: { func: &log.func } 43 }; 44 sg.setup(gfx); 45 46 sdtx.Desc desc = { 47 fonts: [ 48 sdtx.fontKc853(), 49 sdtx.fontKc854(), 50 sdtx.fontZ1013(), 51 sdtx.fontCpc(), 52 sdtx.fontC64(), 53 sdtx.fontOric() 54 ], 55 logger: { func: &log.func }, 56 }; 57 sdtx.setup(desc); 58 } 59 60 void print_font(uint font_index, string title, ubyte r, ubyte g, ubyte b) { 61 sdtx.font(font_index); 62 sdtx.color3b(r, g, b); 63 sdtx.puts(&title[0]); 64 foreach (c; 32 .. 255) { 65 sdtx.putc(cast(char) c); 66 if (((c + 1) & 63) == 0) { 67 sdtx.crlf(); 68 } 69 } 70 sdtx.crlf(); 71 } 72 73 void frame() { 74 sdtx.canvas(sapp.widthf() * 0.5, sapp.heightf() * 0.5); 75 sdtx.origin(0.0, 2.0); 76 sdtx.home(); 77 78 print_font(FONT_KC853, "KC85/3:\n", 0xf4, 0x43, 0x36); 79 print_font(FONT_KC854, "KC85/4:\n", 0x21, 0x96, 0xf3); 80 print_font(FONT_Z1013, "Z1013:\n", 0x4c, 0xaf, 0x50); 81 print_font(FONT_CPC, "Amstrad CPC:\n", 0xff, 0xeb, 0x3b); 82 print_font(FONT_C64, "C64:\n", 0x79, 0x86, 0xcb); 83 print_font(FONT_ORIC, "Oric Atmos:\n", 0xff, 0x98, 0x00); 84 85 sg.Pass pass = { action: state.passAction, swapchain: sglue.swapchain() }; 86 sg.beginPass(pass); 87 sdtx.draw(); 88 sg.endPass(); 89 sg.commit(); 90 } 91 92 void cleanup() { 93 sdtx.shutdown(); 94 sg.shutdown(); 95 } 96 97 void main() { 98 sapp.Desc runner = { 99 window_title: "debugtext.d", 100 init_cb: &init, 101 frame_cb: &frame, 102 cleanup_cb: &cleanup, 103 width: 1024, 104 height: 600, 105 icon: {sokol_default: true}, 106 logger: {func: &log.func} 107 }; 108 sapp.run(runner); 109 }