-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
joppe
committed
Jan 24, 2024
1 parent
0a01786
commit 546a1c0
Showing
5 changed files
with
28 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: jboeve <[email protected]>+#+ */ | ||
/* +#+ */ | ||
/* 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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* 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,41 +59,44 @@ 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); | ||
} | ||
|
||
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) | ||
{ | ||
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++; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* :::::::: */ | ||
/* set_textures.c :+: :+: */ | ||
/* set_textures.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* 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 <stdio.h> | ||
|
||
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); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* :::::::: */ | ||
/* vec_utils.c :+: :+: */ | ||
/* vec_utils.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* 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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.