diff --git a/glonkers.c b/glonkers.c index f8f5f79..8bcaa7c 100644 --- a/glonkers.c +++ b/glonkers.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include "renderer.h" @@ -36,13 +35,14 @@ int main(int argc, char *argv[]) { exit(1); } - struct client_state state = wayland_init(); + struct client_state state; + wayland_init(&state); Renderer renderer = new_renderer(); while (running) { double time = time_since_start(); - render(&renderer, state.width, state.height, time, shader_path, false); + render(&renderer, state.width, state.height, time, shader_path, 0); commit(&state); } diff --git a/wayland.c b/wayland.c index df2078f..ac0c535 100644 --- a/wayland.c +++ b/wayland.c @@ -156,25 +156,24 @@ static void egl_init(struct client_state *state) { } /// Initializes wayland and creates an opengl context -struct client_state wayland_init() { +void wayland_init(struct client_state *state) { int width = 700, height = 700; - struct client_state state = { width, height, 0 }; - state.wl_display = wl_display_connect(NULL); - state.wl_registry = wl_display_get_registry(state.wl_display); - wl_registry_add_listener(state.wl_registry, &wl_registry_listener, &state); - wl_display_roundtrip(state.wl_display); + state->width = width; + state->height = height; + state->wl_display = wl_display_connect(NULL); + state->wl_registry = wl_display_get_registry(state->wl_display); + wl_registry_add_listener(state->wl_registry, &wl_registry_listener, state); + wl_display_roundtrip(state->wl_display); - state.wl_surface = wl_compositor_create_surface(state.wl_compositor); - state.xdg_surface = xdg_wm_base_get_xdg_surface( - state.xdg_wm_base, state.wl_surface); - xdg_surface_add_listener(state.xdg_surface, &xdg_surface_listener, &state); - state.xdg_toplevel = xdg_surface_get_toplevel(state.xdg_surface); - xdg_toplevel_set_title(state.xdg_toplevel, "GLONKERS!"); - wl_surface_commit(state.wl_surface); + state->wl_surface = wl_compositor_create_surface(state->wl_compositor); + state->xdg_surface = xdg_wm_base_get_xdg_surface( + state->xdg_wm_base, state->wl_surface); + xdg_surface_add_listener(state->xdg_surface, &xdg_surface_listener, state); + state->xdg_toplevel = xdg_surface_get_toplevel(state->xdg_surface); + xdg_toplevel_set_title(state->xdg_toplevel, "GLONKERS!"); + wl_surface_commit(state->wl_surface); - egl_init(&state); - - return state; + egl_init(state); } /// Swaps front/backbuffers and dispatches pending wayland commands. diff --git a/wayland.h b/wayland.h index 01137cb..3d05bdc 100644 --- a/wayland.h +++ b/wayland.h @@ -22,6 +22,6 @@ struct client_state { EGLContext egl_context; }; -struct client_state wayland_init(); +void wayland_init(struct client_state *state); void commit(struct client_state *state);