implement view matrix in sprite shader

Sat, 19 Apr 2025 12:18:43 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 19 Apr 2025 12:18:43 +0200
changeset 83
f7ce0db6f72b
parent 82
4e1e698f4b0d
child 84
e4116b4b5774

implement view matrix in sprite shader

shader/sprite_vtx.glsl file | annotate | diff | comparison | revisions
src/ascension/context.h file | annotate | diff | comparison | revisions
src/font.c file | annotate | diff | comparison | revisions
src/scene.c file | annotate | diff | comparison | revisions
src/shader.c file | annotate | diff | comparison | revisions
--- a/shader/sprite_vtx.glsl	Sat Apr 19 11:42:53 2025 +0200
+++ b/shader/sprite_vtx.glsl	Sat Apr 19 12:18:43 2025 +0200
@@ -4,11 +4,12 @@
 out vec2 texcoord;
 
 uniform mat4 projection;
+uniform mat4 view;
 uniform mat4 model;
 uniform float depth;
 
 void main(void) {
-    vec4 pos = projection*model*vec4(position.x, position.y, 0, 1.0);
+    vec4 pos = projection*view*model*vec4(position.x, position.y, 0, 1.0);
     // apply depth
     pos.z = depth / -1024.0;
     gl_Position = pos;
--- a/src/ascension/context.h	Sat Apr 19 11:42:53 2025 +0200
+++ b/src/ascension/context.h	Sat Apr 19 12:18:43 2025 +0200
@@ -38,7 +38,7 @@
 /** The flag for the overall initialized state. */
 #define ASC_FLAG_INITILIZED  0x01u
 
-/** Flag is set when error buffer contains new error information. */
+/** Flag is set when the error buffer contains new error information. */
 #define ASC_FLAG_HAS_ERROR  0x02u
 
 /** Flag is set when SDL wants to quit the application. */
--- a/src/font.c	Sat Apr 19 11:42:53 2025 +0200
+++ b/src/font.c	Sat Apr 19 12:18:43 2025 +0200
@@ -38,7 +38,6 @@
 }
 
 static char const *asc_font_filename(enum AscFontStyle style) {
-    // TODO: do not assume we are running from the program dir
     switch (style) {
         case ASC_FONT_REGULAR:
             return "fonts/OpenSans-Regular.ttf";
@@ -48,6 +47,9 @@
             return "fonts/OpenSans-Italic.ttf";
         case ASC_FONT_BOLD_ITALIC:
             return "fonts/OpenSans-BoldItalic.ttf";
+        default:
+            assert(false);
+            return NULL;
     }
 }
 
--- a/src/scene.c	Sat Apr 19 11:42:53 2025 +0200
+++ b/src/scene.c	Sat Apr 19 12:18:43 2025 +0200
@@ -140,11 +140,12 @@
 
     // Sprites
     // -------
-    // TODO: implement view matrix for 2D worlds
     shader = &asc_active_window->glctx.shader.sprite.program;
     glUseProgram(shader->id);
     glUniformMatrix4fv(shader->projection, 1,
                        GL_FALSE, camera->projection);
+    glUniformMatrix4fv(shader->view, 1,
+                           GL_FALSE, camera->view);
 
     // render opaque sprites from front to back
     glDisable(GL_BLEND);
--- a/src/shader.c	Sat Apr 19 11:42:53 2025 +0200
+++ b/src/shader.c	Sat Apr 19 12:18:43 2025 +0200
@@ -95,7 +95,7 @@
         asc_dprintf("Shader Program %u linked.", id);
         AscShaderProgram prog;
         prog.id = id;
-        // TODO: maybe not every program has the same uniforms
+        // by convention every shader shall have MVP matrices
         prog.model = glGetUniformLocation(id, "model");
         prog.view = glGetUniformLocation(id, "view");
         prog.projection = glGetUniformLocation(id, "projection");

mercurial