# dxCreateRenderTarget (Client)

> Creates a render target: an image the `dx` functions can draw into and that can be used like any other image.

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

## Syntax

```lua
texture|false dxCreateRenderTarget(int width, height [, bool|string withAlpha = false])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `width, height` | `int` | Size in pixels, from 1 to 16384. A vec2 also works. |
| `withAlpha` | `bool\|string` | Keep the alpha channel. Also takes the name of an MTA surface format (`a8r8g8b8`, `x8r8g8b8`, `r5g6b5`...): those with `a` keep alpha, the others do not. *(default: `false`)* |

## Returns

The render target, or `false` when the size is outside 1 to 16384, there is no free video memory or the format is not supported.

## Example

```lua
local canvas = dxCreateRenderTarget(256, 64, true)

addEventHandler("onClientRender", root, function()
    dxSetRenderTarget(canvas, true)
    dxDrawText("Placar: 3 x 1", 0, 0, 256, 64, tocolor(255, 255, 255), 2, "default", "center", "center")
    dxSetRenderTarget()
    dxDrawImage(20, 20, 256, 64, canvas)
end)
```

### Note

A format name MYMP does not know (such as the depth formats) logs a warning and returns `false`.

## See also

- [dxSetRenderTarget (Client)](https://wiki.mymp.gg/en/dxSetRenderTarget.md): Chooses where the next dx functions draw: into a render target or, without one, on the screen.
- [dxDrawImage (Client)](https://wiki.mymp.gg/en/dxDrawImage.md): Draws an image on the screen for one frame.
- [engineSetWorldTexture (Client)](https://wiki.mymp.gg/en/engineSetWorldTexture.md): Swaps a texture on every model of the chosen kinds that uses it. Only the models' materials change, not the txd the texture comes from.
- [destroyElement (Shared)](https://wiki.mymp.gg/en/destroyElement.md): Destroys an element and all of its children. Before it goes, each one fires onElementDestroy on the server or onClientElementDestroy on the client.
