1 //------------------------------------------------------------------------------ 2 // clear.d 3 // 4 // Just clear the framebuffer with an animated color. 5 //------------------------------------------------------------------------------ 6 module examples.clear; 7 8 private: 9 10 import sg = sokol.gfx; 11 import sglue = sokol.glue; 12 import sapp = sokol.app; 13 import log = sokol.log; 14 15 extern (C): 16 @safe: 17 18 sg.PassAction pass_action = { 19 colors: [ 20 {load_action: sg.LoadAction.Clear, clear_value: {r: 1, g: 1, b: 0, a: 1}} 21 ] 22 }; 23 24 static void init() 25 { 26 sg.Desc gfx = { 27 environment: sglue.environment(), 28 logger: {func: &log.slog_func}, 29 }; 30 sg.setup(gfx); 31 32 version (WebAssembly) 33 { /* none */ } 34 else version (D_BetterC) 35 { /* none */ } 36 else 37 { 38 import std.stdio : writeln; 39 40 debug writeln("Backend: ", sg.queryBackend()); 41 } 42 } 43 44 static void frame() 45 { 46 const g = pass_action.colors[0].clear_value.g + 0.01; 47 pass_action.colors[0].clear_value.g = g > 1.0 ? 0.0 : g; 48 sg.Pass pass = {action: pass_action, swapchain: sglue.swapchain}; 49 sg.beginPass(pass); 50 sg.endPass(); 51 sg.commit(); 52 } 53 54 static void cleanup() 55 { 56 sg.shutdown(); 57 } 58 59 void main() 60 { 61 sapp.Desc runner = { 62 window_title: "clear.d", 63 init_cb: &init, 64 frame_cb: &frame, 65 cleanup_cb: &cleanup, 66 width: 640, 67 height: 480, 68 win32_console_attach: true, 69 icon: {sokol_default: true}, 70 logger: {func: &log.func} 71 }; 72 sapp.run(runner); 73 }