aboutsummaryrefslogtreecommitdiff
path: root/examples/embedded.c
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-07-13 11:34:01 +0200
committerSimon Ser <contact@emersion.fr>2023-10-12 18:00:52 +0000
commit0bb445eeffc5bffe4ab0d3ba71f5ff41472232b7 (patch)
treef66756b51e454b96b1c1547a1572c624848c612a /examples/embedded.c
parentb82a53a918600a40dd990ef12a8e7723a2bae7d2 (diff)
examples: split clients in separate repository
The client examples are useful to try out protocols, however they don't need to live in the wlroots repository. Having both clients and compositors in the same place is confusing. The wlroots API changes often but protocols are set in stone.
Diffstat (limited to 'examples/embedded.c')
-rw-r--r--examples/embedded.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/examples/embedded.c b/examples/embedded.c
index 1bf11643..1e52e892 100644
--- a/examples/embedded.c
+++ b/examples/embedded.c
@@ -1,4 +1,6 @@
#define _POSIX_C_SOURCE 200112L
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <stdio.h>
#include <stdlib.h>
@@ -13,7 +15,6 @@
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
-#include "egl_common.h"
#include "xdg-shell-client-protocol.h"
static struct wl_display *remote_display = NULL;
@@ -31,8 +32,12 @@ static struct wlr_scene_output *scene_output = NULL;
static struct wl_listener new_surface = {0};
static struct wl_listener output_frame = {0};
-int width = 500;
-int height = 500;
+static EGLDisplay egl_display;
+static EGLConfig egl_config;
+static EGLContext egl_context;
+
+static int width = 500;
+static int height = 500;
static void draw_main_surface(void);
@@ -120,6 +125,29 @@ static void handle_new_surface(struct wl_listener *listener, void *data) {
wlr_scene_surface_create(&scene->tree, wlr_surface);
}
+static void init_egl(struct wl_display *display) {
+ egl_display = eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR, display, NULL);
+ eglInitialize(egl_display, NULL, NULL);
+
+ EGLint matched = 0;
+ const EGLint config_attribs[] = {
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_NONE,
+ };
+ eglChooseConfig(egl_display, config_attribs, &egl_config, 1, &matched);
+
+ const EGLint context_attribs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE,
+ };
+ egl_context = eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, context_attribs);
+}
+
int main(int argc, char *argv[]) {
wlr_log_init(WLR_DEBUG, NULL);
@@ -128,7 +156,7 @@ int main(int argc, char *argv[]) {
wl_registry_add_listener(registry, &registry_listener, NULL);
wl_display_roundtrip(remote_display);
- egl_init(remote_display);
+ init_egl(remote_display);
struct wl_display *local_display = wl_display_create();
struct wlr_backend *backend = wlr_wl_backend_create(local_display, remote_display);
@@ -152,7 +180,7 @@ int main(int argc, char *argv[]) {
xdg_toplevel_add_listener(xdg_toplevel, &xdg_toplevel_listener, NULL);
egl_window = wl_egl_window_create(main_surface, width, height);
- egl_surface = eglCreatePlatformWindowSurfaceEXT(egl_display,
+ egl_surface = eglCreatePlatformWindowSurface(egl_display,
egl_config, egl_window, NULL);
struct wl_surface *child_surface = wl_compositor_create_surface(compositor);