Minor changes to depth buffering
This commit is contained in:
parent
70dfb5d5ee
commit
e96400f74e
@ -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) {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user