-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw.c
More file actions
64 lines (57 loc) · 1.73 KB
/
draw.c
File metadata and controls
64 lines (57 loc) · 1.73 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ishakuro <ishakuro@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/14 16:58:16 by ishakuro #+# #+# */
/* Updated: 2022/03/21 10:40:11 by ishakuro ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
t_p point(int x, int y)
{
t_p p;
p.x = x;
p.y = y;
return (p);
}
void init_img(t_mlx *mlx)
{
mlx->img = mlx_new_image(mlx->mlx, 1920, 1080);
if (!mlx->img)
exit_program(IMG_ERROR);
mlx->addr = mlx_get_data_addr(mlx->img, &mlx->bits_per_pixel,
&mlx->line_length, &mlx->endian);
if (!mlx->addr)
exit_program(IMG_ERROR);
}
void destroy_img(t_mlx *mlx)
{
mlx_destroy_image(mlx->mlx, mlx->img);
mlx->addr = NULL;
mlx->img = NULL;
}
void draw(t_mlx *mlx)
{
int x;
int y;
y = 0;
init_img(mlx);
while (y < mlx->map->height)
{
x = 0;
while (x < mlx->map->width)
{
if (x != mlx->map->width - 1)
bresenham(point(x, y), point(x + 1, y), mlx);
if (y != mlx->map->height - 1)
bresenham(point(x, y), point(x, y + 1), mlx);
x++;
}
y++;
}
mlx_put_image_to_window(mlx->mlx, mlx->window, mlx->img, 0, 0);
destroy_img(mlx);
}