set_context_attachment(3)
π set_context_attachment(3) β Arcan Lua API
omg hii bestie π welcome to the set_context_attachment(3) page from the Arcan Lua API. This one is short and slay: it changes the active attachment point for the current context. No cap, that's the whole vibe. π
β¨ NAME β¨
set_context_attachment β change the active attachment point for the current context.
π SYNOPSIS π
nil
set_context_attachment( vid )
set_context_attachment( outargs: vid )
π DESCRIPTION π
Okay so by default, every newly created object is attached to the world rendertarget referred to by WORLDID, and newly created rendertargets explicitly adopt source objects and attach to themselves. In later stages of the lifecycle, objects can also be dynamically attached to and detached from one or more rendertargets using the attach_rendertarget and detach_rendertarget commands respectively. π¦
That can get overly verbose when you're creating a bunch of objects and binding them to an existing rendertarget. For those cases, switching out the active context with this function is the move. The returned vid is the vid of the previously active context video. π«
π«Ά NOTES π«Ά
- Another case where the default attachment matters is when different rendertargets have different target densities. Some objects, like text or vector images, will have a backing store tied to the density of their current primary attachment. If you first have an implicit attachment to
WORLDIDand only then switch withattach_rendertarget, that causes costly rerasterization β and this function can avoid it. πβ¨ - The attachment is defined per context, so if the context stack is switched using
push_video_contextorpop_video_context, the attachment point switches too. π - Providing a bad, missing, or non-rt designated
vidwill not change any default attachment state β it only returns the current one. π¨
π EXAMPLE π
Here's the example, copied exactly because code is sacred:
function set_context_attachment0()
-- create an object that will be attached to world
green = color_surface(64, 64, 0, 255, 0);
show_image(green);
-- create the rendertarget that will be our new default
rtgt = alloc_surface(VRESW, VRESH);
define_rendertarget(rtgt, {null_surface(32, 32)});
set_context_attachment(rtgt);
-- make the new rendertarget slowly spinning and scaled
-- to show that newly created are in fact attached correctly
show_image(rtgt);
resize_image(rtgt, VRESW * 0.5, VRESH * 0.5);
move_image(rtgt, VRESW * 0.25, VRESH * 0.25);
rotate_image(rtgt, 90, 500);
-- spawn some random blocks
for i=1,10 do
local b = color_surface(32, 32, 64, math.random(255), 64);
show_image(b);
move_image(b, math.random(VRESW - 32), math.random(VRESH - 32), 500);
end
end
π SEE ALSO: π
vidsys
xoxo, bestie π this page was served by source/version vidsys, dated October 2026, and it's set_context_attachment(3) certified π
π¦ where this page comes from
- nixos 26.05: arcan 0.7.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms