Files
42_INT_04_fdf/srcs/fdf.c
2021-07-24 10:42:04 +02:00

86 lines
2.4 KiB
C

#include "fdf.h"
int shut_down(t_fdf *fdf)
{
while (fdf->map_height--)
free(fdf->map[fdf->map_height]);
free(fdf->map);
mlx_destroy_image(fdf->mlx_ptr, fdf->img_ptr);
mlx_destroy_window(fdf->mlx_ptr, fdf->win_ptr);
mlx_destroy_display(fdf->mlx_ptr);
free(fdf);
exit(0);
return (0);
}
t_fdf *init_fdf(t_fdf *fdf)
{
fdf->offset = 50;
fdf->margin = 50;
fdf->altitude = 3;
fdf->map_size_x = (fdf->map_width - 1) * fdf->offset + 1;
fdf->map_size_y = (fdf->map_height - 1) * fdf->offset + 1;
fdf->win_size_x = fdf->map_size_x + 2 * fdf->margin;
fdf->win_size_y = fdf->map_size_y + 2 * fdf->margin;
fdf->img_size_x = fdf->win_size_x;
fdf->img_size_y = fdf->win_size_y;
fdf->rot_x = -30;
fdf->rot_y = -45;
fdf->mov_x = 0;
fdf->mov_y = 0;
fdf->zoom = -5;
fdf->mlx_ptr = mlx_init();
fdf->win_ptr = mlx_new_window(fdf->mlx_ptr, fdf->win_size_x,
fdf->win_size_y, "test");
fdf->img_ptr = mlx_new_image(fdf->mlx_ptr, fdf->img_size_x,
fdf->img_size_y);
fdf->img_addr = mlx_get_data_addr(fdf->img_ptr, &(fdf->img_bpp),
&(fdf->img_sizel), &(fdf->img_endian));
draw_image(fdf);
return (fdf);
}
int main(int ac, char **av)
{
t_fdf *fdf;
if (ac != 1)
return (0);
fdf = malloc(sizeof(t_fdf));
fdf->map = parse_map(fdf, av);
fdf = init_fdf(fdf);
mlx_hook(fdf->win_ptr, 2, 1L << 0, keypress, fdf);
mlx_hook(fdf->win_ptr, 17, 1L << 17, shut_down, fdf);
mlx_loop(fdf->mlx_ptr);
return (0);
}
/*
** x_event | x_mask | action
** 2 | 1L << 0 | key press
** 3 | 1L << 1 | key release
** 4 | | mouse press
** 5 | | mouse release
** 6 | | mouse move
** 12 | | expose event
** 17 | 1L << 17 | x button press (red button)
** | |
**
** . math lib :
** -lm // needed at compilation to link the lib :
** gcc foo.c -o foo -lm
** . minilibx :
** minilibx_opengl.tgz
** minilibx_mms_20200219_beta.tgz
** // to open an archive.tgz :
** gzip -d archive.tgz --> turn it into archive.tar
** tar -xf archive.tar --> un-archive it
** // how to add a man directory to the manual :
** . cp man/man1 /usr/local/share/man/man1
** (create man1 if necessary)
** . mandb
** // i didn't use any of both library above but the one for linux :
** https://github.com/42Paris/minilibx-linux
** there are pbm with their man pages
*/