# dxSetTexturePixels (Client)

> Writes pixels into a texture made by a script or into a render target.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Screen drawing
- **URL**: https://wiki.mymp.gg/en/dxSetTexturePixels

## Syntax

```lua
bool dxSetTexturePixels(texture texture, string pixels [, int x, y = 0, 0, int width, height = 0, 0])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `texture` | `texture` | A texture from `engineCreateTexture` or a render target. |
| `pixels` | `string` | The pixels in `plain`. |
| `x, y` | `int` | Top-left corner of the area written, in pixels. A vec2 also works. *(default: `0, 0`)* |
| `width, height` | `int` | Size of the area written. With a height of 0, the whole image is written. A vec2 also works. *(default: `0, 0`)* |

## Returns

`true` when the write was done or scheduled, `false` when the image holds no pixels (a screen source, dui or txd texture) or the pixels are not `plain`.

A leading number (MTA's surface index) is accepted and ignored. If the image is still loading, the write happens once it is ready. `plain` pixels are 4 bytes per pixel (blue, green, red, alpha), row by row, followed by the width and the height in 2 bytes each.

## Example

```lua
local tex = engineCreateTexture(64, 64)

dxGetTexturePixels(tex, function(pixels)
    if not pixels then return end
    for x = 0, 63 do
        dxSetPixelColor(pixels, x, 32, 255, 0, 0)
    end
    dxSetTexturePixels(tex, pixels)
end)
```

## See also

- [dxGetTexturePixels (Client)](https://wiki.mymp.gg/en/dxGetTexturePixels.md): Reads an image's pixels and hands them to a function, a few frames later.
- [dxSetPixelColor (Client)](https://wiki.mymp.gg/en/dxSetPixelColor.md): Changes the colour of one pixel of a plain image, in the string itself.
- [engineCreateTexture (Client)](https://wiki.mymp.gg/en/engineCreateTexture.md): Creates a texture from an image file in the resource or from image bytes in memory. The texture exists on this client only.
