From 95d474c9565235f6cc34a65f6a9b3b4fa9dd4fd0 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 31 Aug 2024 22:24:04 +0100 Subject: [PATCH] Save viewport matrix in a variable --- src/model/render.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/model/render.c b/src/model/render.c index 6cced8c..14a5967 100644 --- a/src/model/render.c +++ b/src/model/render.c @@ -4,6 +4,7 @@ #include "utils.h" #include "vec.h" #include +#include #define TRIANGLE_VERTICES 3 @@ -211,7 +212,8 @@ internal V3f get_barycentric_coords(V3f a, V3f b, V3f c, V3f p) { internal V3f get_viewport_vertex(const V3f *vertex, const Image *img) { V4f vh = {.x = vertex->x, .y = 0.0f - vertex->y, .z = vertex->z, .w = 1.0f}; - vh = mat4x4_mul_vec4(viewport(vh.x, vh.y, img->width, img->height), vh); + M4x4f vp = viewport(vh.x, vh.y, img->width, img->height); + vh = mat4x4_mul_vec4(vp, vh); V3f output = project_vec4(vh); output.x = clamp(output.x, 0.0f, img->width);