blob: d17dd39f01f752296ade89f5d045f63f1a5d73ef (
plain)
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
|
/* A CPU-rendered window. */
#include <yasl/yasl.h>
int main(void)
{
yasl_surface *surface = yasl_surface_create(
&(struct yasl_surface_options){.title = "Hello YASL", .width = 640, .height = 480});
if (!surface)
return 1;
yasl_event event;
while (yasl_wait_event(&event, -1) >= 0) {
if (event.type == YASL_EVENT_CLOSE || event.type == YASL_EVENT_QUIT)
break;
if (event.type != YASL_EVENT_REFRESH)
continue;
int w, h;
uint32_t *pixels = yasl_cpu_pixels(surface, &w, &h);
if (!pixels)
break;
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++) {
/* Opaque premultiplied ARGB: red grows rightward, green downward. */
uint32_t r = (uint32_t)(x * 255 / (w > 1 ? w - 1 : 1));
uint32_t g = (uint32_t)(y * 255 / (h > 1 ? h - 1 : 1));
pixels[(size_t)y * w + x] = 0xff000000 | r << 16 | g << 8 | (255 - r);
}
yasl_cpu_present(surface);
}
return yasl_shutdown() < 0;
}
|