Example #1
0
    def __init__(self,
                 context: mgl.Context,
                 shader,
                 width,
                 height,
                 text,
                 font,
                 color=(1, 1, 1, 1),
                 anchor_x='center',
                 anchor_y='center',
                 *args,
                 **kwargs):
        super().__init__(context, shader, *args, **kwargs)
        self.color = Vector4f(color)
        self.anchor_x = anchor_x
        self.anchor_y = anchor_y
        vertices, indices = self.bake(text, font)
        manager = FontManager()
        atlas = manager.atlas_agg
        self.atlas = context.texture(atlas.shape[0:2], 3, atlas.view(np.ubyte))
        vbo = context.buffer(vertices.view(np.ubyte))
        ibo = context.buffer(indices.view(np.ubyte))
        self.vao = context.vertex_array(
            shader,
            [  # TODO: pad? maybe doesn't matter 'cause we're not streaming
                (vbo, '2f 2f 1f', 'vertices', 'texcoord', 'offset')
            ],
            index_buffer=ibo)

        shader['viewport'].value = width, height
        self.atlas.use()
Example #2
0
File: camera.py Project: 3b1b/manim
 def get_fbo(self,
             ctx: moderngl.Context,
             samples: int = 0) -> moderngl.Framebuffer:
     pw = self.pixel_width
     ph = self.pixel_height
     return ctx.framebuffer(color_attachments=ctx.texture(
         (pw, ph),
         components=self.n_channels,
         samples=samples,
     ),
                            depth_attachment=ctx.depth_renderbuffer(
                                (pw, ph), samples=samples))
Example #3
0
 def new(cls, ctx: moderngl.Context, size: Tuple[int, int]) -> 'TexSurface':
     """Create a new TexSurface in the given moderngl context."""
     tex = ctx.texture(size, 4)
     return cls(ctx, tex)