Skip to content

Texture pixels

Client-side
Server-side
Shared

Pixels properties

Section Pixels properties

Pixels have two properties:

  • dimensions: (width and height) which is retrieved by using the function dxGetPixelsSize.
  • format: (plain,jpeg,png,dds) which is retrieved by using the function dxGetPixelsFormat
    • plain - Fastest and simplest - It's default format of the pixels returned by dxGetTexturePixels and the only one that can be used with dxSetTexturePixels, dxGetPixelColor and dxSetPixelColor. But it also uses a lot of bytes, so internet transfers will be longer. Also can't be read by Photoshop or browsers etc.
    • png - A few less bytes, still quite big for net transfers. Can be saved to a file and read by Photoshop and browsers etc.
    • jpeg - A lot less bytes, so best for net transfers. Can be saved to a file and read by Photoshop and browsers etc.
    • dds - DirectDraw Surface. Game's native texture format with various compressed and uncompressed options. Used to store standard, cube or volume textures. Compressed pixels in this format can be loaded nearly instantly by dxCreateTexture.

To convert between the 3 different formats, use the function dxConvertPixels.

Pixels performance

Section Pixels performance

Getting/setting pixels from textures is not quick and not something you want to be doing every frame (in onClientRender for example). Setting pixels to a render target is especially slow. Pixels are ideal however for transferring composite images built on a render target into a normal texture for later use. For example, making a custom radar map.


Pixels can also be loaded from any png/jpeg file just like this:

local fileHandler = fileOpen("hello.jpg")
if (not fileHandler) then
return false
end
local fileSize = fileGetSize(fileHandler)
local filePixels = fileRead(fileHandler, fileSize)
fileClose(fileHandler)

Pixels can be used to create textures just like this:

local newTexture = dxCreateTexture(pixelsData)

Pixels can be used to save textures just like this:

local texturePixels = dxGetTexturePixels(myRenderTarget)
local texturePixelsConverted = dxConvertPixels(texturePixels, "jpeg")
local fileHandler = fileCreate("piccy.jpg")
if (not fileHandler) then
return false
end
fileWrite(fileHandler, texturePixelsConverted)
fileClose(fileHandler)