-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.c
62 lines (51 loc) · 1.67 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
// Compilation command:
// cc main.c -o example.out
#include <stdio.h>
#define SILK_PIXELBUFFER_WIDTH 800
#define SILK_PIXELBUFFER_HEIGHT 600
#define SILK_IMPLEMENTATION
#include "../../silk.h"
int main(int argc, const string argv[]) {
pixel buffer[SILK_PIXELBUFFER_WIDTH * SILK_PIXELBUFFER_HEIGHT];
i32 rotation = 45;
const string text = "Hello, PPM!";
const i32 text_size = 4;
const i32 text_spacing = 1;
silkClearPixelBufferColor(buffer, 0xffffffff);
silkDrawRectPro(
buffer,
(vec2i) { SILK_PIXELBUFFER_WIDTH, SILK_PIXELBUFFER_HEIGHT },
SILK_PIXELBUFFER_WIDTH,
(vec2i) {
SILK_PIXELBUFFER_CENTER_X,
SILK_PIXELBUFFER_CENTER_Y
},
(vec2i) {
SILK_PIXELBUFFER_CENTER_Y / 2,
SILK_PIXELBUFFER_CENTER_Y / 2
},
rotation,
(vec2i) {
SILK_PIXELBUFFER_CENTER_Y / 4,
SILK_PIXELBUFFER_CENTER_Y / 4
},
0xff0000ff
);
silkDrawTextDefault(
buffer,
(vec2i) { SILK_PIXELBUFFER_WIDTH, SILK_PIXELBUFFER_HEIGHT },
SILK_PIXELBUFFER_WIDTH,
text,
(vec2i) {
SILK_PIXELBUFFER_CENTER_X - silkMeasureText(text, text_size, text_spacing).x / 2,
SILK_PIXELBUFFER_CENTER_Y - silkMeasureText(text, text_size, text_spacing).y / 2 + SILK_PIXELBUFFER_CENTER_Y / 2
},
text_size,
text_spacing,
0xff000000
);
image canvas_image = silkBufferToImage(buffer, (vec2i) { SILK_PIXELBUFFER_WIDTH, SILK_PIXELBUFFER_HEIGHT });
silkSaveImage("output.ppm", &canvas_image);
silkUnloadBuffer(canvas_image.data);
return 0;
}