added texture "loading"

This commit is contained in:
Theo Champion 2025-06-04 21:50:33 +02:00
parent 935370ac63
commit 8eb1a4962c
5 changed files with 3671 additions and 5 deletions

View file

@ -3,9 +3,23 @@
# include <stdbool.h>
// TODO: mettre ca dans un autre fichier
# define RESET "\033[0m"
# define RED "\033[31m"
# define GREEN "\033[32m"
# define YELLOW "\033[33m"
# define BLUE "\033[34m"
# define MAGENTA "\033[35m"
# define CYAN "\033[36m"
# define BOLD "\033[1m"
typedef struct s_mapdata
{
char *filename;
char *NO_texture;
char *SO_texture;
char *WE_texture;
char *EA_texture;
bool isvalid;
char error[1024];
} t_mapdata;

3582
ressources/test.xpm Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
NO ./path_to_the_north_texture
SO ./path_to_the_south_texture
WE ./path_to_the_west_texture
EA ./path_to_the_east_texture
NO ./path_to_the_north_texture
SO ./path_to_the_south_texture
WE ./path_to_the_west_texture
EA ./path_to_the_east_texture
F 220,100,0
C 225,30,0

View file

@ -39,6 +39,10 @@ int main(int argc, char **argv)
{
void *mlx;
void *mlx_win;
char *xpm = "./ressources/test.xpm";
void *xpm_image;
int xpm_height;
int xpm_width;
t_mlx_data data;
t_mapdata map;
@ -50,7 +54,9 @@ int main(int argc, char **argv)
mlx_win = mlx_new_window(mlx, 800, 600, "Cub3d");
data.img = mlx_new_image(mlx, 800, 600);
data.addr = mlx_get_data_addr(data.img, &data.bits_per_pixel, &data.line_length, &data.endian);
my_mlx_pixel_put(&data, 5, 5, 0x00FF0000);
xpm_image = mlx_xpm_file_to_image(mlx, xpm, &xpm_width, &xpm_height);
//my_mlx_pixel_put(&data, 5, 5, 0x00FF0000);
mlx_put_image_to_window(mlx, mlx_win, data.img, 0, 0);
mlx_put_image_to_window(mlx, mlx_win, xpm_image, 0, 0);
mlx_loop(mlx);
}

View file

@ -3,6 +3,69 @@
#include <unistd.h>
#include "../../includes/libft.h"
void print_mapdata(const t_mapdata *data)
{
ft_printf(BOLD CYAN "=== Map Data ===\n" RESET);
ft_printf(BOLD "Filename: " RESET "%s\n", data->filename ? data->filename : "(null)");
ft_printf(BOLD "NO Texture: " RESET "%s\n", data->NO_texture ? data->NO_texture : "(null)");
ft_printf(BOLD "SO Texture: " RESET "%s\n", data->SO_texture ? data->SO_texture : "(null)");
ft_printf(BOLD "WE Texture: " RESET "%s\n", data->WE_texture ? data->WE_texture : "(null)");
ft_printf(BOLD "EA Texture: " RESET "%s\n", data->EA_texture ? data->EA_texture : "(null)");
ft_printf(BOLD "Validity: " RESET);
if (data->isvalid)
ft_printf(GREEN "VALID\n" RESET);
else
ft_printf(RED "INVALID\n" RESET);
if (!data->isvalid && data->error[0] != '\0')
{
ft_printf(BOLD RED "Error: " RESET "%s\n", data->error);
}
ft_printf(CYAN "=================\n" RESET);
}
bool set_textures(char *line, t_mapdata *map)
{
char **tab;
int i;
tab = ft_split(line, ' ');
i = 0;
if (tab[0] && tab[1])
{
if (!ft_strncmp(tab[0], "NO", 3) || !ft_strncmp(tab[0], "no", 3))
map->NO_texture = ft_strdup(tab[1]);
if (!ft_strncmp(tab[0], "SO", 3) || !ft_strncmp(tab[0], "so", 3))
map->SO_texture = ft_strdup(tab[1]);
if (!ft_strncmp(tab[0], "WE", 3) || !ft_strncmp(tab[0], "we", 3))
map->WE_texture = ft_strdup(tab[1]);
if (!ft_strncmp(tab[0], "EA", 3) || !ft_strncmp(tab[0], "ea", 3))
map->EA_texture = ft_strdup(tab[1]);
}
while (tab[i])
free(tab[i++]);
free(tab);
return (true);
}
bool add_textures(int fd, t_mapdata *map)
{
char *line;
line = get_next_line(fd);
while (line)
{
//ft_printf("%s", line);
set_textures(line, map);
free(line);
line = get_next_line(fd);
}
print_mapdata(map);
return (true);
}
bool check_filename(char *file)
{
int filename_size;
@ -35,6 +98,7 @@ bool check_cubfile(char *file, t_mapdata *map)
fd = open(file, O_RDONLY);
if (fd < 0)
return (ft_strlcpy(map->error, "Can't open file", 16), false);
add_textures(fd, map);
close(fd);
return (true);
}