diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 16:25:52 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 16:25:52 +0300 |
| commit | 3c39c55676162f83ed2eaf2fee3ec41254abc638 (patch) | |
| tree | a0b90cea96459c6b03b85b9fbfeb2458e28782f6 /examples | |
| parent | ed963bba0b234d52fda14b2a8237dbf02ef4d655 (diff) | |
Fill the hello window with an RGB gradient
Red grows to the right, green downward, and blue fades as red grows.
Rows now step by the frame's stride_bytes instead of assuming packed
pixels.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/hello.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/examples/hello.c b/examples/hello.c index 38a0cac..4c171ec 100644 --- a/examples/hello.c +++ b/examples/hello.c @@ -6,9 +6,16 @@ static bool failed; static void draw(void *ud, struct yasl_surface *surface, struct yasl_frame_context *frame) { (void)ud; - size_t count = (size_t)frame->size.x * frame->size.y; - for (size_t i = 0; i < count; i++) - frame->cpu.pixels[i] = 0xff306090; /* Opaque premultiplied ARGB. */ + int w = frame->size.x, h = frame->size.y; + for (int y = 0; y < h; y++) { + uint32_t *row = frame->cpu.pixels + (size_t)y * (frame->cpu.stride_bytes / 4); + 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)); + row[x] = 0xff000000 | r << 16 | g << 8 | (255 - r); + } + } if (!yasl_frame_present_cpu(frame, NULL, 0)) { fprintf(stderr, "Could not present the draw target\n"); |
