Ejemplo n.º 1
0
 def sprite_nmap(window,
                 view,
                 projection,
                 diffuse,
                 normalmap,
                 position,
                 rotation,
                 scale,
                 origin,
                 view_pos,
                 light_pos,
                 blend=BlendMode.alpha):
     # type: (GLWindow, Mat4, Mat4, TexDescriptor, Texdescriptor, Vec2, float, Vec2, Vec2, Vec2, Vec2, BlendMode) -> None
     model = FrozenMat4.transform(Vec4(position, 0., 1.), rotation,
                                  Vec4(scale * diffuse.size, 0., 1.))
     current = window.blend_mode
     window.blend_mode = blend
     with nmap_sprite_array.render(
             GL_TRIANGLES) as shader:  # type: ShaderProgram
         shader.load2f('origin', *origin)
         shader.load_matrix4f('model', 1, False, model)
         shader.load_matrix4f('view', 1, False, tuple(view))
         shader.load_matrix4f('projection', 1, False, tuple(projection))
         shader.load3f('lightPos', *Vec3(light_pos, .3))
         shader.load3f('viewPos', *Vec3(view_pos, 0.))
         shader.load_sampler2d('diffuseMap', diffuse.id, 0)
         shader.load_sampler2d('normalMap', normalmap.id, 1)
         shader.load1i('normalMapping', 1)
     window.blend_mode = current
Ejemplo n.º 2
0
    def ellipse_fill(window,
                     view,
                     projection,
                     position,
                     rotation,
                     radii,
                     color,
                     precision,
                     tex=None,
                     vcoord=0.,
                     blend=BlendMode.alpha):
        # type: (GLWindow, Mat4, Mat4, Vec2, float, Vec2, Vec4, int, Optional[TexDescriptor], float) -> None
        count = max(8, min(precision, MAX_PRECISION))
        model = FrozenMat4.transform(Vec4(position, 0., 1.), rotation,
                                     Vec4(radii, 0., 1.))

        current = window.blend_mode
        window.blend_mode = blend
        with circlefill_vertex_array.render(
                GL_TRIANGLE_FAN, count + 2) as shader:  # type: ShaderProgram
            shader.load1f('circle_prec', count)
            shader.load_matrix4f('model', 1, False, model)
            shader.load_matrix4f('view', 1, False, tuple(view))
            shader.load_matrix4f('projection', 1, False, tuple(projection))
            shader.load1f('vcoord', vcoord)
            if isinstance(tex, TexDescriptor):
                shader.load_sampler2d('tex', tex.id, 0)
                shader.load1i('solidcolor', 0)
            else:
                shader.load_sampler2d('tex', texdata['circle_line_tex'].id, 0)
                shader.load1i('solidcolor', 1)
            shader.load4f('color', *color)

        window.blend_mode = current
Ejemplo n.º 3
0
    def sprite_subimage(window,
                        view,
                        projection,
                        subimagedescriptor,
                        subimage,
                        position,
                        rotation,
                        scale,
                        origin,
                        color,
                        blend=BlendMode.alpha):
        # type: (GLWindow, Mat4, Mat4, TexSubImageDescriptor, Vec2, float, Vec2, Vec2, Vec4, BlendMode) -> None
        model = FrozenMat4.transform(
            Vec4(position, 0., 1.), rotation,
            Vec4(scale * subimagedescriptor.image_size, 0., 1.))
        current = window.blend_mode
        window.blend_mode = blend
        image_index = int(round(subimage, 0)) % subimagedescriptor.image_count
        l, t, r, b = subimagedescriptor.bboxes[image_index]

        with anim_sprite_array.render(
                GL_TRIANGLES) as shader:  # type: ShaderProgram
            shader.load_matrix4f('model', 1, False, model)
            shader.load_matrix4f('view', 1, False, tuple(view))
            shader.load_matrix4f('projection', 1, False, tuple(projection))
            shader.load4f('lefttoprightbottom', l, t, r, b)
            shader.load4f('color', *color)
            shader.load_sampler2d('tex', subimagedescriptor.tex_descriptor.id,
                                  0)
        window.blend_mode = current
