Image:getPointer
EditReturns a raw pointer to the Image's pixel data. This can be used to interface with other C libraries or the LuaJIT FFI.
pointer = Image:getPointer(level, layer)
Arguments
Name | Type | Default | Description |
level | number | 1 | The mipmap level to get the pointer of (for DDS and KTX images). |
layer | number | 1 | The array layer to get the pointer of (for DDS and KTX images). |
Returns
Name | Type | Description |
pointer | userdata | A pointer to the raw pixel data. |
Example
Simple example of writing to Image pixels with LuaJIT's FFI module.
local ffi = require 'ffi'
function lovr.load()
image = lovr.data.newImage(2, 2)
ffi.cdef [[
typedef struct { uint8_t r, g, b, a; } Pixel;
]]
pointer = image:getPointer()
pixels = ffi.cast('Pixel*', pointer)
pixels[0] = { 255, 0, 0, 255 }
pixels[1] = { 0, 255, 0, 255 }
pixels[2] = { 0, 0, 255, 255 }
pixels[3] = { 255, 255, 255, 255 }
texture = lovr.graphics.newTexture(image)
end
function lovr.draw(pass)
pass:setSampler('nearest')
pass:fill(texture)
end