/
main.c
87 lines (78 loc) · 2.18 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmartin <mmartin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/02/10 13:52:27 by mmartin #+# #+# */
/* Updated: 2014/03/24 19:39:38 by mmartin ### ########.fr */
/* */
/* ************************************************************************** */
#include <mlx.h>
#include <stdlib.h>
#include <libft.h>
#include "ft_rt.h"
static int ft_key_hook(int keycode, t_data *d)
{
if (keycode == 65307)
{
mlx_destroy_image(d->mlx, d->img);
mlx_destroy_window(d->mlx, d->win);
ft_destroy_data(d);
exit(EXIT_SUCCESS);
}
return (1);
}
static int ft_expose_hook(t_data *d)
{
mlx_put_image_to_window(d->mlx, d->win, d->img, 0, 0);
return (1);
}
static void ft_get_data(t_data *d)
{
int bpp;
int sizeline;
int endian;
d->data = mlx_get_data_addr(d->img, &bpp, &sizeline, &endian);
d->bpp = bpp;
d->sizeline = sizeline;
d->endian = endian;
}
static void ft_free_file(t_file *tmp)
{
t_file *ptr;
while (tmp)
{
ptr = tmp;
tmp = tmp->next;
free(ptr->line);
free(ptr);
}
}
int main(int argc, char **argv)
{
t_data d;
t_file *file;
t_file *tmp;
file = NULL;
if (argc != 2)
ft_putendl_fd("Usage: ./rt scene", 2);
else
{
tmp = ft_init(&file, &d, argv[1]);
ft_parsing(file, &d);
ft_get_light(file, &d);
if ((d.mlx = mlx_init()) == NULL)
return (-1);
d.win = mlx_new_window(d.mlx, d.width, d.height, "RT");
d.img = mlx_new_image(d.mlx, d.width, d.height);
ft_get_data(&d);
ft_free_file(tmp);
ft_raytracing(&d);
mlx_key_hook(d.win, &ft_key_hook, &d);
mlx_expose_hook(d.win, &ft_expose_hook, &d);
mlx_loop(d.mlx);
}
return (0);
}