dxSetRenderTarget | Multi Theft Auto: Wiki Skip to content

dxSetRenderTarget

Client-side
Server-side
Shared

This function changes the drawing destination for the dx functions. It can be used to select a previously created render target, or if called with no arguments, restore drawing directly to the screen.

Note
  • Items drawn with postGUI set to true will not appear on a custom render target.
  • dxSetRenderTarget can be set at any time as long as <min_mta_version> in meta.xml is set to at least 1.3.0-9.04431 e.g. <min_mta_version client="1.3.0-9.04431" />.

OOP Syntax Help! I don't understand this!

Syntax

bool dxSetRenderTarget ( ​dx-rendertarget renderTarget, [ ​bool clear = false ] )
Required Arguments
  • renderTarget: The render target element whose pixels we want to draw on.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • clear (default: false): If set to true, the render target will also be cleared.

Returns

  • bool: result

Returns true if the render target was successfully changed, false otherwise.

Code Examples

client
local myRenderTarget
addEventHandler("onClientResourceStart", resourceRoot, function()
myRenderTarget = dxCreateRenderTarget(80, 100) -- Create a render target texture which is 80 x 100 pixels
end)
addEventHandler("onClientRender", root, function()
if myRenderTarget then
dxSetRenderTarget(myRenderTarget) -- Select custom render target
dxDrawText("Hello", 10, 20) -- The message 'Hello' will be drawn on myRenderTarget
dxSetRenderTarget() -- Select default render target
dxDrawText("Goodbye", 10, 20) -- The message 'Goodbye' will be drawn directly to the screen
end
end)

Changelog

  • 1.3.0-9.04431

    Removed restrictions on when dxSetRenderTarget could be called.