summaryrefslogtreecommitdiff
path: root/src/tex.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2021-12-25 22:01:57 -0800
committerVito Caputo <vcaputo@pengaru.com>2021-12-25 22:01:57 -0800
commit189eac273ba14c8ca0d22b31182b030ccc4c7756 (patch)
treec49ac8c15404cb68ae4ccb4cf2a2ba0f7417c705 /src/tex.c
parent8da03aff8bca547bb83f1b049a65232f03123d5a (diff)
*: introduce a projection matrix and winmodesrev3
The bulk of this is mechanical wiring up of a projection_x to all the nodes. But this also introduces maintenance of the projection_x, with aspect-ratio preservation in two of the modes: WINDOWED and FULLSCREEN, with the previously default stretched-to-fill fullscreen mode now relegated to a third FILLSCREEN winmode. The default at startup is now an aspect ratio-preserving windowed mode. Simply press the 'f' key at any time to cycle through them. This was mostly done in sars to provide a source-available test for reproducing a fullscreen SDL2 bug I filed @ https://github.com/libsdl-org/SDL/issues/5139 Otherwise it's pretty silly to bother with doing anything on sars... but it is a handy little mule for such things.
Diffstat (limited to 'src/tex.c')
-rw-r--r--src/tex.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/tex.c b/src/tex.c
index b67af17..af110f0 100644
--- a/src/tex.c
+++ b/src/tex.c
@@ -54,6 +54,7 @@ static const char *tex_vs = ""
"#version 120\n"
"uniform mat4 model_x;"
+ "uniform mat4 projection_x;"
"attribute vec3 vertex;"
"attribute vec2 texcoord;"
@@ -61,7 +62,7 @@ static const char *tex_vs = ""
"void main()"
"{"
" gl_TexCoord[0].xy = texcoord;"
- " gl_Position = model_x * vec4(vertex, 1.f);"
+ " gl_Position = projection_x * model_x * vec4(vertex, 1.f);"
"}"
"";
@@ -81,11 +82,12 @@ static const char *tex_fs = ""
/* Render simply renders a texd texture onto the screen */
-void tex_render(tex_t *tex, float alpha, m4f_t *model_x)
+void tex_render(tex_t *tex, float alpha, m4f_t *projection_x, m4f_t *model_x)
{
int *uniforms, *attributes;
assert(tex);
+ assert(projection_x);
assert(model_x);
shader_use(tex_shader, NULL, &uniforms, NULL, &attributes);
@@ -104,7 +106,8 @@ void tex_render(tex_t *tex, float alpha, m4f_t *model_x)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glUniform1f(uniforms[0], alpha);
- glUniformMatrix4fv(uniforms[1], 1, GL_FALSE, &model_x->m[0][0]);
+ glUniformMatrix4fv(uniforms[1], 1, GL_FALSE, &projection_x->m[0][0]);
+ glUniformMatrix4fv(uniforms[2], 1, GL_FALSE, &model_x->m[0][0]);
glDrawArrays(GL_TRIANGLES, 0, 6);
@@ -123,9 +126,10 @@ tex_t * tex_new(int width, int height, const unsigned char *buf)
if (!vbo) {
/* common to all tex instances */
tex_shader = shader_pair_new(tex_vs, tex_fs,
- 2,
+ 3,
(const char *[]) {
"alpha",
+ "projection_x",
"model_x",
},
2,
© All Rights Reserved