Minor changes to depth buffering

This commit is contained in:
Abdelrahman Said 2024-07-14 22:36:36 +01:00
parent 70dfb5d5ee
commit e96400f74e
2 changed files with 6 additions and 3 deletions

View File

@ -9,6 +9,8 @@
#include <SDL2/SDL_events.h> #include <SDL2/SDL_events.h>
#include <SDL2/SDL_keycode.h> #include <SDL2/SDL_keycode.h>
#include <math.h> #include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main(void) { int main(void) {

View File

@ -7,6 +7,7 @@
#include "window/window.h" #include "window/window.h"
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
@ -232,8 +233,8 @@ void draw_filled_triangle(window_t *wnd, Arena *arena, triangle_t triangle) {
i32 index = -1; i32 index = -1;
i64 xl = -1; i64 xl = -1;
i64 xr = -1; i64 xr = -1;
f32 current_z = INFINITY; f32 current_z = 0.0f;
f32 new_z = INFINITY; f32 new_z = 0.0f;
for (i64 y = y0; y <= y2; ++y) { for (i64 y = y0; y <= y2; ++y) {
index = y - y0; index = y - y0;
@ -247,7 +248,7 @@ void draw_filled_triangle(window_t *wnd, Arena *arena, triangle_t triangle) {
current_z = get_z_pixel(wnd, x, y); current_z = get_z_pixel(wnd, x, y);
new_z = list_get(z_segment, x - xl); new_z = list_get(z_segment, x - xl);
if (new_z > current_z) { if (new_z >= current_z) {
set_z_pixel(wnd, x, y, new_z); set_z_pixel(wnd, x, y, new_z);
set_pixel(wnd, x, y, triangle.colour); set_pixel(wnd, x, y, triangle.colour);
} }