Exemple #1
0
    def __init__(self):
        # Window parameters
        self.WIDTH = 800
        self.HEIGHT = 600

        # LED parameters
        self.LED_WIDTH = 5
        self.LED_SPACING = 5

        # Number of LEDs on each wall
        self.LEFT_WALL = self.HEIGHT / (self.LED_WIDTH + self.LED_SPACING)
        self.RIGHT_WALL = self.LEFT_WALL
        self.TOP_WALL = self.WIDTH / (self.LED_WIDTH + self.LED_SPACING)

        # The window doing the rendering
        self.wnd = glwindow.window((800, 600))

        # The context that we write to
        self.ctx = moderngl.create_context()

        def getPos(i):
            """
            Calculates the position of the LED as an (x,y) coordinate, where x
            and y belong to (-1,1).

            Parameters:
                i       Ranges from 0 to 1 and represents how far the desired
                        LED is along the strip
            """
            if i < 1/3.0:
                # Left wall
                return (-0.9, (6*i - 1)*0.95)
            elif i < 2/3.0:
                # Top wall
                return (((i - 1/3.0) * 6 - 1)*0.9, 0.95)
            else:
                # Right wall
                return (0.9, ((2/3.0 - i) * 6 + 1)*0.95)

        # Init LED objects
        n = rendering_conf.NUM_PIXELS       # More concise
        self.leds = [_LED(self.ctx, getPos(i/n), self.LED_WIDTH)
                     for i in range(n)]
Exemple #2
0
            gl_Position.y *= -1.0;
        }
    '''),
    fragment_shader=glsl('''
        #version 450
        #pragma shader_stage(fragment)

        layout (location = 0) in vec4 in_color;
        layout (location = 0) out vec4 out_color;

        void main() {
            out_color = in_color;
        }
    '''),
    vertex_count=3,
)

wnd_1 = glwindow.window((512, 512), 'Window 1')
wnd_2 = glwindow.window((512, 512), 'Window 2')

wnd_1.show(True)
wnd_2.show(True)

instance.surface(wnd_1.handle, framebuffer.output[0])
instance.surface(wnd_2.handle, framebuffer.output[0])

while wnd_1.visible or wnd_2.visible:
    glwindow.update()
    task.run()
    instance.present()
Exemple #3
0
        void main() {
            gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
            out_color = colors[gl_VertexIndex];
            gl_Position.y *= -1.0;
        }
    '''),
    fragment_shader=glsl('''
        #version 450
        #pragma shader_stage(fragment)

        layout (location = 0) in vec4 in_color;
        layout (location = 0) out vec4 out_color;

        void main() {
            out_color = in_color;
        }
    '''),
    vertex_count=3,
)

wnd = glwindow.window((512, 512))
wnd.show(True)

instance.surface(wnd.handle, framebuffer.output[0])

while wnd.visible:
    glwindow.update()
    task.run()
    instance.present()
Exemple #4
0
import glwindow
import moderngl as mgl
import numpy as np

wnd = glwindow.window((840, 480))
ctx = mgl.create_context()

prog = ctx.program(
    vertex_shader='''
        #version 140
        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 140
        in vec4 frag_color;
        out vec4 color;
        void main() {
            color = vec4(frag_color);
        }
    ''',
)