M MY Multiplayer: Wiki
Side
Kind

dxGetTexturePixels

Client

Reads an image's pixels and hands them to a function, a few frames later.

bool dxGetTexturePixels(texture|dui texture, function callback [, string format = plain, string textureFormat = unknown, bool mipmaps = true, int x, y = 0, 0, int width, height = 0, 0])

Parameters

NameTypeDescription
texturetexture|duiThe image: a texture, render target, screen source or dui. A txd texture works too.
formatstringFormat: plain, png, jpeg or dds.default plain
textureFormatstringFor dds: unknown (the image's own), argb, xrgb, rgb, dxt1, dxt2, dxt3, dxt4 or dxt5. Only allowed after format.default unknown
mipmapsboolFor dds: generate mipmaps. Only allowed after format.default true
x, yintTop-left corner of the area read, in pixels. A vec2 also works.default 0, 0
width, heightintSize of the area read. With a height of 0, the whole image is read. A vec2 also works.default 0, 0
callbackfunctionReceives the pixels as a string, or false when the read failed.

Returns

true when the read started, false when the image has no content yet.

A leading number (MTA's surface index) is accepted and ignored. 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

local target = dxCreateRenderTarget(256, 256, true)

dxGetTexturePixels(target, "png", function(pixels)
    if not pixels then return end
    local file = fileCreate("snapshot.png")
    fileWrite(file, pixels)
    fileClose(file)
end)
Coming from MTAMTA returns the pixels right away. MYMP hands them to a function, since reading from the GPU takes a few frames.

See also