Ejemplo n.º 4
0
 def oriented_rect_fill(window,
                        view,
                        projection,
                        position,
                        size,
                        origin,
                        angle,
                        color,
                        blend=BlendMode.alpha):
     # type: (GLWindow, FrozenMat4, FrozenMat4, Vec2, Vec2, Vec2, float, Vec4, BlendMode) -> None
     model = FrozenMat4.transform(Vec4(position, 0., 1.), angle,
                                  Vec4(size, 0., 1.))
     current = window.blend_mode
     window.blend_mode = blend
     with rectfill_vertex_array.render(
             GL_TRIANGLES) as shader:  # type: ShaderProgram
         shader.load2f('origin', *origin)
         shader.load_matrix4f('model', 1, False, model)
         shader.load_matrix4f('view', 1, False, tuple(view))
         shader.load_matrix4f('projection', 1, False, tuple(projection))
         shader.load1f('vcoord', 0.)
         shader.load4f('color', *color)
         shader.load_sampler2d('tex', texdata['rect_tex'].id, 0)
         shader.load1i('solidcolor', 1)
     window.blend_mode = current
Ejemplo n.º 5
0
 def oriented_rect_line(window,
                        view,
                        projection,
                        position,
                        size,
                        origin,
                        angle,
                        color,
                        tex=None,
                        vcoord=0.,
                        blend=BlendMode.alpha):
     # type: (GLWindow, FrozenMat4, FrozenMat4, Vec2, Vec2, Vec2, float, Vec4, Optional[TexDescriptor], Optional[float], BlendMode) -> None
     model = FrozenMat4.transform(Vec4(position, 0., 1.), angle,
                                  Vec4(size, 0., 1.))
     current = window.blend_mode
     window.blend_mode = blend
     with rectline_vertex_array.render(
             GL_LINE_STRIP) as shader:  # type: ShaderProgram
         shader.load2f('origin', *origin)
         shader.load_matrix4f('model', 1, False, model)
         shader.load_matrix4f('view', 1, False, tuple(view))
         shader.load_matrix4f('projection', 1, False, tuple(projection))
         shader.load1f('vcoord', vcoord)
         shader.load4f('color', *color)
         if isinstance(tex, TexDescriptor):
             shader.load_sampler2d('tex', tex.id, 0)
             shader.load1i('solidcolor', 0)
         else:
             shader.load_sampler2d('tex', texdata['rect_tex'].id, 0)
             shader.load1i('solidcolor', 1)
     window.blend_mode = current
Ejemplo n.º 6
0
 def __init__(self):
     self._position = Vec4(0., 0., 0., 1.)
     self._origin = Vec2(.5, .5)
     self._rotation = 0.
     self._scaling = Vec4(1., 1., 0., 1.)
     self._color = Vec4(1., 1., 1., 1.)
     self._endcolor = Vec4(1., 1., 1., 1.)
     self._blend = BlendMode.alpha
     self._texture = None
     self._model = None
     self._updt_model = True
Ejemplo n.º 7
0
        def render(self, view, projection):
            # type: (Mat4, Mat4) -> None
            model = tuple(
                Mat4.transform(
                    Vec4(self._position, 0., 1.), self._rotation,
                    Vec4(self._scaling * self._texdescriptor.size, 0., 1.)))
            color = Vec4(self._color.rgb, self._color.a * self._alpha)

            with sprite_array.render(
                    GL_TRIANGLES) as shader:  # type: ShaderProgram
                shader.load_matrix4f('model', 1, False, model)
                shader.load_matrix4f('view', 1, False, tuple(view))
                shader.load_matrix4f('projection', 1, False, tuple(projection))
                shader.load4f('color', *color)
                shader.load_sampler2d('tex', self._texdescriptor.id, 0)
