Thu, 21 Mar 2024 20:48:18 +0100
rename font shader to generic sprite shader
shader/font_frag.glsl | file | annotate | diff | comparison | revisions | |
shader/font_vtx.glsl | file | annotate | diff | comparison | revisions | |
shader/sprite_frag.glsl | file | annotate | diff | comparison | revisions | |
shader/sprite_vtx.glsl | file | annotate | diff | comparison | revisions | |
src/ascension/shader.h | file | annotate | diff | comparison | revisions | |
src/scene.c | file | annotate | diff | comparison | revisions | |
src/shader.c | file | annotate | diff | comparison | revisions | |
src/text.c | file | annotate | diff | comparison | revisions |
1.1 --- a/shader/font_frag.glsl Thu Mar 21 20:34:33 2024 +0100 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,10 +0,0 @@ 1.4 -#version 400 core 1.5 - 1.6 -layout(location = 0) out vec4 diffuse; 1.7 -in vec2 texcoord; 1.8 - 1.9 -uniform sampler2DRect surface; 1.10 - 1.11 -void main(void) { 1.12 - diffuse = texture(surface, texcoord); 1.13 -}
2.1 --- a/shader/font_vtx.glsl Thu Mar 21 20:34:33 2024 +0100 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,12 +0,0 @@ 2.4 -#version 400 core 2.5 - 2.6 -layout(location = 0) in vec2 position; 2.7 -out vec2 texcoord; 2.8 - 2.9 -uniform mat4 projection; 2.10 -uniform mat4 model; 2.11 - 2.12 -void main(void) { 2.13 - gl_Position = projection*model*vec4(position, 0.0, 1.0); 2.14 - texcoord = vec2(model[0].x, model[1].y)*position; 2.15 -}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/shader/sprite_frag.glsl Thu Mar 21 20:48:18 2024 +0100 3.3 @@ -0,0 +1,10 @@ 3.4 +#version 400 core 3.5 + 3.6 +layout(location = 0) out vec4 diffuse; 3.7 +in vec2 texcoord; 3.8 + 3.9 +uniform sampler2DRect surface; 3.10 + 3.11 +void main(void) { 3.12 + diffuse = texture(surface, texcoord); 3.13 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/shader/sprite_vtx.glsl Thu Mar 21 20:48:18 2024 +0100 4.3 @@ -0,0 +1,12 @@ 4.4 +#version 400 core 4.5 + 4.6 +layout(location = 0) in vec2 position; 4.7 +out vec2 texcoord; 4.8 + 4.9 +uniform mat4 projection; 4.10 +uniform mat4 model; 4.11 + 4.12 +void main(void) { 4.13 + gl_Position = projection*model*vec4(position, 0.0, 1.0); 4.14 + texcoord = vec2(model[0].x, model[1].y)*position; 4.15 +}
5.1 --- a/src/ascension/shader.h Thu Mar 21 20:34:33 2024 +0100 5.2 +++ b/src/ascension/shader.h Thu Mar 21 20:48:18 2024 +0100 5.3 @@ -39,13 +39,13 @@ 5.4 int projection; 5.5 } AscShaderProgram; 5.6 5.7 -typedef struct AscShaderFont { 5.8 +typedef struct AscShaderSprite { 5.9 AscShaderProgram base; 5.10 int surface; 5.11 -} AscShaderFont; 5.12 +} AscShaderSprite; 5.13 5.14 5.15 -extern AscShaderFont ASC_SHADER_FONT; 5.16 +extern AscShaderSprite ASC_SHADER_SPRITE; 5.17 5.18 5.19 /**
6.1 --- a/src/scene.c Thu Mar 21 20:34:33 2024 +0100 6.2 +++ b/src/scene.c Thu Mar 21 20:48:18 2024 +0100 6.3 @@ -160,8 +160,8 @@ 6.4 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 6.5 // TODO: see if we can really always ignore the view matrix 6.6 // TODO: compute render order for alpha blending to work correctly 6.7 - glUseProgram(ASC_SHADER_FONT.base.id); 6.8 - glUniformMatrix4fv(ASC_SHADER_FONT.base.projection, 1, 6.9 + glUseProgram(ASC_SHADER_SPRITE.base.id); 6.10 + glUniformMatrix4fv(ASC_SHADER_SPRITE.base.projection, 1, 6.11 GL_FALSE, camera->projection); 6.12 asc_scene_draw_render_group(scene->rg_fonts); 6.13 }
7.1 --- a/src/shader.c Thu Mar 21 20:34:33 2024 +0100 7.2 +++ b/src/shader.c Thu Mar 21 20:48:18 2024 +0100 7.3 @@ -32,7 +32,7 @@ 7.4 #include <GL/glew.h> 7.5 #include <string.h> 7.6 7.7 -AscShaderFont ASC_SHADER_FONT; 7.8 +AscShaderSprite ASC_SHADER_SPRITE; 7.9 7.10 7.11 AscShader asc_shader_compile(unsigned int type, 7.12 @@ -137,10 +137,10 @@ 7.13 } 7.14 7.15 void asc_shader_initialize_predefined(void) { 7.16 - ASC_SHADER_FONT.base = asc_shader_compile_link_discard("shader/font_vtx.glsl", "shader/font_frag.glsl"); 7.17 - ASC_SHADER_FONT.surface = glGetUniformLocation(ASC_SHADER_FONT.base.id, "surface"); 7.18 + ASC_SHADER_SPRITE.base = asc_shader_compile_link_discard("shader/sprite_vtx.glsl", "shader/sprite_frag.glsl"); 7.19 + ASC_SHADER_SPRITE.surface = glGetUniformLocation(ASC_SHADER_SPRITE.base.id, "surface"); 7.20 } 7.21 7.22 void asc_shader_destroy_predefined(void) { 7.23 - asc_shader_program_destroy(ASC_SHADER_FONT.base); 7.24 + asc_shader_program_destroy(ASC_SHADER_SPRITE.base); 7.25 } 7.26 \ No newline at end of file
8.1 --- a/src/text.c Thu Mar 21 20:34:33 2024 +0100 8.2 +++ b/src/text.c Thu Mar 21 20:48:18 2024 +0100 8.3 @@ -38,13 +38,13 @@ 8.4 } 8.5 8.6 // Upload model matrix 8.7 - glUniformMatrix4fv(ASC_SHADER_FONT.base.model, 1, 8.8 + glUniformMatrix4fv(ASC_SHADER_SPRITE.base.model, 1, 8.9 GL_FALSE, node->base.final_transform); 8.10 8.11 // Upload surface 8.12 glActiveTexture(GL_TEXTURE0); 8.13 glBindTexture(GL_TEXTURE_RECTANGLE, node->tex_id); 8.14 - glUniform1i(ASC_SHADER_FONT.surface, 0); 8.15 + glUniform1i(ASC_SHADER_SPRITE.surface, 0); 8.16 8.17 // Draw mesh 8.18 asc_primitives_draw_plane();