diff --git a/libc3/window/cairo/cairo_png.c b/libc3/window/cairo/cairo_png.c
deleted file mode 100644
index a82c914..0000000
--- a/libc3/window/cairo/cairo_png.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* c3
- * Copyright 2022,2023 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software granted the above
- * copyright notice and this permission paragraph are included in all
- * copies and substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#include <assert.h>
-#include <err.h>
-#include <unistd.h>
-#include <cairo.h>
-#include <libc3/c3.h>
-#include "cairo_png.h"
-
-cairo_surface_t * cairo_png_1 (const s8 *path)
-{
- s_str found_str;
- s_str path_str;
- cairo_surface_t *surface = NULL;
- assert(path);
- str_init_1(&path_str, NULL, path);
- if (file_search(&path_str, sym_1("r"), &found_str)) {
- surface = cairo_image_surface_create_from_png(found_str.ptr.ps8);
- if (! surface)
- warnx("cairo_png_1: cairo_image_surface_create_from_png: %s",
- found_str.ptr.ps8);
- str_clean(&found_str);
- }
- else
- warnx("cairo_png_1: file not found: %s", path);
- return surface;
-}
diff --git a/libc3/window/cairo/cairo_png.h b/libc3/window/cairo/cairo_png.h
deleted file mode 100644
index 3d0c204..0000000
--- a/libc3/window/cairo/cairo_png.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* c3
- * Copyright 2022,2023 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software granted the above
- * copyright notice and this permission paragraph are included in all
- * copies and substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#ifndef CAIRO_PNG_H
-#define CAIRO_PNG_H
-
-#include "types.h"
-#include <cairo.h>
-
-cairo_surface_t * cairo_png_1 (const s8 *path);
-
-#endif /* CAIRO_PNG_H */
diff --git a/libc3/window/cairo/cairo_sprite.c b/libc3/window/cairo/cairo_sprite.c
index 02feaad..ebc907a 100644
--- a/libc3/window/cairo/cairo_sprite.c
+++ b/libc3/window/cairo/cairo_sprite.c
@@ -56,12 +56,12 @@ s_cairo_sprite * cairo_sprite_init (s_cairo_sprite *sprite,
warnx("cairo_sprite_init: NULL surface");
return NULL;
}
- sprite->surface_w = cairo_image_surface_get_width(surface);
- sprite->surface_h = cairo_image_surface_get_height(surface);
+ sprite->total_w = cairo_image_surface_get_width(surface);
+ sprite->total_h = cairo_image_surface_get_height(surface);
sprite->dim_x = dim_x;
sprite->dim_y = dim_y;
- sprite->w = sprite->surface_w / dim_x;
- sprite->h = sprite->surface_h / dim_y;
+ sprite->w = sprite->total_w / dim_x;
+ sprite->h = sprite->total_h / dim_y;
sprite->frame_count = frame_count ? frame_count : (dim_x * dim_y);
return sprite;
}
diff --git a/libc3/window/cairo/demo/window_cairo_demo.c b/libc3/window/cairo/demo/window_cairo_demo.c
index 4881ede..62ed72a 100644
--- a/libc3/window/cairo/demo/window_cairo_demo.c
+++ b/libc3/window/cairo/demo/window_cairo_demo.c
@@ -18,8 +18,8 @@
#include <xkbcommon/xkbcommon.h>
#include "../../window.h"
#include "../window_cairo.h"
-#include "../cairo_png.h"
#include "../cairo_sprite.h"
+#include "../cairo_surface.h"
#include "window_cairo_demo.h"
#include "bg_rect.h"
#include "lightspeed.h"
diff --git a/libc3/window/cairo/demo/window_cairo_demo.h b/libc3/window/cairo/demo/window_cairo_demo.h
index 16930b7..8df2e6b 100644
--- a/libc3/window/cairo/demo/window_cairo_demo.h
+++ b/libc3/window/cairo/demo/window_cairo_demo.h
@@ -18,7 +18,7 @@
#define WINDOW_CAIRO_DEMO_SEQUENCE_COUNT 4
bool window_cairo_demo_button (s_window_cairo *window, u8 button,
- sw x, sw y);
+ sw x, sw y);
bool window_cairo_demo_key (s_window_cairo *window, uw keysym);
bool window_cairo_demo_load (s_window_cairo *window);
bool window_cairo_demo_render (s_window_cairo *window, cairo_t *cr);
diff --git a/libc3/window/cairo/sources.mk b/libc3/window/cairo/sources.mk
index f6d4a27..b87ea50 100644
--- a/libc3/window/cairo/sources.mk
+++ b/libc3/window/cairo/sources.mk
@@ -1,14 +1,14 @@
# sources.mk generated by update_sources
HEADERS = \
cairo_font.h \
- cairo_png.h \
cairo_sprite.h \
+ cairo_surface.h \
types.h \
window_cairo.h \
SOURCES = \
cairo_font.c \
- cairo_png.c \
cairo_sprite.c \
+ cairo_surface.c \
window_cairo.c \
diff --git a/libc3/window/cairo/sources.sh b/libc3/window/cairo/sources.sh
index 8a467a8..d2c7fc8 100644
--- a/libc3/window/cairo/sources.sh
+++ b/libc3/window/cairo/sources.sh
@@ -1,3 +1,3 @@
# sources.sh generated by update_sources
-HEADERS='cairo_font.h cairo_png.h cairo_sprite.h types.h window_cairo.h '
-SOURCES='cairo_font.c cairo_png.c cairo_sprite.c window_cairo.c '
+HEADERS='cairo_font.h cairo_sprite.h cairo_surface.h types.h window_cairo.h '
+SOURCES='cairo_font.c cairo_sprite.c cairo_surface.c window_cairo.c '
diff --git a/libc3/window/cairo/types.h b/libc3/window/cairo/types.h
index 7042c35..7c27bf4 100644
--- a/libc3/window/cairo/types.h
+++ b/libc3/window/cairo/types.h
@@ -68,8 +68,8 @@ struct cairo_font {
};
struct cairo_sprite {
- uw surface_w;
- uw surface_h;
+ uw total_w;
+ uw total_h;
uw dim_x;
uw dim_y;
uw frame_count;
diff --git a/libc3/window/sdl2/sdl2_sprite.c b/libc3/window/sdl2/sdl2_sprite.c
index 8725265..f0c5862 100644
--- a/libc3/window/sdl2/sdl2_sprite.c
+++ b/libc3/window/sdl2/sdl2_sprite.c
@@ -29,10 +29,13 @@ static void ilEnsureInit (void)
void ilClean (void)
{
+ /*
if (g_il_is_loaded) {
- iluInit();
- ilInit();
+ iluDestroy();
+ ilDestroy();
+ g_il_is_loaded = false;
}
+ */
}
void sdl2_sprite_clean (s_sdl2_sprite *sprite)
@@ -82,6 +85,15 @@ s_sdl2_sprite * sdl2_sprite_init (s_sdl2_sprite *sprite,
sprite->w = sprite->total_w / dim_x;
sprite->h = sprite->total_h / dim_y;
sprite->frame_count = frame_count ? frame_count : (dim_x * dim_y);
+ sprite->gl_textures = malloc(frame_count * sizeof(GLuint));
+ if (! sprite->gl_textures) {
+ warn("sdl2_sprite: sprite->gl_textures");
+ ilDeleteImages(2, il_images);
+ str_clean(&sprite->path);
+ str_clean(&sprite->real_path);
+ return NULL;
+ }
+ glGenTextures(frame_count, sprite->gl_textures);
ilBindImage(il_images[1]);
ilTexImage(sprite->w, sprite->h, 1, 32, IL_RGBA, IL_UNSIGNED_BYTE,
NULL);
@@ -95,7 +107,7 @@ s_sdl2_sprite * sdl2_sprite_init (s_sdl2_sprite *sprite,
ilCopyPixels(x * sprite->w, y * sprite->h, 0,
sprite->w, sprite->h, 1, IL_RGBA, IL_UNSIGNED_BYTE,
data);
-
+ glTexImage2D(
i++;
x++;
}