summaryrefslogtreecommitdiff
path: root/examples/sinewave.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2025-01-12 12:13:56 +0100
committerMitya Selivanov <automainint@guattari.tech>2025-01-12 12:13:56 +0100
commit29d736aecc5db0deb67053931e5b1cf03a9defc3 (patch)
tree50caf18887aeda07b24bee5d4143130f8546aff7 /examples/sinewave.c
parent464575c72a8a20b5e565f91cebfeb470edc8542e (diff)
downloadreduced_system_layer-29d736aecc5db0deb67053931e5b1cf03a9defc3.zip
f32 colors; g_ prefix
Diffstat (limited to 'examples/sinewave.c')
-rw-r--r--[-rwxr-xr-x]examples/sinewave.c45
1 files changed, 9 insertions, 36 deletions
diff --git a/examples/sinewave.c b/examples/sinewave.c
index a1f19f8..3a127ae 100755..100644
--- a/examples/sinewave.c
+++ b/examples/sinewave.c
@@ -1,30 +1,3 @@
-#if 0 /*
-#/ ================================================================
-#/
-#/ sinewave.c
-#/
-#/ ================================================================
-#/
-#/ Self-compilation shell script
-#/
-SRC=${0##*./}
-BIN=${SRC%.*}
-gcc \
- -Wall -Wextra -Werror -pedantic \
- -Wno-old-style-declaration \
- -Wno-missing-braces \
- -Wno-unused-variable \
- -Wno-unused-but-set-variable \
- -Wno-unused-parameter \
- -Wno-overlength-strings \
- -O3 \
- -fsanitize=undefined,address,leak \
- -lX11 -lm -lasound \
- -o $BIN $SRC && \
- ./$BIN $@ && rm $BIN
-exit $? # */
-#endif
-
#include "../graphics.c"
i64 time_0 = 0;
@@ -33,26 +6,26 @@ i64 audio_samples = 0;
f32 frames[AUDIO_SAMPLE_RATE * AUDIO_NUM_CHANNELS] = {0};
b8 ui_button(f64 x, f64 y, f64 width, f64 height) {
- b8 has_cursor = platform.cursor_x >= x && platform.cursor_x < x + width &&
- platform.cursor_y >= y && platform.cursor_y < y + height;
+ b8 has_cursor = g_platform.cursor_x >= x && g_platform.cursor_x < x + width &&
+ g_platform.cursor_y >= y && g_platform.cursor_y < y + height;
- b8 is_pressed = has_cursor && platform.key_down[BUTTON_LEFT];
+ b8 is_pressed = has_cursor && g_platform.key_down[BUTTON_LEFT];
if (is_pressed)
- fill_rectangle(OP_SET, 0xffffff, x, y, width, height);
+ fill_rectangle(OP_SET, (vec3_f32) { 1.f, 1.f, 1.f }, x, y, width, height);
else if (has_cursor)
- fill_rectangle(OP_SET, 0xa0a000, x, y, width, height);
+ fill_rectangle(OP_SET, (vec3_f32) { .8f, .8f, 0.f }, x, y, width, height);
else
- fill_rectangle(OP_SET, 0x808030, x, y, width, height);
+ fill_rectangle(OP_SET, (vec3_f32) { .8f, .8f, .2f }, x, y, width, height);
- return has_cursor && platform.key_pressed[BUTTON_LEFT];
+ return has_cursor && g_platform.key_pressed[BUTTON_LEFT];
}
void update_and_render_frame(void) {
i32 num_events = p_handle_events();
if (num_events > 0) {
- fill_rectangle(OP_SET, 0x202020, 0, 0, platform.frame_width, platform.frame_height);
+ fill_rectangle(OP_SET, (vec3_f32) { .1f, .1f, .1f }, 0, 0, g_platform.frame_width, g_platform.frame_height);
if (ui_button(100, 100, 200, 200))
p_queue_sound(0, AUDIO_SAMPLE_RATE, frames);
@@ -70,7 +43,7 @@ i32 main(i32 argc, c8 **argv) {
(void) argc;
(void) argv;
- platform = (Platform) {
+ g_platform = (Platform) {
.title = "Sine Wave",
.graceful_exit = 1,
};