feat: adding windows from mlx and close features

This commit is contained in:
Raphael 2024-11-11 20:11:47 +01:00
parent a0e6957d66
commit 09688e1c48
4 changed files with 62 additions and 3 deletions

View file

@ -6,7 +6,7 @@
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ # # By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 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) LDFLAGS += $(MLXFLAGS)
SRC =\ SRC =\
raycast/mlx_init.c \
parsing/arguments.c \ parsing/arguments.c \
sources/cleanups.c \ sources/cleanups.c \
sources/error.c \ sources/error.c \

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:30:26 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 <stdbool.h> # include <stdbool.h>
int init_mlx_env(t_info *info);
void cleanup_info(t_info *info); void cleanup_info(t_info *info);
int c3_options(t_info *info, int argc, char *argv[]); int c3_options(t_info *info, int argc, char *argv[]);
void c3_perror(t_info *info); void c3_perror(t_info *info);

54
raycast/mlx_init.c Normal file
View file

@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mlx_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
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);
}

View file

@ -6,12 +6,14 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:30:03 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.h"
#include "cub3d_struct.h" #include "cub3d_struct.h"
#include "mlx_functions.h"
#include "mlx_structs.h"
#include "ft_string.h" #include "ft_string.h"
#include <fcntl.h> #include <fcntl.h>
@ -55,6 +57,7 @@ void run_cub3d(t_info *info)
// - validity check // - validity check
// - mlx inits // - mlx inits
// - game loop // - game loop
init_mlx_env(info);
// - mlx cleanup // - mlx cleanup
(void)info; (void)info;
} }