mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
115 lines
4.8 KiB
C
115 lines
4.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* load_texture.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/09/03 17:02:08 by tchampio #+# #+# */
|
|
/* Updated: 2025/09/22 17:17:34 by tchampio ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../../libft/includes/libft.h"
|
|
#include "../cub3d_data.h"
|
|
#include "../utils/frees.h"
|
|
#include "../utils/inits.h"
|
|
#include "../../mlx/mlx.h"
|
|
|
|
t_img_data *load_hud_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)
|
|
{
|
|
ft_printf("Error: failed to open image at %s\n", path);
|
|
destroy(data, 1);
|
|
}
|
|
ft_printf("image: %p\n", 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);
|
|
img_data->height = height;
|
|
img_data->width = width;
|
|
return (img_data);
|
|
}
|
|
|
|
void load_points_textures(t_cub3d_data *data)
|
|
{
|
|
data->point_figures[0] = load_hud_texture(data, "ressources/zero.xpm");
|
|
data->point_figures[1] = load_hud_texture(data, "ressources/one.xpm");
|
|
data->point_figures[2] = load_hud_texture(data, "ressources/two.xpm");
|
|
data->point_figures[3] = load_hud_texture(data, "ressources/three.xpm");
|
|
data->point_figures[4] = load_hud_texture(data, "ressources/four.xpm");
|
|
data->point_figures[5] = load_hud_texture(data, "ressources/five.xpm");
|
|
data->point_figures[6] = load_hud_texture(data, "ressources/six.xpm");
|
|
data->point_figures[7] = load_hud_texture(data, "ressources/seven.xpm");
|
|
data->point_figures[8] = load_hud_texture(data, "ressources/eight.xpm");
|
|
data->point_figures[9] = load_hud_texture(data, "ressources/nine.xpm");
|
|
}
|
|
|
|
void load_perk_logos(t_cub3d_data *data)
|
|
{
|
|
data->perk_logos[0] = load_hud_texture(data,
|
|
"ressources/juggernog_logo.xpm");
|
|
data->perk_logos[1] = load_hud_texture(data,
|
|
"ressources/revive_logo.xpm");
|
|
data->perk_logos[2] = load_hud_texture(data,
|
|
"ressources/doubletap_logo.xpm");
|
|
}
|
|
|
|
void load_round_indicators(t_cub3d_data *data)
|
|
{
|
|
data->tally_marks[4] = load_hud_texture(data, "ressources/tally_five.xpm");
|
|
data->tally_marks[3] = load_hud_texture(data, "ressources/tally_four.xpm");
|
|
data->tally_marks[2] = load_hud_texture(data, "ressources/tally_three.xpm");
|
|
data->tally_marks[1] = load_hud_texture(data, "ressources/tally_two.xpm");
|
|
data->tally_marks[0] = load_hud_texture(data, "ressources/tally_one.xpm");
|
|
data->round_figures[0] = load_hud_texture(data,
|
|
"ressources/round_zero.xpm");
|
|
data->round_figures[1] = load_hud_texture(data, "ressources/round_one.xpm");
|
|
data->round_figures[2] = load_hud_texture(data, "ressources/round_two.xpm");
|
|
data->round_figures[3] = load_hud_texture(data,
|
|
"ressources/round_three.xpm");
|
|
data->round_figures[4] = load_hud_texture(data,
|
|
"ressources/round_four.xpm");
|
|
data->round_figures[5] = load_hud_texture(data,
|
|
"ressources/round_five.xpm");
|
|
data->round_figures[6] = load_hud_texture(data,
|
|
"ressources/round_six.xpm");
|
|
data->round_figures[7] = load_hud_texture(data,
|
|
"ressources/round_seven.xpm");
|
|
data->round_figures[8] = load_hud_texture(data,
|
|
"ressources/round_eight.xpm");
|
|
data->round_figures[9] = load_hud_texture(data,
|
|
"ressources/round_nine.xpm");
|
|
}
|
|
|
|
void load_textures(t_cub3d_data *data)
|
|
{
|
|
data->no_texture = load_single_texture(data, data->map->no_texture);
|
|
data->so_texture = load_single_texture(data, data->map->so_texture);
|
|
data->we_texture = load_single_texture(data, data->map->we_texture);
|
|
data->ea_texture = load_single_texture(data, data->map->ea_texture);
|
|
data->barricades_texture[0] = load_single_texture(data,
|
|
"ressources/barricades_2.xpm");
|
|
data->barricades_texture[1] = load_single_texture(data,
|
|
"ressources/barricades_3.xpm");
|
|
data->barricades_texture[2] = load_single_texture(data,
|
|
"ressources/barricades_4.xpm");
|
|
data->barricades_texture[3] = load_single_texture(data,
|
|
"ressources/barricades_5.xpm");
|
|
data->barricades_texture[4] = load_single_texture(data,
|
|
"ressources/barricades_6.xpm");
|
|
data->barricades_texture[5] = load_single_texture(data,
|
|
"ressources/barricades_7.xpm");
|
|
load_points_textures(data);
|
|
load_perk_logos(data);
|
|
load_round_indicators(data);
|
|
}
|