2025-05-05 17:09:11 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* main.c :+: :+: :+: */
|
|
|
|
|
/* +:+ +:+ +:+ */
|
2025-05-06 13:24:32 +02:00
|
|
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
2025-05-05 17:09:11 +02:00
|
|
|
/* +#+#+#+#+#+ +#+ */
|
2025-05-06 13:24:32 +02:00
|
|
|
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
2025-06-06 13:57:31 +02:00
|
|
|
/* Updated: 2025/06/06 13:12:28 by tchampio ### ########.fr */
|
2025-05-05 17:09:11 +02:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
2025-05-06 09:30:32 +02:00
|
|
|
#include "../includes/libft.h"
|
2025-06-06 13:57:31 +02:00
|
|
|
#include "../mlx/mlx.h"
|
2025-06-04 19:16:59 +02:00
|
|
|
#include "../includes/maputils.h"
|
2025-05-06 13:24:32 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
2025-05-06 09:30:32 +02:00
|
|
|
|
2025-05-06 12:25:17 +02:00
|
|
|
typedef struct s_mlx_data
|
|
|
|
|
{
|
|
|
|
|
void *img;
|
|
|
|
|
char *addr;
|
|
|
|
|
int bits_per_pixel;
|
|
|
|
|
int line_length;
|
|
|
|
|
int endian;
|
|
|
|
|
} t_mlx_data;
|
|
|
|
|
|
2025-05-06 13:24:32 +02:00
|
|
|
|
2025-05-06 12:25:17 +02:00
|
|
|
void my_mlx_pixel_put(t_mlx_data *data, int x, int y, int color)
|
|
|
|
|
{
|
|
|
|
|
char *dst;
|
|
|
|
|
|
|
|
|
|
dst = data->addr + (y * data->line_length + x * (data->bits_per_pixel / 8));
|
|
|
|
|
*(unsigned int*)dst = color;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-06 13:57:31 +02:00
|
|
|
int destroy(t_mapdata *map)
|
|
|
|
|
{
|
|
|
|
|
(void)map;
|
|
|
|
|
exit(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int key_destroy(int keycode, t_mapdata *map)
|
|
|
|
|
{
|
|
|
|
|
if (keycode == 65307)
|
|
|
|
|
destroy(map);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 17:09:11 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2025-05-06 12:25:17 +02:00
|
|
|
void *mlx;
|
|
|
|
|
void *mlx_win;
|
2025-06-04 21:50:33 +02:00
|
|
|
char *xpm = "./ressources/test.xpm";
|
|
|
|
|
void *xpm_image;
|
|
|
|
|
int xpm_height;
|
|
|
|
|
int xpm_width;
|
2025-05-06 12:25:17 +02:00
|
|
|
t_mlx_data data;
|
2025-05-06 13:24:32 +02:00
|
|
|
t_mapdata map;
|
2025-05-06 12:25:17 +02:00
|
|
|
|
2025-05-05 17:09:11 +02:00
|
|
|
if (argc < 2)
|
|
|
|
|
return (ft_printf("Error: Missing cub3d filename\n"), 1);
|
2025-05-06 13:24:32 +02:00
|
|
|
if (!check_cubfile(argv[1], &map))
|
|
|
|
|
return (ft_printf("Error: Wrong map file. Reason: %s\n", map.error), 1);
|
2025-05-06 12:25:17 +02:00
|
|
|
mlx = mlx_init();
|
|
|
|
|
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);
|
2025-06-04 21:50:33 +02:00
|
|
|
xpm_image = mlx_xpm_file_to_image(mlx, xpm, &xpm_width, &xpm_height);
|
|
|
|
|
//my_mlx_pixel_put(&data, 5, 5, 0x00FF0000);
|
2025-06-06 13:57:31 +02:00
|
|
|
mlx_hook(mlx_win, 17, 0L, destroy, &map);
|
|
|
|
|
mlx_key_hook(mlx_win, key_destroy, &map);
|
2025-05-06 12:25:17 +02:00
|
|
|
mlx_put_image_to_window(mlx, mlx_win, data.img, 0, 0);
|
2025-06-04 21:50:33 +02:00
|
|
|
mlx_put_image_to_window(mlx, mlx_win, xpm_image, 0, 0);
|
2025-05-06 12:25:17 +02:00
|
|
|
mlx_loop(mlx);
|
2025-05-05 17:09:11 +02:00
|
|
|
}
|