/* A CPU-rendered window. Build instructions: docs/getting-started.md. */ #include #include 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; }