-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.c
60 lines (55 loc) · 1.71 KB
/
render.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmomeni <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/19 20:39:12 by mmomeni #+# #+# */
/* Updated: 2023/07/09 20:00:02 by mmomeni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static void render_map(t_ctx *ctx)
{
size_t i;
size_t j;
size_t prev_j;
apply_factors(ctx);
i = 0;
prev_j = 0;
while (ctx->map->points[i])
{
j = 0;
while (!ctx->map->points[i][j].eol)
{
if (i != 0 && j < prev_j)
draw_line(ctx, ctx->map->points[i][j],
ctx->map->points[i - 1][j]);
if (j != 0)
draw_line(ctx, ctx->map->points[i][j],
ctx->map->points[i][j - 1]);
j++;
}
prev_j = j;
i++;
}
}
void render(t_ctx *ctx)
{
size_t i;
size_t j;
if (ctx->img)
mlx_delete_image(ctx->mlx, ctx->img);
ctx->img = mlx_new_image(ctx->mlx, ctx->meta->w_width, ctx->meta->w_height);
j = 0;
while (j < ctx->meta->w_height)
{
i = 0;
while (i < ctx->meta->w_width)
mlx_put_pixel(ctx->img, i++, j, ctx->meta->bg_color);
j++;
}
render_map(ctx);
mlx_image_to_window(ctx->mlx, ctx->img, 0, 0);
}