-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminiRT.c
More file actions
81 lines (74 loc) · 2.43 KB
/
miniRT.c
File metadata and controls
81 lines (74 loc) · 2.43 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* miniRT.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenamar <abenamar@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/28 18:09:55 by abenamar #+# #+# */
/* Updated: 2024/04/24 14:14:48 by abenamar ### ########.fr */
/* */
/* ************************************************************************** */
#include "miniRT.h"
static bool ft_program_isvalid(char const *filename)
{
int const inum[] = {_WIDTH, _HEIGHT, _SAMPLES_PER_PIXEL};
float const fnum = _SHADOW_BIAS;
char const *const extension = ft_strrchr(filename, '.');
if (inum[0] <= 0)
return (ft_pstderr(__ERR_01), false);
if (inum[1] <= 0)
return (ft_pstderr(__ERR_02), false);
if (inum[2] <= 0)
return (ft_pstderr(__ERR_03), false);
if (signbit(fnum))
return (ft_pstderr(__ERR_04), false);
if (!extension || ft_strncmp(extension, ".rt", 4))
return (ft_pstderr(__ERR_05), false);
return (true);
}
static int ft_frame_render(t_xclient *const xclient)
{
int i;
int j;
if (xclient->update)
{
j = 0;
while (j < _HEIGHT)
{
i = 0;
while (i < _WIDTH)
{
ft_pixel_put(xclient, i, j, \
ft_ray_tracing(xclient->scene, i, j));
++i;
}
++j;
}
mlx_put_image_to_window(xclient->mlx, xclient->win, xclient->img, 0, 0);
xclient->update = false;
}
return (EXIT_SUCCESS);
}
int main(int ac, char **av)
{
t_scene *scene;
t_xclient *xclient;
if (ac < 2)
return (ft_pstderr(__USAGE), 2);
if (!ft_program_isvalid(av[1]))
return (EXIT_FAILURE);
scene = ft_scene_new(av[1]);
if (!scene)
return (EXIT_FAILURE);
xclient = ft_xclient_new(scene);
if (!xclient)
return (EXIT_FAILURE);
mlx_hook(xclient->win, \
DestroyNotify, ButtonReleaseMask, mlx_loop_end, xclient->mlx);
mlx_hook(xclient->win, KeyPress, KeyPressMask, ft_key_press, xclient);
mlx_loop_hook(xclient->mlx, ft_frame_render, xclient);
mlx_loop(xclient->mlx);
ft_xclient_free(xclient);
return (EXIT_SUCCESS);
}