From 28736c578701393f35cac2bd2ad49de18d7f879e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Jun 2017 18:23:49 -0400 Subject: Move example -> examples And the compositor example into its own directory --- examples/simple.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/simple.c (limited to 'examples/simple.c') diff --git a/examples/simple.c b/examples/simple.c new file mode 100644 index 00000000..4bbdf399 --- /dev/null +++ b/examples/simple.c @@ -0,0 +1,52 @@ +#define _POSIX_C_SOURCE 199309L +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "shared.h" + +struct sample_state { + float color[3]; + int dec; +}; + +void handle_output_frame(struct output_state *output, struct timespec *ts) { + struct compositor_state *state = output->compositor; + struct sample_state *sample = state->data; + + long ms = (ts->tv_sec - state->last_frame.tv_sec) * 1000 + + (ts->tv_nsec - state->last_frame.tv_nsec) / 1000000; + int inc = (sample->dec + 1) % 3; + + sample->color[inc] += ms / 2000.0f; + sample->color[sample->dec] -= ms / 2000.0f; + + if (sample->color[sample->dec] < 0.0f) { + sample->color[inc] = 1.0f; + sample->color[sample->dec] = 0.0f; + sample->dec = inc; + } + + glClearColor(sample->color[0], sample->color[1], sample->color[2], 1.0); + glClear(GL_COLOR_BUFFER_BIT); +} + +int main() { + struct sample_state state = { + .color = { 1.0, 0.0, 0.0 }, + .dec = 0, + }; + struct compositor_state compositor = { 0, + .data = &state, + .output_frame_cb = handle_output_frame, + }; + compositor_init(&compositor); + compositor_run(&compositor); +} -- cgit v1.2.3