src/sprite.c

changeset 115
e5f8c99b0987
parent 114
5b91bbab1ac0
child 116
bfb2a7d62047
--- a/src/sprite.c	Sat May 10 15:42:56 2025 +0200
+++ b/src/sprite.c	Sat May 10 18:51:45 2025 +0200
@@ -32,8 +32,12 @@
 
 #include <GL/glew.h>
 
+#include "ascension/mesh.h"
+
 static void asc_sprite_destroy(AscSceneNode *node) {
-    ((AscSprite *) node)->texture->refcount--;
+    AscSprite *sprite = (AscSprite *) node;
+    asc_mesh_destroy(&sprite->mesh);
+    sprite->texture->refcount--;
 }
 
 AscSceneNode *asc_sprite_create(struct asc_sprite_create_args args) {
@@ -52,6 +56,7 @@
     node->destroy_func = asc_sprite_destroy;
 
     node->position = asc_vec3f_new(args.x, args.y, ASC_SCENE_2D_DEPTH_OFFSET);
+    // TODO: do not use scale, add mesh params instead
     node->scale = asc_vec3f_new(
         args.width == 0 ? args.texture->width : args.width,
         args.height == 0 ? args.texture->height : args.height,
@@ -59,6 +64,9 @@
     );
     asc_node_update_transform(node);
 
+    // initialize mesh
+    asc_mesh_plane_2d(&sprite->mesh);
+
     return node;
 }
 
@@ -80,5 +88,5 @@
     }
 
     // Draw mesh
-    asc_mesh_draw_triangle_strip(ASC_PRIMITIVE_PLANE);
+    asc_mesh_draw_triangle_strip(&node->mesh);
 }

mercurial