wip calcul texture image x position, and add protection when creating texture

This commit is contained in:
hugogogo
2022-05-02 23:19:27 +02:00
parent 628a0c0cad
commit 75692c09a6
6 changed files with 116 additions and 34 deletions

View File

@@ -1,15 +1,34 @@
#include "cube3d.h"
static void init_txtr_img(t_img *img, void *mlx_ptr, char *path)
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)
{
init_txtr_img(&txt->img_n, mlx_ptr, txt->txt_north);
init_txtr_img(&txt->img_n, mlx_ptr, txt->txt_south);
init_txtr_img(&txt->img_n, mlx_ptr, txt->txt_east);
init_txtr_img(&txt->img_n, mlx_ptr, txt->txt_west);
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);
}
}