mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
feat: use t_img_data to store textures insted of void ptr
This allows for easier writing of future functions, see next pr comming soon
This commit is contained in:
parent
121db8bd3c
commit
c09ba88d90
3 changed files with 25 additions and 15 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
|
||||
/* Updated: 2025/07/31 14:17:28 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/08/05 13:09:22 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,10 +23,10 @@ typedef struct s_cub3d_data
|
|||
{
|
||||
void *mlx;
|
||||
void *mlx_win;
|
||||
void *no_texture;
|
||||
void *so_texture;
|
||||
void *we_texture;
|
||||
void *ea_texture;
|
||||
t_img_data *no_texture;
|
||||
t_img_data *so_texture;
|
||||
t_img_data *we_texture;
|
||||
t_img_data *ea_texture;
|
||||
t_img_data *img_data;
|
||||
t_mapdata *map;
|
||||
t_player player;
|
||||
|
|
|
|||
|
|
@ -67,13 +67,17 @@ int destroy(t_cub3d_data *data)
|
|||
mlx_destroy_image(data->mlx, data->img_data->img);
|
||||
free(data->img_data);
|
||||
if (data->no_texture)
|
||||
mlx_destroy_image(data->mlx, data->no_texture);
|
||||
mlx_destroy_image(data->mlx, data->no_texture->img);
|
||||
free(data->no_texture);
|
||||
if (data->so_texture)
|
||||
mlx_destroy_image(data->mlx, data->so_texture);
|
||||
mlx_destroy_image(data->mlx, data->so_texture->img);
|
||||
free(data->so_texture);
|
||||
if (data->ea_texture)
|
||||
mlx_destroy_image(data->mlx, data->ea_texture);
|
||||
mlx_destroy_image(data->mlx, data->ea_texture->img);
|
||||
free(data->ea_texture);
|
||||
if (data->we_texture)
|
||||
mlx_destroy_image(data->mlx, data->we_texture);
|
||||
mlx_destroy_image(data->mlx, data->we_texture->img);
|
||||
free(data->we_texture);
|
||||
if (data->mlx)
|
||||
mlx_destroy_display(data->mlx);
|
||||
free(data->mlx);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */
|
||||
/* Updated: 2025/07/31 14:27:12 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/08/05 13:19:40 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,11 +17,12 @@
|
|||
#include "../map/map_checker.h"
|
||||
#include "frees.h"
|
||||
|
||||
void *load_single_texture(t_cub3d_data *data, char *path)
|
||||
t_img_data *load_single_texture(t_cub3d_data *data, char *path)
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
void *img;
|
||||
t_img_data *img_data;
|
||||
|
||||
img = mlx_xpm_file_to_image(data->mlx, path, &width, &height);
|
||||
if (img == NULL)
|
||||
|
|
@ -35,7 +36,12 @@ void *load_single_texture(t_cub3d_data *data, char *path)
|
|||
destroy(data);
|
||||
}
|
||||
ft_printf("image: %p\n", img);
|
||||
return (img);
|
||||
img_data = ft_calloc(sizeof(t_img_data), 1);
|
||||
img_data->img = img;
|
||||
img_data->addr = mlx_get_data_addr(img_data->img,
|
||||
&img_data->bits_per_pixel, &img_data->line_length,
|
||||
&img_data->endian);
|
||||
return (img_data);
|
||||
}
|
||||
|
||||
void load_textures(t_cub3d_data *data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue