src/shader.c

changeset 80
9f7bfc0a1dc3
parent 79
ed46a265b679
child 83
f7ce0db6f72b
--- a/src/shader.c	Thu Mar 20 20:36:09 2025 +0100
+++ b/src/shader.c	Fri Apr 18 19:34:31 2025 +0200
@@ -110,12 +110,32 @@
     }
 }
 
-void asc_shader_program_destroy(AscShaderProgram program) {
-    if (program.id > 0) {
-        asc_dprintf("Delete Shader Program %u", program.id);
-        glDeleteProgram(program.id);
+void asc_shader_program_destroy(AscShaderProgram *program) {
+    if (program->id > 0) {
+        asc_dprintf("Delete Shader Program %u", program->id);
+        glDeleteProgram(program->id);
     }
-    program.id = 0;
+    program->id = 0;
+}
+
+int asc_shader_sprite_init(AscShaderSprite *sprite) {
+    AscShaderCodes codes;
+    if (asc_shader_load_code_files((AscShaderCodeFiles){
+        .vtx = "./shader/sprite_vtx.glsl",
+        .frag = "./shader/sprite_frag.glsl"
+    }, &codes)) {
+        asc_error("Loading sprite shader failed.");
+        return 1;
+    }
+    sprite->program = asc_shader_program_create(codes);
+    if (asc_has_error()) {
+        asc_shader_free_codes(codes);
+        return 1;
+    }
+    sprite->depth = glGetUniformLocation(sprite->program.id, "depth");
+    sprite->tex = glGetUniformLocation(sprite->program.id, "texture");
+    asc_shader_free_codes(codes);
+    return 0;
 }
 
 AscShaderProgram asc_shader_program_create(AscShaderCodes codes) {

mercurial