Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with moderngl #16

Open
oogre opened this issue Jun 13, 2022 · 0 comments
Open

Integration with moderngl #16

oogre opened this issue Jun 13, 2022 · 0 comments

Comments

@oogre
Copy link

oogre commented Jun 13, 2022

Hello,
I'm trying to integrate syphonpy with moderGL,
the goal is to build a modular video synthetizer.

I think I miss something, cause my understanding of syphonpy and modernGL is very partial.
First of all, I test both of these libraries, they are running well.
After that I mixed exemples form A and B, here lies the mix :

import numpy as np
import syphonpy
import pprint
from PIL import Image
import moderngl
from ported._example import Example
import time as delay

class AlphaBlending(Example):
    gl_version = (3, 3)
    title = "Alpha Blending"

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.id = 0;
        self.server = syphonpy.SyphonServer("headlessTest2")
        self.size = (1280, 720)
        self.fbo = self.ctx.framebuffer(
            color_attachments=[self.ctx.texture(self.size, 4)]
        )
        self.fbo.use()
        self.prog = self.ctx.program(
            vertex_shader='''
                #version 330

                in vec2 vert;

                in vec4 vert_color;
                out vec4 frag_color;

                uniform vec2 scale;
                uniform float rotation;

                void main() {
                    frag_color = vert_color;
                    float r = rotation * (0.5 + gl_InstanceID * 0.05);
                    mat2 rot = mat2(cos(r), sin(r), -sin(r), cos(r));
                    gl_Position = vec4((rot * vert) * scale, 0.0, 1.0);
                }
            ''',
            fragment_shader='''
                #version 330
                in vec4 frag_color;
                out vec4 color;
                void main() {
                    color = vec4(frag_color);
                }
            ''',
        )

        self.scale = self.prog['scale']
        self.rotation = self.prog['rotation']

        self.scale.value = (0.5, self.aspect_ratio * 0.5)

        vertices = np.array([
            1.0, 0.0,
            1.0, 0.0, 0.0, 0.5,

            -0.5, 0.86,
            0.0, 1.0, 0.0, 0.5,

            -0.5, -0.86,
            0.0, 0.0, 1.0, 0.5,
        ], dtype='f4')

        self.vbo = self.ctx.buffer(vertices)
        self.vao = self.ctx.simple_vertex_array(self.prog, self.vbo, 'vert', 'vert_color')

    def render(self, time: float, frame_time: float):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.BLEND)
        self.fbo.use()
        self.fbo.clear(255, 255, 255, 255)
        self.rotation.value = time
        self.vao.render(instances=10)

        viewPort = syphonpy.MakeRect(0,0,self.fbo.width,self.fbo.height)
        size = syphonpy.MakeSize(self.fbo.width,self.fbo.height)

        self.server.publish_frame_texture(self.fbo.glo, viewPort, size, False)


if __name__ == '__main__':
    AlphaBlending.run()

I run

python3 basic_alpha_blending.py

it works... the video output is piped to syphon which is what I need, the window build by moderGL is full white.
but I want to run it headless. so

I run

python3 basic_alpha_blending.py --window headless

it does not work. the syphon server looks to be created, but nothing is displayed into syphon recorder
(which I use to visualize the rendering)
later as debug, I saved the rendering FBO to a png file to isolate the bug origin,
this worked without any troubble,
So I imagine the trouble comes from syphonpy
but I'm kind of blocked...

does anyone here ve a bit of advices ?
Thanks for reading me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant