# C API: Overlays

A picture the host draws on the CPU, blended over the frame by the renderer: [Overlays](../../guides/overlay.md).

## sona_renderer_overlay

```c
sona_result sona_renderer_overlay(sona_renderer *r, const sona_overlay *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `o` | `const sona_overlay *` | A [`sona_overlay`](../fields.md#sona_overlay) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](../../troubleshooting.md#error-codes)).

**Example** (also in [Overlays: a picture over the frame](../../guides/overlay.md)):

```c
sona_overlay o;
memset(&o, 0, sizeof o);
o.size = sizeof o;
o.width = hud_w;
o.height = hud_h;
o.rgba = hud_pixels;          /* straight RGBA8, row 0 at the top; read during the call only */
o.revision = hud_revision;    /* the same as the last call's: nothing is uploaded */
o.dirty[0] = x; o.dirty[1] = y; o.dirty[2] = w; o.dirty[3] = h;   /* what changed; w 0: all of it */
/* o.rect: where it lands in the target, pixels from the top left; w 0: the whole target */
sona_renderer_overlay(renderer, &o);
sona_draw(renderer, &view, &target, &opts);   /* the avatars, the credit, then the overlay */
sona_renderer_overlay(renderer, NULL);        /* the next draws have none (the texture is kept) */
```

Sets r's overlay for every `sona_draw` that follows, until the next call. o NULL takes it away (its texture is kept for the next one of the same size). After `sona_renderer_reset` or a lost device, set it again. `SONA_E_ARGUMENT` for a bad size or stride, a dirty rectangle outside the picture, or no rgba; `SONA_E_LIMIT` past the largest texture.

## sona_renderer_underlay

```c
sona_result sona_renderer_underlay(sona_renderer *r, const sona_overlay *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `o` | `const sona_overlay *` | A [`sona_overlay`](../fields.md#sona_overlay) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_UNSUPPORTED`, `SONA_E_LIMIT`, `SONA_E_MEMORY`, `SONA_E_CONTEXT` ([what each means](../../troubleshooting.md#error-codes)).

**Example**:

```c
sona_overlay x_overlay;
memset(&x_overlay, 0, sizeof x_overlay);
x_overlay.size = sizeof x_overlay;
sona_result result = sona_renderer_underlay(r, &x_overlay);
if (result != SONA_OK) printf("sona_renderer_underlay: %s\n", sona_result_name(result));
```

A picture behind the avatars, as a page's backdrop behind a clear canvas: drawn first in the main pass at o->rect (w or h 0: the whole target), for every `sona_draw` and `sona_snapshot` until the next call; NULL takes it away. The frame's bloom runs over it as over the avatars. The editor draws 360sona.com's stage gradient this way. GL and Vulkan have it; on the other backends it returns `SONA_E_UNSUPPORTED` and the frame's clear shows.
