From e9276925fafc909c0662d8a13961983c8dca2620 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 4 May 2021 14:52:19 -0500 Subject: [PATCH] drawing a purple rectangle. --- site/index.html | 2 +- site/js/onyx-loader.js | 2 -- src/build.onyx | 1 + src/tower.onyx | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/site/index.html b/site/index.html index eed4244..1211287 100644 --- a/site/index.html +++ b/site/index.html @@ -20,6 +20,6 @@ - This browser does not support the Canvas API. + This browser does not support the Canvas API. diff --git a/site/js/onyx-loader.js b/site/js/onyx-loader.js index bece7b7..a48a38a 100644 --- a/site/js/onyx-loader.js +++ b/site/js/onyx-loader.js @@ -28,8 +28,6 @@ function launch_onyx_program(script_path, call_start) { return WebAssembly.instantiate(wasm_code, import_object); }) .then(function(wasm_module) { - // @ROBUSTNESS: This only allows for 1 Onyx program to running at a time in the window. - // This probably iesn't a limitation that needs to be worried about, but it is a limitation. window.ONYX_MEMORY = wasm_module.instance.exports.memory; window.ONYX_INSTANCE = wasm_module.instance; diff --git a/src/build.onyx b/src/build.onyx index a2d3272..3869d20 100644 --- a/src/build.onyx +++ b/src/build.onyx @@ -6,5 +6,6 @@ #load "modules/webgl2/module" #load "modules/js_events/module" +#load "modules/immediate_mode/module" #load "src/tower" diff --git a/src/tower.onyx b/src/tower.onyx index 536bfb0..7f2ed09 100644 --- a/src/tower.onyx +++ b/src/tower.onyx @@ -1,6 +1,45 @@ use package core +#private_file events :: package js_events +#private_file gl :: package gl +#private_file gfx :: package immediate_mode + main :: (args: [] cstr) { println("Hello World!"); + + gl.init("game"); + events.init(); + gfx.immediate_renderer_init(); + + start_loop :: () -> void #foreign "game" "start_loop" --- + start_loop(); +} + +#export "loop" () { + poll_events(); + draw(); +} + +poll_events :: () { + for event: events.consume() do switch event.kind { + case .MouseDown do println("Mouse was down!"); + + case .Resize { + printf("Window was resized to: %i %i\n", event.resize.width, event.resize.height); + + gl.setSize(event.resize.width, event.resize.height); + gl.viewport(0, 0, event.resize.width, event.resize.height); + gfx.use_ortho_projection(0, ~~event.resize.width, 0, ~~event.resize.height); + } + } +} + +draw :: () { + gl.clearColor(0, 0, 0, 1); + gl.clear(gl.COLOR_BUFFER_BIT); + + gfx.quad(.{ 0, 0 }, .{ 400, 400 }, color=.{ 1, 0, 1 }); + gfx.flush(); } + -- 2.25.1