-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
99 lines (88 loc) · 2.45 KB
/
main.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
95
96
97
98
99
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oal-tena <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/09 09:49:20 by oal-tena #+# #+# */
/* Updated: 2022/08/09 15:27:25 by oal-tena ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../include/mlx_example.h"
#define WIDTH 800
#define HEIGHT 600
typedef struct s_line
{
int x0;
int y0;
int x1;
int y1;
int x2;
int y2;
} t_line;
typedef struct s_windows
{
void *mlx;
void *win;
void *img;
int *data;
int bpp;
int size_line;
int endian;
} t_windows;
void init_window(t_windows *window)
{
window->mlx = mlx_init();
window->win = mlx_new_window(window->mlx, WIDTH, HEIGHT, "mlx_ex01");
window->img = mlx_new_image(window->mlx, WIDTH, HEIGHT);
window->data = (int *)mlx_get_data_addr(window->img, &window->bpp,
&window->size_line, &window->endian);
}
void init_line(t_line *line)
{
line->x0 = 600;
line->y0 = 0;
line->x1 = 0;
line->y1 = 0;
line->x2 = 300;
line->y2 = 300;
}
//exmaple put by pixel
void draw_line_by_pixel(t_windows *window, t_line *line)
{
while (line->y1 < line->y2)
{
window->data[(line->y1 * WIDTH) + line->x1] = 0xDD9933;
line->y1++;
line->x1++;
}
}
//exmple of put per pixel
void draw_line_per_pxel(t_windows *window, t_line *line)
{
char *pixel;
while (line->y0 < line->y2)
{
pixel = (char *)window->data + (line->y0 * window->size_line) + (line->x0
* 4);
pixel[0] = 0xFF;
pixel[1] = 0xFF >> 8;
pixel[2] = 0xFF >> 16;
line->y0++;
line->x0--;
}
}
int main(void)
{
t_windows *window;
t_line *line;
window = (t_windows *)malloc(sizeof(t_windows));
line = (t_line *)malloc(sizeof(t_line));
init_window(window);
init_line(line);
draw_line_by_pixel(window, line);
draw_line_per_pxel(window, line);
mlx_put_image_to_window(window->mlx, window->win, window->img, 0, 0);
mlx_loop(window->mlx);
}