cub3d/src/main.c
2025-06-04 18:28:06 +02:00

81 lines
2.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
/* Updated: 2025/05/06 13:16:18 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/libft.h"
#include "../includes/mlx.h"
//#include "../includes/filecheck.h"
#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
typedef struct s_mlx_data
{
void *img;
char *addr;
int bits_per_pixel;
int line_length;
int endian;
} t_mlx_data;
typedef struct s_mapdata
{
char *filename;
bool isvalid;
char error[1024];
} t_mapdata;
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;
}
bool check_filename(char *file)
{
(void)file;
return (false);
}
bool check_cubfile(char *file, t_mapdata *map)
{
int fd;
fd = open(file, O_RDONLY);
if (fd < 0)
return (ft_strlcpy(map->error, "Can't open file", 16), false);
if (!check_filename(file))
return (ft_strlcpy(map->error, "File is not a .cub file", 25), false);
close(fd);
return (true);
}
int main(int argc, char **argv)
{
void *mlx;
void *mlx_win;
t_mlx_data data;
t_mapdata map;
if (argc < 2)
return (ft_printf("Error: Missing cub3d filename\n"), 1);
if (!check_cubfile(argv[1], &map))
return (ft_printf("Error: Wrong map file. Reason: %s\n", map.error), 1);
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);
my_mlx_pixel_put(&data, 5, 5, 0x00FF0000);
mlx_put_image_to_window(mlx, mlx_win, data.img, 0, 0);
mlx_loop(mlx);
}