Ejemplo n.º 8
0
    def pie_ellipse_fill(window,
                         view,
                         projection,
                         position,
                         rotation,
                         radii,
                         start,
                         end,
                         color,
                         precision,
                         tex=None,
                         vcoord=0.,
                         blend=BlendMode.alpha):
        # type: (GLWindow, Mat4, Mat4, Vec2, float, Vec2, float, float, Vec4, float, Optional[TexDescriptor], float, BlendMode) -> None
        a = start % 360.
        b = end % 360.
        if b < a:
            theta = (360. - a) + b
        else:
            theta = b - a
        if theta == 0:
            return

        model = FrozenMat4.transform(Vec4(position, 0., 1.), rotation,
                                     Vec4(radii, 0., 1.))
        arc_prec = int(max(5, precision / (360. / theta)))
        current = window.blend_mode
        window.blend_mode = blend
        with pie_vertex_array.render(
                GL_TRIANGLE_FAN, arc_prec) as shader:  # type: ShaderProgram
            shader.load1f('angle', a)
            shader.load1f('theta', theta)
            shader.load1f('arc_prec', arc_prec - 1)
            shader.load_matrix4f('model', 1, False, model)
            shader.load_matrix4f('view', 1, False, tuple(view))
            shader.load_matrix4f('projection', 1, False, tuple(projection))
            shader.load1f('vcoord', vcoord)
            if isinstance(tex, TexDescriptor):
                shader.load_sampler2d('tex', tex.id, 0)
                shader.load1i('solidcolor', 0)
            else:
                shader.load_sampler2d('tex', texdata['circle_line_tex'].id, 0)
                shader.load1i('solidcolor', 1)
            shader.load4f('color', *color)

        window.blend_mode = current
Ejemplo n.º 9
0
 def __init__(self, texdescriptor):
     # type: (TexDescriptor) -> None
     self._texdescriptor = texdescriptor
     self._position = Vec2(0., 0.)
     self._rotation = 0.
     self._scaling = Vec2(1., 1.)
     self._color = Vec4(1., 1., 1., 1.)
     self._blend = BlendMode.alpha
     self._alpha = 1.
Ejemplo n.º 10
0
        def render(self, view, projection):
            # type: (Mat4, Mat4) -> None
            model = tuple(
                Mat4.transform(
                    Vec4(self._position, 0., 1.), self._rotation,
                    Vec4(self._scaling * self._anim_descriptor.image_size, 0.,
                         1.)))
            image_index = int(round(self._subimage,
                                    0)) % self._anim_descriptor.image_count
            l, t, r, b = self._anim_descriptor.bboxes[image_index]
            color = Vec4(self._color.rgb, self._color.a * self._alpha)

            with anim_sprite_array.render(
                    GL_TRIANGLES) as shader:  # type: ShaderProgram
                shader.load_matrix4f('model', 1, False, model)
                shader.load_matrix4f('view', 1, False, tuple(view))
                shader.load_matrix4f('projection', 1, False, tuple(projection))
                shader.load4f('lefttoprightbottom', l, t, r, b)
                shader.load4f('color', *color)
                shader.load_sampler2d('tex', self._texdescriptor.id, 0)

            if self._flip_speed != 0:
                self._subimage = (self._subimage + self._flip_speed
                                  ) % self._anim_descriptor.image_count
Ejemplo n.º 11
0
 def sprite(window,
            view,
            projection,
            texture,
            position,
            rotation,
            scale,
            origin,
            color,
            blend=BlendMode.alpha):
     # type: (GLWindow, Mat4, Mat4, TexDescriptor, Vec2, float, Vec2, Vec2, Vec4, BlendMode) -> None
     model = FrozenMat4.transform(Vec4(position, 0., 1.), rotation,
                                  Vec4(scale * texture.size, 0., 1.))
     current = window.blend_mode
     window.blend_mode = blend
     with sprite_array.render(
             GL_TRIANGLES) as shader:  # type: ShaderProgram
         shader.load2f('origin', *origin)
         shader.load_matrix4f('model', 1, False, model)
         shader.load_matrix4f('view', 1, False, tuple(view))
         shader.load_matrix4f('projection', 1, False, tuple(projection))
         shader.load4f('color', *color)
         shader.load_sampler2d('tex', texture.id, 0)
     window.blend_mode = current