Skip to content

GPUBuffer

GPUBuffer provides an interface to interact with the GPU buffer.

The buffer is sized to the screen size upon creation and cannot be resized, indexing out of bounds will be discarded.

Warning

The GPUBuffer index starts at 0!

Example

Generate a red and blue pattern, where every even pixel is red and every odd pixel is blue.

This can either generate a checkerboard pattern or a vertical lines pattern depending on the screen size.

Lua
local gpu = require("gpu")
local buffer<close> = gpu.newBuffer()

for i = 0, #buffer - 1 do
    if i % 2 == 0 then
        buffer[i] = 0xff0000
    else
        buffer[i] = 0x0000ff
    end
end

gpu.setBuffer(buffer)

Last update: March 11, 2023
Created: March 11, 2023