35 lines
1.1 KiB
C
35 lines
1.1 KiB
C
#include "cube3d.h"
|
|
|
|
static int init_txtr_img(t_img *img, void *mlx_ptr, char *path)
|
|
{
|
|
img->ptr = mlx_xpm_file_to_image(mlx_ptr, path, &img->width, &img->height);
|
|
if (img->ptr == NULL)
|
|
return (1);
|
|
img->data = mlx_get_data_addr(img->ptr, &img->bpp, &img->szl, &img->ndn);
|
|
return (0);
|
|
}
|
|
|
|
void init_txtr(t_txt *txt, void *mlx_ptr)
|
|
{
|
|
if (init_txtr_img(&txt->img_n, mlx_ptr, txt->txt_north) == 1)
|
|
mb_exit("failed to read image for texture nord", EXIT_FAILURE);
|
|
if (init_txtr_img(&txt->img_s, mlx_ptr, txt->txt_south) == 1)
|
|
{
|
|
mlx_destroy_image(mlx_ptr, txt->img_n.ptr);
|
|
mb_exit("failed to read image for texture south", EXIT_FAILURE);
|
|
}
|
|
if (init_txtr_img(&txt->img_e, mlx_ptr, txt->txt_east) == 1)
|
|
{
|
|
mlx_destroy_image(mlx_ptr, txt->img_n.ptr);
|
|
mlx_destroy_image(mlx_ptr, txt->img_s.ptr);
|
|
mb_exit("failed to read image for texture east", EXIT_FAILURE);
|
|
}
|
|
if (init_txtr_img(&txt->img_w, mlx_ptr, txt->txt_west) == 1)
|
|
{
|
|
mlx_destroy_image(mlx_ptr, txt->img_n.ptr);
|
|
mlx_destroy_image(mlx_ptr, txt->img_s.ptr);
|
|
mlx_destroy_image(mlx_ptr, txt->img_e.ptr);
|
|
mb_exit("failed to read image for texture west", EXIT_FAILURE);
|
|
}
|
|
}
|