test triangle rendered?

This commit is contained in:
veclavtlica
2026-09-13 22:30:19 +03:00
parent 4e1fa1ed1c
commit 578c4a6d4f
6 changed files with 193 additions and 3 deletions
+31
View File
@@ -7,6 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "../../Common/gem.h"
#include "../../Common/lzw.h"
#include "../../Common/mat.h"
#include "display.h"
@@ -132,6 +133,36 @@ extern int plr_display_x11_main(int argc, char *argv[]) {
pixel_buffer[pixel_index + 3] = 0; // Alpha/Padding
}
}
com_mat_t proj = com_mat_perspective(640, 480, 1, 100 * COM_FIX_FRACUNIT,
COM_FIX_PIHALF);
com_mat_t view = com_mat_look_at(com_vec_from(0, 0, 0),
com_vec_from(0, COM_FIX_FRACUNIT, 0),
com_vec_from(-COM_FIX_FRACUNIT, 0, 0));
com_mat_t mvp = com_mat_reoder(com_mat_mul(proj, view));
com_vec_t v0 =
com_vec_from(5 * COM_FIX_FRACUNIT, 0, 2 * COM_FIX_FRACUNIT);
com_vec_t v1 = com_vec_from(5 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT,
4 * COM_FIX_FRACUNIT);
com_vec_t v2 = com_vec_from(5 * COM_FIX_FRACUNIT, 2 * COM_FIX_FRACUNIT,
4 * COM_FIX_FRACUNIT);
com_vec_t c0 = com_gem_vec_project_clip(mvp, v0);
com_vec_t c1 = com_gem_vec_project_clip(mvp, v1);
com_vec_t c2 = com_gem_vec_project_clip(mvp, v2);
com_pnt_t p0, p1, p2;
uint8_t cc0 = com_gem_clip_vis_project(c0, &p0);
uint8_t cc1 = com_gem_clip_vis_project(c1, &p1);
uint8_t cc2 = com_gem_clip_vis_project(c2, &p2);
com_pnt_print(p0);
com_pnt_print(p1);
com_pnt_print(p2);
com_gem_draw_triangle(p0, p1, p2, (uint8_t *)pixel_buffer);
// Draw the complete image onto the window when exposed
XPutImage(display,
window, // Target drawable
+1
View File
@@ -2,6 +2,7 @@ CC=clang
# todo: Only link to libm on debug.
CFLAGS=-lX11 -Wall -std=c99 -g3 -O3 -msse2 -lm
DEPS = ../Common/lzw.h ../Common/mat.h ../Common/vec.h ../Common/fix.h ../Common/def.h ../Common/bits.h \
../Common/gem.h \
../Common/Timer/timer.h \
./Display/display.h
OBJ = ../Common/lzw.o ../Common/fix.o ../Common/mat.o