-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawing.c
More file actions
85 lines (78 loc) · 2.13 KB
/
Copy pathdrawing.c
File metadata and controls
85 lines (78 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* drawing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fatkeski <fatkeski@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/19 18:30:45 by fatkeski #+# #+# */
/* Updated: 2025/02/24 14:49:28 by fatkeski ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/cub3d.h"
int create_trgb(int t, int r, int g, int b)
{
return (t << 24 | r << 16 | g << 8 | b);
}
int is_valid_rgb_channel(int *rgb_array)
{
int i;
int flag;
i = 0;
flag = 0;
while (i < 3)
{
if (rgb_array[i] < 0 || rgb_array[i] > 255)
flag = 1;
i++;
}
if (flag == 1)
return (FALSE);
return (TRUE);
}
void draw_background(int row, int column, t_game *game)
{
while (row < (SCREENHEIGHT / 2))
{
column = 0;
while (column < SCREENWIDTH)
{
game->img_buffer[(row * SCREENWIDTH)
+ column] = game->img.ceiling_color;
column++;
}
row++;
}
while (row < SCREENHEIGHT)
{
column = 0;
while (column < SCREENWIDTH)
{
game->img_buffer[(row * SCREENWIDTH)
+ column] = game->img.floor_color;
column++;
}
row++;
}
}
void render_wall_slice(t_game *game, int x)
{
double step;
double tex_pos;
int i;
int tex_y;
int color;
step = 1.0 * TILE / game->ray.wall_height;
tex_pos = (game->ray.start_y - SCREENHEIGHT / 2 + game->ray.wall_height / 2)
* step;
i = game->ray.start_y;
while (i <= game->ray.end_y)
{
tex_y = (int)tex_pos & 63;
tex_pos += step;
color = game->cub_surfaces[game->ray.hit_point].addr[(TILE * tex_y)
+ game->ray.tex_x];
game->img_buffer[i * SCREENWIDTH + x] = color;
i++;
}
}