-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
68 lines (61 loc) · 1.95 KB
/
main.c
File metadata and controls
68 lines (61 loc) · 1.95 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ubuntuser <ubuntuser@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/20 10:00:00 by smetola #+# #+# */
/* Updated: 2025/12/05 23:54:28 by ubuntuser ### ########.fr */
/* */
/* ************************************************************************** */
#include "miniRT.h"
static void ft_hook(void *param)
{
mlx_t *mlx;
mlx = param;
if (mlx_is_key_down(mlx, MLX_KEY_ESCAPE))
mlx_close_window(mlx);
}
static mlx_t *init_mlx_window(mlx_image_t **g_image)
{
mlx_t *mlx;
mlx = mlx_init(WIDTH, HEIGHT, "miniRT", true);
if (!mlx)
{
puts(mlx_strerror(mlx_errno));
return (NULL);
}
*g_image = mlx_new_image(mlx, WIDTH, HEIGHT);
if (!*g_image)
{
mlx_close_window(mlx);
puts(mlx_strerror(mlx_errno));
return (NULL);
}
if (mlx_image_to_window(mlx, *g_image, 0, 0) == -1)
{
mlx_close_window(mlx);
puts(mlx_strerror(mlx_errno));
return (NULL);
}
return (mlx);
}
int32_t main(int argc, char **argv)
{
mlx_t *mlx;
mlx_image_t *g_image;
t_scene scene;
init_scene(&scene);
if (!check_args(argc, argv[1]) || !parse_rt_file(argv[1], &scene))
return (free_scene(&scene), EXIT_FAILURE);
mlx = init_mlx_window(&g_image);
if (!mlx)
return (free_scene(&scene), EXIT_FAILURE);
mlx_loop_hook(mlx, ft_hook, mlx);
render_scene(scene, g_image);
mlx_loop(mlx);
mlx_terminate(mlx);
free_scene(&scene);
return (EXIT_SUCCESS);
}