-
Notifications
You must be signed in to change notification settings - Fork 0
/
textures.c
53 lines (49 loc) · 1.78 KB
/
textures.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* textures.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmacmaho <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/23 23:48:41 by nmaliare #+# #+# */
/* Updated: 2023/07/08 15:48:05 by bmacmaho ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int load_texture(mlx_t *mlx, mlx_image_t **img, char *file)
{
xpm_t *texture;
texture = mlx_load_xpm42(file);
if (!texture)
{
perror("Error");
return (0);
}
*img = mlx_texture_to_image(mlx, &(texture->texture));
mlx_delete_xpm42(texture);
return (1);
}
int prepare_textures(t_cub *cub)
{
if (!load_texture(cub->mlx, &(cub->map.north), cub->map.no))
return (0);
if (!load_texture(cub->mlx, &(cub->map.south), cub->map.so))
{
mlx_delete_image(cub->mlx, cub->map.north);
return (0);
}
if (!load_texture(cub->mlx, &(cub->map.east), cub->map.ea))
{
mlx_delete_image(cub->mlx, cub->map.north);
mlx_delete_image(cub->mlx, cub->map.south);
return (0);
}
if (!load_texture(cub->mlx, &(cub->map.west), cub->map.we))
{
mlx_delete_image(cub->mlx, cub->map.north);
mlx_delete_image(cub->mlx, cub->map.south);
mlx_delete_image(cub->mlx, cub->map.east);
return (0);
}
return (1);
}