blob: 9e324a6f84788e2a3a35c03dcc8e1e2ef0ba64c4 (
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
|
/* A CPU-rendered window. Build instructions: docs/getting-started.md. */
#include <yasl/yasl.h>
#include <yasl/cpu.h>
int main(void)
{
yasl_surface *surface = yasl_surface_create("Hello YASL", 640, 480, YASL_SURFACE_CPU);
yasl_event event;
while (surface && yasl_wait_event(&event, -1) >= 0 &&
event.type != YASL_EVENT_CLOSE && event.type != YASL_EVENT_QUIT) {
if (event.type != YASL_EVENT_REFRESH) continue;
int w, h;
uint32_t *pixels = yasl_cpu_pixels(surface, &w, &h);
for (int y = 0; pixels && y < h; y++) {
for (int x = 0; x < w; x++) {
/* Red grows rightward, green downward, blue fades; opaque premultiplied ARGB. */
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);
}
yasl_shutdown();
return surface ? 0 : 1;
}
|