I have managed to recreate the script to some extent. But the image is drawn only after I close the sender or ReleaseReceiver(). I’m not sure how to fix this. Maybe someone will have more luck. Sender has to the same name and resolution to connect.
import bpy
import gpu
import bgl
from gpu_extras.batch import batch_for_shader
import SpoutSDK
receiverName = 'aaa'
spoutReceiverWidth = 640
spoutReceiverHeight = 360
# create spout receiver
spoutReceiver = SpoutSDK.SpoutReceiver()
# Its signature in c++ looks like this: bool pyCreateReceiver(const char* theName, unsigned int theWidth, unsigned int theHeight, bool bUseActive);
spoutReceiver.pyCreateReceiver(receiverName,spoutReceiverWidth,spoutReceiverHeight, False)
# create texture for spout receiver
textureReceiveID = bgl.Buffer(bgl.GL_BYTE, spoutReceiverWidth*spoutReceiverHeight*4)
bgl.glGenTextures(1,textureReceiveID)
print("textureReceiveID "+str(textureReceiveID[0]))
# initalise receiver texture
bgl.glBindTexture(bgl.GL_TEXTURE_2D, textureReceiveID[0])
bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_WRAP_S, bgl.GL_CLAMP_TO_EDGE)
bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_WRAP_T, bgl.GL_CLAMP_TO_EDGE)
bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST)
bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST)
# copy data into texture
bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA, spoutReceiverWidth, spoutReceiverHeight, 0, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, textureReceiveID )
bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
shader = gpu.shader.from_builtin('2D_IMAGE')
shader.bind()
c=0
def draw():
global c
bgl.glActiveTexture(bgl.GL_TEXTURE0)
#(char* name, int &width, int &height, GLuint TextureID, GLuint TextureTarget, bool bInvert, GLuint HostFBO)
spoutReceiver.pyReceiveTexture(receiverName, spoutReceiverWidth, spoutReceiverHeight, textureReceiveID[0], bgl.GL_TEXTURE_2D, False, 0)
spoutReceiver.ReleaseReceiver()
bgl.glBindTexture(bgl.GL_TEXTURE_2D, textureReceiveID[0])
shader.bind()
shader.uniform_int("image", 0)
batch_for_shader(shader, 'TRI_FAN',{"pos": ((0, 0), (640, 0), (640, 360), (0, 360)),"texCoord": ((0, 0), (1, 0), (1, 1), (0, 1)),}).draw(shader)
print(str(c))
c+=1
draw_handle = bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL')