diff options
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | graphics.c | 79 | ||||
| -rw-r--r-- | graphics.h | 9 | ||||
| -rw-r--r-- | main.c | 79 | ||||
| -rw-r--r-- | state.h | 11 |
5 files changed, 97 insertions, 87 deletions
@@ -22,15 +22,15 @@ $(BIN): $(OBJ) printf " LD %s\n" $@ $(CC) $(LDFLAGS) $^ -o $@ -$(OBJDIR)/%.o: %.c %.h +$(OBJDIR)/%.o: %.c %.h state.h printf " CC %s\n" $@ $(CC) $(CFLAGS) -c $< -o $@ -$(OBJDIR)/%.o: */%.c */%.h +$(OBJDIR)/%.o: */%.c */%.h state.h printf " CC %s\n" $@ $(CC) $(CFLAGS) -c $< -o $@ -$(OBJDIR)/%.o: %.c +$(OBJDIR)/%.o: %.c state.h printf " CC %s\n" $@ $(CC) $(CFLAGS) -c $< -o $@ diff --git a/graphics.c b/graphics.c new file mode 100644 index 0000000..33febff --- /dev/null +++ b/graphics.c @@ -0,0 +1,79 @@ +#include "graphics.h" + +bool init_gl(client_state* state) { + EGLint attrs[] = { + EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, + EGL_CONFORMANT, EGL_OPENGL_BIT, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_DEPTH_SIZE, 24, + EGL_NONE + }; + + state->egl_window = wl_egl_window_create(state->surface, state->width, state->height); + if (!state->egl_window) { + fprintf(stderr, "ewindow\n"); + return false; + } + + + state->egl_display = eglGetDisplay(state->display); + if (state->egl_display == EGL_NO_DISPLAY) { + fprintf(stderr, "edisplay\n"); + return false; + } + { + EGLint major, minor; + if (eglInitialize(state->egl_display, &major, &minor) != EGL_TRUE) { + fprintf(stderr, "eglinit\n"); + return false; + } + + printf("EGL version %u.%u\n", major, minor); + } + eglBindAPI(EGL_OPENGL_API); + + EGLint num_configs; + if (eglChooseConfig(state->egl_display, attrs, &state->egl_config, 1, &num_configs) != EGL_TRUE) { + fprintf(stderr, "econfig: %d\n", eglGetError()); + return false; + } + + state->egl_surface = eglCreateWindowSurface(state->egl_display, state->egl_config, + (EGLNativeWindowType)state->egl_window, NULL); + if (state->egl_surface == EGL_NO_SURFACE) { + fprintf(stderr, "esurface\n"); + return false; + } + + state->egl_context = eglCreateContext(state->egl_display, state->egl_config, + EGL_NO_CONTEXT, NULL); + if (state->egl_context == EGL_NO_CONTEXT) { + fprintf(stderr, "econtext: %x\n", eglGetError()); + return false; + } + + eglMakeCurrent(state->egl_display, state->egl_surface, state->egl_surface, state->egl_context); + + if (!gladLoadGL()) { + fprintf(stderr, "gladLoadGL"); + return false; + } + + { + GLint major, minor; + glGetIntegerv(GL_MAJOR_VERSION, &major); + glGetIntegerv(GL_MINOR_VERSION, &minor); + printf("GL version %u.%u\n", major, minor); + } + + return true; +} + +void render_frame(client_state *state) { + glClearColor(1.0, 1.0, 1.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + eglSwapBuffers(state->egl_display, state->egl_surface); +} diff --git a/graphics.h b/graphics.h new file mode 100644 index 0000000..8889bf7 --- /dev/null +++ b/graphics.h @@ -0,0 +1,9 @@ +#ifndef GRAPHICS_H_ +#define GRAPHICS_H_ + +#include "state.h" + +bool init_gl(client_state* state); +void render_frame(client_state* state); + +#endif @@ -1,83 +1,14 @@ #include <EGL/egl.h> #include <stdio.h> -#include "./state.h" +#include "state.h" +#include "graphics.h" + #include "wlr-layer-shell-unstable-v1.h" extern struct wl_registry_listener registry_listener; extern struct zwlr_layer_surface_v1_listener layer_surface_listener; -bool init_gl(client_state* state) { - EGLint attrs[] = { - EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - EGL_CONFORMANT, EGL_OPENGL_BIT, - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 24, - EGL_NONE - }; - - state->egl_window = wl_egl_window_create(state->surface, state->width, state->height); - if (!state->egl_window) { - fprintf(stderr, "ewindow\n"); - return false; - } - - - state->egl_display = eglGetDisplay(state->display); - if (state->egl_display == EGL_NO_DISPLAY) { - fprintf(stderr, "edisplay\n"); - return false; - } - { - EGLint major, minor; - if (eglInitialize(state->egl_display, &major, &minor) != EGL_TRUE) { - fprintf(stderr, "eglinit\n"); - return false; - } - - printf("EGL version %u.%u\n", major, minor); - } - eglBindAPI(EGL_OPENGL_API); - - EGLint num_configs; - if (eglChooseConfig(state->egl_display, attrs, &state->egl_config, 1, &num_configs) != EGL_TRUE) { - fprintf(stderr, "econfig: %d\n", eglGetError()); - return false; - } - - state->egl_surface = eglCreateWindowSurface(state->egl_display, state->egl_config, - (EGLNativeWindowType)state->egl_window, NULL); - if (state->egl_surface == EGL_NO_SURFACE) { - fprintf(stderr, "esurface\n"); - return false; - } - - state->egl_context = eglCreateContext(state->egl_display, state->egl_config, - EGL_NO_CONTEXT, NULL); - if (state->egl_context == EGL_NO_CONTEXT) { - fprintf(stderr, "econtext: %x\n", eglGetError()); - return false; - } - - eglMakeCurrent(state->egl_display, state->egl_surface, state->egl_surface, state->egl_context); - - if (!gladLoadGL()) { - fprintf(stderr, "gladLoadGL"); - return false; - } - - { - GLint major, minor; - glGetIntegerv(GL_MAJOR_VERSION, &major); - glGetIntegerv(GL_MINOR_VERSION, &minor); - printf("GL version %u.%u\n", major, minor); - } - return true; -} - int main() { client_state state = {0}; @@ -116,8 +47,6 @@ int main() { while (state.running) { wl_display_dispatch_pending(state.display); - glClearColor(1.0, 1.0, 1.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - eglSwapBuffers(state.egl_display, state.egl_surface); + render_frame(&state); } } @@ -1,5 +1,6 @@ #ifndef STATE_H_ #define STATE_H_ + #include <wayland-client.h> #include <wayland-egl.h> #include <wlr-layer-shell-unstable-v1.h> @@ -24,18 +25,10 @@ typedef struct { struct wl_keyboard* keyboard; struct wl_pointer* pointer; - struct wl_surface* cursor_surface; - struct wl_cursor_image* cursor_image; - struct wl_cursor_theme* cursor_theme; - struct wl_buffer* cursor_buffer; - struct wl_cursor* cursor; - - struct wl_buffer* screen_buffer; - struct wp_cursor_shape_manager_v1* cursor_shape_manager; struct wp_cursor_shape_device_v1* cursor_shape_device; - struct xkb_context* xkb_context; + struct xkb_context* xkb_context; struct xkb_keymap* xkb_keymap; struct xkb_state* xkb_state; struct xkb_compose_state* xkb_compose_state; |
