Wed, 08 Nov 2023 21:46:29 +0100
add projection matrix to AscWindow
src/ascension/datatypes.h | file | annotate | diff | comparison | revisions | |
src/ascension/window.h | file | annotate | diff | comparison | revisions | |
src/window.c | file | annotate | diff | comparison | revisions |
--- a/src/ascension/datatypes.h Tue Nov 07 21:24:06 2023 +0100 +++ b/src/ascension/datatypes.h Wed Nov 08 21:46:29 2023 +0100 @@ -35,6 +35,10 @@ extern "C" { #endif +// -------------------------------------------------------------------------- +// Datatype Definitions +// -------------------------------------------------------------------------- + typedef unsigned char asc_ubyte; typedef signed char asc_sbyte; @@ -62,6 +66,12 @@ #endif } asc_col4f; +typedef float asc_mat4f[4][4]; + +// -------------------------------------------------------------------------- +// General Utility Functions +// -------------------------------------------------------------------------- + static inline int asc_clamp_i(int v, int min, int max) { if (v < min) return min; if (v > max) return max; @@ -90,6 +100,25 @@ return r; } +// -------------------------------------------------------------------------- +// Matrix Functions +// -------------------------------------------------------------------------- + +static inline void asc_mat4f_ortho( + asc_mat4f mat, + float left, + float right, + float bottom, + float top +) { + memset(mat, 0, sizeof(float) * 16); + mat[0][0] = 2.f / (right - left); + mat[1][1] = 2.f / (top - bottom); + mat[2][2] = -1; + mat[3][0] = -(right + left) / (right - left); + mat[3][1] = -(top + bottom) / (top - bottom); +} + #ifdef __cplusplus } // extern "C" #endif
--- a/src/ascension/window.h Tue Nov 07 21:24:06 2023 +0100 +++ b/src/ascension/window.h Wed Nov 08 21:46:29 2023 +0100 @@ -57,6 +57,7 @@ SDL_GLContext glctx; Uint32 id; asc_vec2i dimensions; + asc_mat4f projection; } AscWindow;
--- a/src/window.c Tue Nov 07 21:24:06 2023 +0100 +++ b/src/window.c Wed Nov 08 21:46:29 2023 +0100 @@ -57,6 +57,7 @@ if (asc_context.windows[i].id == id) { asc_context.windows[i].dimensions.width = width; asc_context.windows[i].dimensions.height = height; + asc_mat4f_ortho(asc_context.windows[i].projection, 0, (float) width, (float) height, 0); return; } } @@ -144,6 +145,13 @@ &window->dimensions.width, &window->dimensions.height ); + asc_mat4f_ortho( + window->projection, + 0, + (float) window->dimensions.width, + (float) window->dimensions.height, + 0 + ); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, settings->gl_major_version);