diff --git a/Makefile b/Makefile index 34627ca..df469cc 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/11/11 17:18:13 by rparodi ### ########.fr # +# Updated: 2024/11/11 20:02:50 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -42,6 +42,7 @@ MLXFLAGS = -L$(MLX_DIR) -lmlx -L/opt/X11/lib -lX11 -lXext -lXrender -lXrandr -lX LDFLAGS += $(MLXFLAGS) SRC =\ + raycast/mlx_init.c \ parsing/arguments.c \ sources/cleanups.c \ sources/error.c \ diff --git a/includes/cub3d.h b/includes/cub3d.h index ae0b004..99509de 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */ -/* Updated: 2024/11/09 01:19:41 by bgoulard ### ########.fr */ +/* Updated: 2024/11/11 20:00:54 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ # include +int init_mlx_env(t_info *info); void cleanup_info(t_info *info); int c3_options(t_info *info, int argc, char *argv[]); void c3_perror(t_info *info); diff --git a/raycast/mlx_init.c b/raycast/mlx_init.c new file mode 100644 index 0000000..26486c5 --- /dev/null +++ b/raycast/mlx_init.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mlx_init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/11 19:53:42 by rparodi #+# #+# */ +/* Updated: 2024/11/11 20:11:11 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cub3d.h" +#include "cub3d_struct.h" +#include "mlx_functions.h" +#include "mlx_structs.h" +#include + +int _keyhook(int keycode, t_info *info) +{ + if (keycode == 53 || keycode == 65307) + return (cleanup_info(info), EXIT_SUCCESS); + return (0); +} + +int _redcross(t_info *info) +{ + return (cleanup_info(info), EXIT_SUCCESS); +} + +t_win_list *_init_mlx_window(t_info *info) +{ + int x; + int y; + + x = 0; + y = 0; + mlx_get_screen_size(info->mlx_ptr, &x, &y); + return (mlx_new_window(info->mlx_ptr, x, y, "Miaou")); +} + +int init_mlx_env(t_info *info) +{ + info->mlx_ptr = mlx_init(); + if (!info->mlx_ptr) + return (MLX_ERROR); + info->win_ptr = _init_mlx_window(info); + if (!info->win_ptr) + return (MLX_ERROR); + mlx_hook(info->win_ptr, 2, 1L << 0, _keyhook, info); + mlx_hook(info->win_ptr, 17, 1L << 17, _redcross, info); + mlx_loop(info->mlx_ptr); + return (NO_ERROR); +} diff --git a/sources/main.c b/sources/main.c index 0a6d618..a1dca47 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,12 +6,14 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */ -/* Updated: 2024/11/11 19:30:41 by rparodi ### ########.fr */ +/* Updated: 2024/11/11 20:01:31 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" #include "cub3d_struct.h" +#include "mlx_functions.h" +#include "mlx_structs.h" #include "ft_string.h" #include @@ -55,6 +57,7 @@ void run_cub3d(t_info *info) // - validity check // - mlx inits // - game loop + init_mlx_env(info); // - mlx cleanup (void)info; }