-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmlx_things.c
94 lines (86 loc) · 2.74 KB
/
mlx_things.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mlx_things.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mghalmi <mghalmi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/28 10:46:41 by mghalmi #+# #+# */
/* Updated: 2024/01/28 10:48:22 by mghalmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "main.h"
void init_mlx(t_mlx *mlx, t_scene *data)
{
t_cam *cam_begin;
mlx->mlx = mlx_init();
cam_begin = mlx->cam;
mlx->begin = mlx->cam;
while (mlx->cam)
{
mlx->cam->img_ptr = mlx_new_image(mlx->mlx, data->xres, data->yres);
mlx->cam->px_img = (int *)mlx_get_data_addr(mlx->cam->img_ptr, \
&mlx->cam->bits_per_pixel, &mlx->cam->size_line, &mlx->cam->endian);
mlx->cam = mlx->cam->next;
}
mlx->cam = cam_begin;
}
void message_prompt(int ac)
{
int t;
t = NUM_THREADS;
if (ac == 2)
{
if (NUM_THREADS == 1)
printf(GREEN_COLOR "\nScene successfully rendered with 1 thread, " \
RESET_COLOR);
else
printf(GREEN_COLOR \
"\nScene successfully rendered with %d threads, " \
RESET_COLOR, t);
printf("press ESC at any momnet to close the program.\n");
printf("If the scene has several cameras, ");
printf("press space to change between them\n\n");
}
else
{
printf(GREEN_COLOR "\nScene successfully saved to BMP\n" RESET_COLOR);
printf("The file has been saved into the \"images\" directory\n\n");
exit(EXIT_SUCCESS);
}
}
int next_cam(int keycode, t_mlx *mlx)
{
if (keycode == ESC_KEY)
exit(0);
if (keycode != SP_KEY)
return (0);
if (mlx->cam->next)
{
mlx->cam = mlx->cam->next;
mlx_put_image_to_window(\
mlx->mlx, mlx->win, mlx->cam->img_ptr, 0, 0);
}
else
{
mlx->cam = mlx->begin;
mlx_put_image_to_window(\
mlx->mlx, mlx->win, mlx->cam->img_ptr, 0, 0);
}
return (1);
}
int close_program(void *param)
{
param = (void *)param;
exit(EXIT_SUCCESS);
return (1);
}
void graphic_loop(t_mlx mlx, t_scene data)
{
mlx.win = mlx_new_window(mlx.mlx, data.xres, data.yres, \
"miniRT");
mlx_put_image_to_window(mlx.mlx, mlx.win, mlx.cam->img_ptr, 0, 0);
mlx_hook(mlx.win, DESTROYNOTIFY, STRUCTURENOTIFYMASK, close_program, 0);
mlx_hook(mlx.win, KEYPRESS, KEYPRESSMASK, next_cam, &mlx);
mlx_loop(mlx.mlx);
}