aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2025-10-11 01:45:08 -0400
committerJack Jamison <jackqjamison@gmail.com>2025-10-11 01:45:08 -0400
commitba3a68a4f73f6653b1e1b095abc08234dedc504d (patch)
treec7f12e78cd6d97c7f559811064865bc8a6eeeb9f
parentf23baade916e844b6b6c9714e6b5d81020f6ba57 (diff)
added graphics.h
-rw-r--r--Makefile6
-rw-r--r--graphics.c79
-rw-r--r--graphics.h9
-rw-r--r--main.c79
-rw-r--r--state.h11
5 files changed, 97 insertions, 87 deletions
diff --git a/Makefile b/Makefile
index 79e9587..98e3784 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/main.c b/main.c
index fae4ac2..9baf779 100644
--- a/main.c
+++ b/main.c
@@ -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);
}
}
diff --git a/state.h b/state.h
index 514b263..fec2cd3 100644
--- a/state.h
+++ b/state.h
@@ -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;