-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
64 lines (57 loc) · 1.98 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mouaammo <mouaammo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/18 22:37:31 by mouaammo #+# #+# */
/* Updated: 2023/09/29 15:44:44 by mouaammo ### ########.fr */
/* */
/* ************************************************************************** */
#include "include/cub3d.h"
void error( char *str)
{
ft_putstr_fd(str, 2);
exit(1);
}
void get_imgs_data(t_cub3d *data)
{
int tmp;
if (data->img)
mlx_destroy_image(data->mlx, data->img);
mlx_clear_window(data->mlx, data->win);
data->img = mlx_new_image(data->mlx, WINDOW_WIDTH, WINDOW_HEIGHT);
data->frame = (unsigned int *)mlx_get_data_addr(data->img,
&tmp, &tmp, &tmp);
}
int render_img(t_cub3d *data)
{
get_imgs_data(data);
update_position_player(data);
render_rays(data);
render_textures(data);
mlx_put_image_to_window(data->mlx, data->win, data->img, 0, 0);
return (0);
}
int main(int argc, char **argv)
{
t_cub3d *data;
t_list *list;
data = malloc (sizeof (t_cub3d));
if (!data)
return (1);
data->img = NULL;
data->map_img = NULL;
list = parsing(argc, argv);
initialize_map(data, list);
mlx_hook(data->win, ON_KEYDOWN, 0, key_pressed, data);
mlx_hook(data->win, ON_KEYUP, 0, key_released, data);
mlx_hook(data->win, ON_DESTROY, 0, destroy_window, data);
get_textures(data);
mlx_loop_hook(data->mlx, render_img, data);
mlx_loop(data->mlx);
free_list(&list);
free_data(&data);
return (0);
}