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
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
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
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
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
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
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
def get_model(self): # type: () -> FrozenMat4 return FrozenMat4.transform(self._position, self._rotation, self._scaling)