Spout.SpoutReceiver.new: Difference between revisions
From GiderosMobile
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
'''Available since:''' Gideros | '''Available since:''' Gideros 2018.6.3<br/> | ||
'''Class:''' [[Spout]]<br/> | '''Class:''' [[Spout]]<br/> | ||
| Line 11: | Line 11: | ||
=== Return values === | === Return values === | ||
'''Returns''' (SpoutReceiver) the new receiver object<br/> | '''Returns''' (SpoutReceiver) the new receiver object<br/> | ||
=== Example === | |||
'''Receive from another application''' | |||
<syntaxhighlight lang="lua"> | |||
require "spout" | |||
local receiver = SpoutReceiver.new() | |||
-- list the senders currently running on this machine | |||
for _, s in ipairs(receiver:findSenders()) do | |||
print(s.name, s.width, s.height) | |||
end | |||
-- connect to one of them and create a texture of the right size | |||
local ok, name, w, h = receiver:bind("OBS-Studio", false) | |||
local rt = RenderTarget.new(w, h, true, false, false, false, nil, false) | |||
local texW, texH = w, h | |||
local preview = Bitmap.new(rt) | |||
stage:addChild(preview) | |||
stage:addEventListener(Event.ENTER_FRAME, function(e) | |||
-- keep the name Spout reports back, the sender may be renamed or replaced | |||
local connected, actualName, aw, ah = receiver:receiveTexture(rt, name) | |||
name = actualName or name | |||
if connected and aw and ah and (aw ~= texW or ah ~= texH) then | |||
-- the sender was resized: rebuild the receiving texture | |||
texW, texH = aw, ah | |||
rt = RenderTarget.new(texW, texH, true, false, false, false, nil, false) | |||
preview:setTexture(rt) | |||
end | |||
end) | |||
</syntaxhighlight> | |||
{{Spout}} | {{Spout}} | ||
Latest revision as of 00:51, 13 November 2026
Available since: Gideros 2018.6.3
Class: Spout
Description
Creates a new receiver. It is not connected to anything until bind() or receiveTexture() is called.
(SpoutReceiver) = SpoutReceiver.new()
Return values
Returns (SpoutReceiver) the new receiver object
Example
Receive from another application
require "spout"
local receiver = SpoutReceiver.new()
-- list the senders currently running on this machine
for _, s in ipairs(receiver:findSenders()) do
print(s.name, s.width, s.height)
end
-- connect to one of them and create a texture of the right size
local ok, name, w, h = receiver:bind("OBS-Studio", false)
local rt = RenderTarget.new(w, h, true, false, false, false, nil, false)
local texW, texH = w, h
local preview = Bitmap.new(rt)
stage:addChild(preview)
stage:addEventListener(Event.ENTER_FRAME, function(e)
-- keep the name Spout reports back, the sender may be renamed or replaced
local connected, actualName, aw, ah = receiver:receiveTexture(rt, name)
name = actualName or name
if connected and aw and ah and (aw ~= texW or ah ~= texH) then
-- the sender was resized: rebuild the receiving texture
texW, texH = aw, ah
rt = RenderTarget.new(texW, texH, true, false, false, false, nil, false)
preview:setTexture(rt)
end
end)