diff --git a/include/meta.h b/include/meta.h index bac0505..a6a0ddc 100644 --- a/include/meta.h +++ b/include/meta.h @@ -6,7 +6,7 @@ /* By: jboeve +#+ */ /* +#+ */ /* Created: 2023/11/01 20:07:37 by jboeve#+##+# */ -/* Updated: 2024/01/18 11:56:06 by jboeve ######## odam.nl */ +/* Updated: 2024/01/25 00:28:17 by joppe ######## odam.nl */ /**/ /* ************************************************************************** */ @@ -186,6 +186,7 @@ typedef struct s_attr { t_tex w; t_tex f; t_tex c; + t_tex c_alt; t_rgba floor_c; t_rgba ceiling_c; } t_attr; diff --git a/src/game/render_viewport.c b/src/game/render_viewport.c index fa696ad..5b8dd48 100644 --- a/src/game/render_viewport.c +++ b/src/game/render_viewport.c @@ -6,7 +6,7 @@ /* By: yzaim +#+ */ /* +#+ */ /* Created: 2024/01/08 15:28:08 by yzaim #+# #+# */ -/* Updated: 2024/01/24 18:17:54 by jboeve ######## odam.nl */ +/* Updated: 2024/01/25 00:35:46 by joppe ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -59,24 +59,26 @@ static void draw_column(t_meta *meta, t_ray *ray, uint32_t col, uint32_t h) } } -void draw_fc(mlx_image_t *image, t_vray *vray, mlx_texture_t *f_tex, mlx_texture_t *c_tex, uint32_t col, uint32_t row) +void draw_fc(mlx_image_t *image, t_vray *vray, mlx_texture_t *f_tex, mlx_texture_t *c_tex, mlx_texture_t *c_alt_tex, uint32_t col, uint32_t row) { - t_vec2i cell; - - cell = (t_vec2i){(int)vray->floor.x, (int)vray->floor.y}; - // cell = vec2d_to_vec2i(floor); - + const t_vec2i cell = vec2d_to_vec2i(vray->floor); // coordinate of pixel in texture const t_vec2i c_t = (t_vec2i){(int)(c_tex->width * (vray->floor.x - cell.x)) & (c_tex->width - 1), (int)(c_tex->height * (vray->floor.y - cell.y)) & (c_tex->height - 1)}; const t_vec2i f_t = (t_vec2i){(int)(f_tex->width * (vray->floor.x - cell.x)) & (f_tex->width - 1), (int)(f_tex->height * (vray->floor.y - cell.y)) & (f_tex->height - 1)}; - vray->floor = vec2d_add(vray->floor, vray->step); - const uint32_t c_pixel = pixel_picker(c_tex, c_t.x, c_t.y); + const uint32_t c_alt_pixel = pixel_picker(c_alt_tex, c_t.x, c_t.y); const uint32_t f_pixel = pixel_picker(f_tex, f_t.x, f_t.y); - mlx_put_pixel(image, col, WINDOW_HEIGHT - row - 1, c_pixel); + + vray->floor = vec2d_add(vray->floor, vray->step); + + if (cell.y % 2 && cell.x % 2) + mlx_put_pixel(image, col, WINDOW_HEIGHT - row - 1, c_alt_pixel); + else + mlx_put_pixel(image, col, WINDOW_HEIGHT - row - 1, c_pixel); + mlx_put_pixel(image, col, row, f_pixel); } @@ -84,8 +86,9 @@ void render_viewport(mlx_image_t *image, t_player *p) { uint32_t col = 0; uint32_t row = 0; - //floor and ceiling + + //floor and ceiling if (p->should_render) { while (row < image->height) @@ -93,7 +96,7 @@ void render_viewport(mlx_image_t *image, t_player *p) col = 0; while (col < image->width) { - draw_fc(p->meta->image, &p->vrays[row], p->meta->attributes.f.tex, p->meta->attributes.c.tex, col, row); + draw_fc(p->meta->image, &p->vrays[row], p->meta->attributes.f.tex, p->meta->attributes.c.tex, p->meta->attributes.c_alt.tex, col, row); col++; } row++; @@ -103,7 +106,7 @@ void render_viewport(mlx_image_t *image, t_player *p) col = 0; - while(col < image->width) + while (col < image->width) { draw_column(p->meta, &p->rays[col], col, image->height); col++; diff --git a/src/set_textures.c b/src/set_textures.c index 3978bd5..4098ff1 100644 --- a/src/set_textures.c +++ b/src/set_textures.c @@ -1,17 +1,18 @@ /* ************************************************************************** */ /* */ /* :::::::: */ -/* set_textures.c :+: :+: */ +/* set_textures.c :+: :+: */ /* +:+ */ /* By: yzaim +#+ */ /* +#+ */ /* Created: 2024/01/08 15:56:45 by yzaim #+# #+# */ -/* Updated: 2024/01/24 11:14:24 by yzaim ######## odam.nl */ +/* Updated: 2024/01/25 00:29:36 by joppe ######## odam.nl */ /* */ /* ************************************************************************** */ #include "parser.h" #include "meta.h" +#include int set_floor_and_ceiling_textures(t_attr *attributes) { @@ -27,6 +28,11 @@ int set_floor_and_ceiling_textures(t_attr *attributes) if (attributes->c.tex == NULL) return (EXIT_FAILURE); } + + attributes->c_alt.tex = mlx_load_png("texture_examples/window_square.png"); + if (attributes->c_alt.tex == NULL) + return (EXIT_FAILURE); + return (EXIT_SUCCESS); } diff --git a/src/vector/vec_utils.c b/src/vector/vec_utils.c index b34a8fb..98f5bea 100644 --- a/src/vector/vec_utils.c +++ b/src/vector/vec_utils.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* :::::::: */ -/* vec_utils.c :+: :+: */ +/* vec_utils.c :+: :+: */ /* +:+ */ /* By: yzaim +#+ */ /* +#+ */ /* Created: 2024/01/08 16:09:31 by yzaim #+# #+# */ -/* Updated: 2024/01/08 16:09:35 by yzaim ######## odam.nl */ +/* Updated: 2024/01/25 00:19:05 by joppe ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/texture_examples/window_square.png b/texture_examples/window_square.png new file mode 100644 index 0000000..7ce6793 Binary files /dev/null and b/texture_examples/window_square.png differ