Skip to content

Instantly share code, notes, and snippets.

@chancyk
Last active July 11, 2021 23:28
Show Gist options
  • Save chancyk/f8fc70ea55ab61ac25db2df2f1a03c86 to your computer and use it in GitHub Desktop.
Save chancyk/f8fc70ea55ab61ac25db2df2f1a03c86 to your computer and use it in GitHub Desktop.
let color = uint8((x / uiState.windowWidth) * 256)
let screen = newImage(512, 512)
let screenCtx = newContext(screen)
screenCtx.font = uiCtx.consoleFont
screen.fill(rgba(255, 255, 255, 255))
screen.fillText(
uiCtx.consoleFont.style(36, rgba(color, color, color, 255)),
$frameRate
)
var surface = createRGBSurface(0, cint 512, cint 512, 32, rmask, gmask, bmask, amask)
# screenCtx.image.data is a seq[ColorRGBX]. ColorRGBX is an object of uint8s
var dataPtr = screenCtx.image.data[0].addr
surface.pixels = dataPtr
var mainTexture = uiCtx.render.createTextureFromSurface(surface)
uiCtx.render.copy(mainTexture, nil, nil)
surface.pixels = nil
dealloc(dataPtr)
dataPtr = nil
destroy(surface)
destroy(mainTexture)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment