-
Notifications
You must be signed in to change notification settings - Fork 2
/
export.c
67 lines (62 loc) · 2.12 KB
/
export.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: snicolet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/07/21 19:01:04 by snicolet #+# #+# */
/* Updated: 2016/07/22 21:01:24 by snicolet ### ########.fr */
/* */
/* ************************************************************************** */
#include "arguments.h"
#include "parser.h"
#include "libft.h"
#include "sda.h"
#include <unistd.h>
int rt_export(t_rt *rt, int ac, char **av)
{
int fd;
const char *filepath = av[0];
const char *dest = av[1];
(void)ac;
rt->settings.fake_texture_load = 1;
if (!(rt->root = rt_parser(filepath, rt)))
{
ft_putendl_fd("error.", 2);
return (PARSE_ARG_ERROR);
}
fd = (dest) ? sda_export_file(dest) : 1;
if (fd < 0)
return (PARSE_ARG_ERROR);
sda_export(rt, fd);
if (fd != 1)
close(fd);
return (PARSE_ARG_STOPALL);
}
int rt_export_bmp(t_rt *rt, int ac, char **av)
{
const char *filepath = av[0];
const char *dest = av[1];
(void)ac;
ft_putendl("export bmp requested");
if (((rt->root = rt_parser(filepath, rt))) && (rt_checkcamera(rt)))
{
if (SDL_Init(0) < 0)
{
ft_putendl_fd("error: failed to init sdl", 2);
return (PARSE_ARG_ERROR);
}
rt->sys.screen = draw_make_surface(rt->sys.geometry);
draw_reset_surface(rt->sys.screen, COLOR_WHITE);
rt->settings.cfgbits |= RT_CFGB_FREESCREEN;
ft_putstr("rendering scene\n");
rt_render(rt);
ft_putstr("render done\n");
sda_export_bitmap_file(dest, rt->sys.screen);
return (PARSE_ARG_STOPALL);
}
else
ft_putstr_fd("error: failed to parse file.\n", 2);
return (PARSE_ARG_ERROR);
}