summaryrefslogtreecommitdiff
path: root/sources/texture.h
diff options
context:
space:
mode:
authorHenrique Alves <henrique.alves@itsjungle.xyz>2024-04-22 10:32:24 +0300
committerHenrique Alves <henrique.alves@itsjungle.xyz>2024-04-22 10:32:24 +0300
commitcef05d32d6a8e38d8d84a5a7efac4494b00f1ce9 (patch)
treec8275c6c573deca60efa14a96f26d7c7a37847d3 /sources/texture.h
parenta73b626d98e331605fdfd293ab4c006a84cfd8b8 (diff)
downloadgamejam-slgj-2024-cef05d32d6a8e38d8d84a5a7efac4494b00f1ce9.tar.gz
gamejam-slgj-2024-cef05d32d6a8e38d8d84a5a7efac4494b00f1ce9.tar.bz2
gamejam-slgj-2024-cef05d32d6a8e38d8d84a5a7efac4494b00f1ce9.zip
Testing texture API
Diffstat (limited to 'sources/texture.h')
-rw-r--r--sources/texture.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/sources/texture.h b/sources/texture.h
new file mode 100644
index 0000000..f7bd3c3
--- /dev/null
+++ b/sources/texture.h
@@ -0,0 +1,48 @@
+#include "raylib.h"
+#include <libguile.h>
+#include <stdio.h>
+
+struct texture_2d {
+ Texture2D texture;
+};
+
+static SCM texture_2d_type;
+
+static void finalize_texture_2d(SCM texture_2d_scm) {
+ struct texture_2d *texture_2d;
+ texture_2d = scm_foreign_object_ref(texture_2d_scm, 0);
+ UnloadTexture(texture_2d->texture);
+}
+
+static void init_texture_2d_type (void) {
+ SCM name, slots;
+ scm_t_struct_finalize finalizer;
+
+ name = scm_from_utf8_symbol("texture_2d");
+ slots = scm_list_1(scm_from_utf8_symbol("data"));
+ finalizer = finalize_texture_2d;
+
+ texture_2d_type = scm_make_foreign_object_type(name, slots, finalizer);
+}
+
+static SCM rl_load_texture(SCM file_name_scm) {
+ scm_t_string_failed_conversion_handler handler;
+ char* file_name = scm_to_stringn(file_name_scm, NULL, NULL, handler);
+
+ struct texture_2d *new_texture_2d;
+
+ // Tested different mallocs, didn't work
+ /* new_texture_2d = (struct texture_2d *) scm_malloc(sizeof (struct texture_2d)); */
+ new_texture_2d = (struct texture_2d *) scm_gc_malloc(sizeof (struct texture_2d), "texture_2d");
+
+ new_texture_2d->texture = LoadTexture(file_name);
+
+ return scm_make_foreign_object_1(texture_2d_type, new_texture_2d);
+}
+
+static void rl_texture_define_methods() {
+ init_texture_2d_type();
+
+ scm_c_define_gsubr ("rl-load-texture", 1, 0, 0, rl_load_texture);
+}
+