summaryrefslogtreecommitdiff
path: root/src/surface.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2021-10-29 13:23:44 +0100
committerPhil Jones <philj56@gmail.com>2021-10-29 13:23:44 +0100
commitc691b8e48c572e2d5f1c7c16c8f42babd7d706d5 (patch)
treeb3d601919670c41e0409477e22371ab77e092aa2 /src/surface.c
parent3bf156c9d9598acbee38c49d17cdb7d77e79d520 (diff)
Basic text entry working.
Diffstat (limited to 'src/surface.c')
-rw-r--r--src/surface.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/surface.c b/src/surface.c
new file mode 100644
index 0000000..6253801
--- /dev/null
+++ b/src/surface.c
@@ -0,0 +1,34 @@
+#include "client.h"
+#include "gl.h"
+#include "surface.h"
+
+#undef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+void surface_initialise(struct surface *surface, struct wl_display *wl_display, struct image *texture)
+{
+ egl_create_window(&surface->egl, surface->wl_surface, surface->width, surface->height);
+ egl_create_context(&surface->egl, wl_display);
+ gl_initialise(&surface->gl, texture);
+}
+
+void surface_draw(struct surface *surface, struct color *color, struct image *texture)
+{
+ egl_make_current(&surface->egl);
+ gl_clear(&surface->gl, color);
+
+ if (texture != NULL && texture->buffer != NULL) {
+ double scale = MAX(
+ (double)surface->width / texture->width,
+ (double)surface->height / texture->height
+ );
+ uint32_t width = (uint32_t)(scale * texture->width);
+ uint32_t height = (uint32_t)(scale * texture->height);
+ int32_t x = -((int32_t)width - (int32_t)surface->width) / 2;
+ int32_t y = -((int32_t)height - (int32_t)surface->height) / 2;
+
+ gl_draw_texture(&surface->gl, texture, x, y, width, height);
+ }
+
+ egl_swap_buffers(&surface->egl);
+}