diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-06-29 16:00:24 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-06-29 16:00:24 -0400 |
commit | 8920b5d607c6b3b5d04894fc1837ac4f2d9558ae (patch) | |
tree | 3c79b4faff213544ed247e1c126fc89508bdd75d /examples/simple.c | |
parent | 97f6e9b69aecf1fbcbc2fa95cb2009f873c86d40 (diff) | |
parent | 486ec5953cf51f5fde834bf8fa7fbe56f0be9a0e (diff) |
Merge branch 'wlcore'
Diffstat (limited to 'examples/simple.c')
-rw-r--r-- | examples/simple.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/examples/simple.c b/examples/simple.c new file mode 100644 index 00000000..45cb2b93 --- /dev/null +++ b/examples/simple.c @@ -0,0 +1,56 @@ +#define _POSIX_C_SOURCE 199309L +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <inttypes.h> +#include <wayland-server.h> +#include <GLES2/gl2.h> +#include <wlr/backend.h> +#include <wlr/session.h> +#include <wlr/types/wlr_output.h> +#include <xkbcommon/xkbcommon.h> +#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; + } + + wlr_output_make_current(output->output); + + glClearColor(sample->color[0], sample->color[1], sample->color[2], 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + wlr_output_swap_buffers(output->output); +} + +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); +} |