-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
68 lines (64 loc) · 2.22 KB
/
main.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mspasic <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/17 08:39:03 by aheinane #+# #+# */
/* Updated: 2024/10/24 12:46:20 by mspasic ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int initialise_mlx(t_cub *data)
{
data->mlx = mlx_init(WIDTH, HEIGHT, "CUB3D", true);
if (!(data->mlx))
{
perror(mlx_strerror(mlx_errno));
mlx_terminate(data->mlx);
return (EXIT_FAILURE);
}
data->image = mlx_new_image(data->mlx, WIDTH, HEIGHT);
if (!(data->image))
{
mlx_close_window(data->mlx);
perror(mlx_strerror(mlx_errno));
mlx_terminate(data->mlx);
return (EXIT_FAILURE);
}
if (mlx_image_to_window(data->mlx, data->image, 0, 0) == -1)
{
mlx_close_window(data->mlx);
perror(mlx_strerror(mlx_errno));
mlx_terminate(data->mlx);
return (EXIT_FAILURE);
}
return (EXIT_SUCCESS);
}
int main(int argc, char **argv)
{
t_cub param;
param = (t_cub){0};
param.texture = (t_textures){0};
param.texture.play = (t_playa){0};
param.cur = (t_wall){0};
param.ture = (t_draw_tex){0};
if (argc >= 2)
{
if (check_args(argv[1]))
return (print_err_int("Error: Please provide a valid *.cub file."));
open_close_file(argv, ¶m.texture);
if (initialise_mlx(¶m))
return (print_err_int("Error: Failed to init MLX."));
mlx_loop_hook(param.mlx, &ft_draw_window, ¶m);
mlx_key_hook(param.mlx, &ft_hook, ¶m);
mlx_loop(param.mlx);
mlx_terminate(param.mlx);
free_map(¶m.texture);
}
else
return (print_err_int \
("Error: Please provide a *.cub file as the first argument."));
return (EXIT_SUCCESS);
}