def __init__(self, transform=None, viewport=None, color=(1, 1, 1, 1), **kwargs): dtype = [('position', (np.float32, 2), '!local', (0, 0)), ('texcoord', (np.float32, 2), '!local', (0, 0)), ('offset', (np.float32, 1), '!local', 0), ('origin', (np.float32, 3), 'shared', (0, 0, 0)), ('color', (np.float32, 4), 'shared', color)] print('===========================') if "vertex" in kwargs.keys(): vertex = kwargs["vertex"] del kwargs["vertex"] else: vertex = library.get('collections/agg-glyph.vert') if "fragment" in kwargs.keys(): fragment = kwargs["vertex"] del kwargs["vertex"] else: fragment = library.get('collections/agg-glyph.frag') Collection.__init__(self, dtype=dtype, itype=np.uint32, mode=gl.GL_TRIANGLES, vertex=vertex, fragment=fragment) program = self._programs[0] if transform is not None: program["transform"] = transform else: program["transform"] = Position() if "viewport" in program.hooks: if viewport is not None: program["viewport"] = viewport else: program["viewport"] = Viewport() manager = FontManager() atlas = manager.atlas_agg self['atlas_data'] = atlas self['atlas_data'].interpolation = gl.GL_LINEAR self['atlas_shape'] = atlas.shape[1], atlas.shape[0]
def __init__(self, transform=None, viewport=None, **kwargs): dtype = [('position', (np.float32, 2), '!local', (0, 0)), ('texcoord', (np.float32, 2), '!local', (0, 0)), ('origin', (np.float32, 3), 'shared', (0, 0, 0)), ('direction', (np.float32, 3), 'shared', (1, 0, 0)), ('scale', (np.float32, 1), 'shared', 0.005), ('color', (np.float32, 4), 'shared', (0, 0, 0, 1))] if "vertex" in kwargs.keys(): vertex = library.get(kwargs["vertex"]) del kwargs["vertex"] else: vertex = library.get('collections/sdf-glyph.vert') if "fragment" in kwargs.keys(): fragment = library.get(kwargs["fragment"]) del kwargs["fragment"] else: fragment = library.get('collections/sdf-glyph.frag') Collection.__init__(self, dtype=dtype, itype=np.uint32, mode=gl.GL_TRIANGLES, vertex=vertex, fragment=fragment) program = self._programs[0] if transform is not None: program["transform"] = transform # else: # program["transform"] = Position() if "viewport" in program.hooks: if viewport is not None: program["viewport"] = viewport else: program["viewport"] = Viewport() manager = FontManager() atlas = manager.atlas_sdf self['u_kernel'] = data.get("spatial-filters.npy") self['atlas_data'] = atlas self['atlas_data'].interpolation = gl.GL_LINEAR self['atlas_shape'] = atlas.shape[1], atlas.shape[0]
# Distributed under the (new) BSD License. # ----------------------------------------------------------------------------- from glumpy import app from glumpy.log import log from glumpy.graphics.text import FontManager from glumpy.graphics.collections import GlyphCollection from glumpy.transforms import Position, OrthographicProjection, Viewport window = app.Window(width=1200, height=800, color=(1, 1, 1, 1)) @window.event def on_draw(dt): window.clear() labels.draw() labels = GlyphCollection("agg", transform=OrthographicProjection(Position())) text = "The quick brown fox jumps over the lazy dog" x, y, z = 2, window.height, 0 log.info("Caching texture fonts") for i in range(6, 54, 2): font = FontManager.get("OpenSans-Regular.ttf", size=i, mode="agg") y -= i * 1.1 labels.append(text, font, origin=(x, y, z), anchor_x="left") window.attach(labels["transform"]) window.attach(labels["viewport"]) app.run()
transform = Trackball(Position()) viewport = Viewport() labels = GlyphCollection(transform=transform, viewport=viewport) paths = PathCollection(mode="agg+", transform=transform, viewport=viewport) ticks = SegmentCollection(mode="agg", transform=transform, viewport=viewport, linewidth="local", color="local") # xmin,xmax = 0,800 # ymin,ymax = 0,800 xmin, xmax = -1, 1 ymin, ymax = -1, 1 z = 0 regular = FontManager.get("OpenSans-Regular.ttf") bold = FontManager.get("OpenSans-Bold.ttf") n = 11 scale = 0.001 for i, y in enumerate(np.linspace(xmin, xmax, n)): text = "%.2f" % (i / 10.0) labels.append( text, regular, origin=(1.05, y, z), scale=scale, direction=(1, 0, 0), anchor_x="left", anchor_y="center" ) labels.append( text, regular, origin=(y, -1.05, z), scale=scale, direction=(1, 0, 0), anchor_x="center", anchor_y="top" ) title = "Lorenz strange attractor" labels.append( title, bold, origin=(0, 1.1, z), scale=2 * scale, direction=(1, 0, 0), anchor_x="center", anchor_y="center"
for z in np.linspace(zmin, zmax, n_major)[0:-1]: paths.append(linepath((xmin, ymin, z), (xmin + length_major, ymin, z)), linewidth=2.0, color=(0, 0, 0, 1)) for z in np.linspace(zmin, zmax, n_minor)[0:-1]: paths.append(linepath((xmin, ymin, z), (xmin + length_minor, ymin, z)), linewidth=1.0, color=(0, 0, 0, 1)) # Tick labels # ------------------------------------- labels = GlyphCollection(transform=transform, viewport=viewport, vertex='collections/tick-labels.vert') regular = FontManager.get("OpenSans-Regular.ttf") n = 10 + 1 scale = 0.002 for i, y in enumerate(np.linspace(xmin, xmax, n)[:-1]): text = "%.2f" % (i / 10.0) labels.append(text, regular, origin=(xmax + 0.1, y, zmin), scale=0.65 * scale, direction=(1, 0, 0), anchor_x="left", anchor_y="center") labels.append(text, regular, origin=(y, -.001, zmin), scale=0.65 * scale,
# Distributed under the (new) BSD License. # ----------------------------------------------------------------------------- from glumpy import app from glumpy.log import log from glumpy.graphics.text import FontManager from glumpy.graphics.collections import GlyphCollection from glumpy.transforms import Position, OrthographicProjection, Viewport window = app.Window(width=1200, height=800, color=(1, 1, 1, 1)) @window.event def on_draw(dt): window.clear() labels.draw() labels = GlyphCollection('agg', transform=OrthographicProjection(Position())) text = "The quick brown fox jumps over the lazy dog" x, y, z = 2, window.height, 0 log.info("Caching texture fonts") for i in range(6, 54, 2): font = FontManager.get("OpenSans-Regular.ttf", size=i, mode='agg') y -= i * 1.1 labels.append(text, font, origin=(x, y, z), anchor_x="left") window.attach(labels["transform"]) window.attach(labels["viewport"]) app.run()
v_texcoord = texcoord; <viewport.transform>; float scale = (3.5 - length(gl_Position.xyz)/length(vec3(1.5))); v_color.a = scale; // We set actual position after transform v_offset = 3.0*(offset + origin.x - int(origin.x)); gl_Position /= gl_Position.w; gl_Position = gl_Position + vec4(2.0*position/<viewport.viewport_global>.zw,0,0); } """ labels = GlyphCollection('agg', vertex=vertex, transform=transform, viewport=viewport) font = FontManager.get("OpenSans-Regular.ttf", size=16, mode='agg') for i in range(len(P)): labels.append(C[i], font, origin = P[i]) labels["position"][:,1] -= 20 window = app.Window(width=1024, height=1024, color=(.2,.2,.35,1)) window.attach(transform) window.attach(viewport) @window.event def on_draw(dt): window.clear() gl.glEnable(gl.GL_DEPTH_TEST) earth.draw(gl.GL_TRIANGLES, indices) paths.draw() gl.glDisable(gl.GL_DEPTH_TEST)
anchor_x = "left", anchor_y = "center") x = xmax - 0.05*(xmax-xmin) labels.append(values[i].upper(), regular, color=c, origin = (x,y,0), scale = 0.002, direction = (1,0,0), anchor_x = "right", anchor_y = "center") transform = PanZoom(OrthographicProjection(Position(),normalize=True),aspect=1) transform.zoom = 0.165 viewport = Viewport() quads = collections.TriangleCollection(transform = transform, viewport=viewport) labels = collections.GlyphCollection(transform = transform, viewport=viewport) regular = FontManager.get("OpenSans-Regular.ttf") x,y = -2.5*2.6,+4 for i,name in enumerate(["Red", "Pink", "Purple", "Deep Purple", "Indigo", "Blue", "Light Blue", "Cyan", "Teal", "Green", "Light Green", "Lime", "Yellow", "Amber", "Orange", "Deep Orange", "Brown", "Grey"]): family = "material:%s" % name if i > 0 and (i % 6) == 0: y -= 4 x = -2.5*2.6 if name not in ["Brown", "Grey"]: names = list(color.get(family).keys())[:-1][::-1] values = color.get(family+":*")[:-4][::-1] else: names = list(color.get(family).keys())[::-1]
labels = GlyphCollection(transform=transform, viewport=viewport) paths = PathCollection(mode="agg+", transform=transform, viewport=viewport) ticks = SegmentCollection(mode="agg", transform=transform, viewport=viewport, linewidth='local', color='local') # xmin,xmax = 0,800 # ymin,ymax = 0,800 xmin, xmax = -1, 1 ymin, ymax = -1, 1 z = 0 regular = FontManager.get("OpenSans-Regular.ttf") bold = FontManager.get("OpenSans-Bold.ttf") n = 11 scale = 0.001 for i, y in enumerate(np.linspace(xmin, xmax, n)): text = "%.2f" % (i / 10.0) labels.append(text, regular, origin=(1.05, y, z), scale=scale, direction=(1, 0, 0), anchor_x="left", anchor_y="center") labels.append(text, regular, origin=(y, -1.05, z),
"Came whiffling through the tulgey wood,\n" " And burbled as it came!\n" "One, two! One, two! And through and through\n" " The vorpal blade went snicker-snack!\n" "He left it dead, and with its head\n" " He went galumphing back.\n" "\"And, has thou slain the Jabberwock?\n" " Come to my arms, my beamish boy!\n" "O frabjous day! Callooh! Callay!'\n" " He chortled in his joy.\n" "\n" "`Twas brillig, and the slithy toves\n" " Did gyre and gimble in the wabe;\n" "All mimsy were the borogoves,\n" " And the mome raths outgrabe.\n" ) window = app.Window(width=700, height=700, color=(1,1,1,1)) @window.event def on_draw(dt): window.clear() glyphs.draw() glyphs = GlyphCollection(transform=Trackball(Position())) glyphs.append(jabberwocky, FontManager.get("Roboto-Regular.ttf")) window.attach(glyphs["transform"]) window.attach(glyphs["viewport"]) app.run()
def grid(transform, viewport, scale=1.0): ticks = SegmentCollection(mode="agg", transform=transform, viewport=viewport, linewidth='local', color='local') labels = GlyphCollection(transform=transform, viewport=viewport) # xmin,xmax = 0,800 # ymin,ymax = 0,800 xmin, xmax = -1, 1 nx = 11 dx = (xmax - xmin) / (nx - 1) ymin, ymax = -1, 1 ny = 11 dy = (ymax - ymin) / (ny - 1) z = 0 regular = FontManager.get("OpenSans-Regular.ttf") bold = FontManager.get("OpenSans-Bold.ttf") labels_scale = 0.001 for x in np.linspace(xmin, xmax, nx): text = "%.2f" % (x * scale) labels.append(text, regular, origin=(x, ymin - dy / 2, z), scale=labels_scale, direction=(1, 0, 0), anchor_x="center", anchor_y="top") for y in np.linspace(ymin, ymax, ny): text = "%.2f" % (y * scale) labels.append(text, regular, origin=(xmin - dx / 2, y, z), scale=labels_scale, direction=(1, 0, 0), anchor_x="right", anchor_y="center") title = "H3M example" labels.append(title, bold, origin=(0, xmax + dx, z), scale=2 * labels_scale, direction=(1, 0, 0), anchor_x="center", anchor_y="center") # Frame # ------------------------------------- P0 = [(xmin, ymin, z), (xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z)] P1 = [(xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z), (xmin, ymin, z)] ticks.append(P0, P1, linewidth=2) # Grids # ------------------------------------- n = 11 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymax P1[:, 2] = z ticks.append(P0, P1, linewidth=1, color=(0, 0, 0, .25)) P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = xmin P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P0[:, 2] = z P1[:, 0] = xmax P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P1[:, 2] = z ticks.append(P0, P1, linewidth=1, color=(0, 0, 0, .25)) # Majors # ------------------------------------- n = 11 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin - 0.015 P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymin + 0.025 * (ymax - ymin) P1[:, 2] = z ticks.append(P0, P1, linewidth=1.5) P0[:, 1] = ymax + 0.015 P1[:, 1] = ymax - 0.025 * (ymax - ymin) ticks.append(P0, P1, linewidth=1.5) P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = xmin - 0.015 P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P0[:, 2] = z P1[:, 0] = xmin + 0.025 * (xmax - xmin) P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P1[:, 2] = z ticks.append(P0, P1, linewidth=1.5) P0[:, 0] = xmax + 0.015 P1[:, 0] = xmax - 0.025 * (xmax - xmin) ticks.append(P0, P1, linewidth=1.5) # Minors # ------------------------------------- n = 111 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymin + 0.0125 * (ymax - ymin) P1[:, 2] = z ticks.append(P0, P1, linewidth=1) P0[:, 1] = ymax P1[:, 1] = ymax - 0.0125 * (ymax - ymin) ticks.append(P0, P1, linewidth=1) P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = xmin P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P0[:, 2] = z P1[:, 0] = xmin + 0.0125 * (xmax - xmin) P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P1[:, 2] = z ticks.append(P0, P1, linewidth=1) P0[:, 0] = xmax P1[:, 0] = xmax - 0.0125 * (xmax - xmin) ticks.append(P0, P1, linewidth=1) return ticks
uniform sampler2D texture; varying vec2 v_texcoord; void main() { gl_FragColor = texture2D(texture, v_texcoord); } """ window = app.Window(width=1024, height=1024) @window.event def on_draw(dt): window.clear() program.draw(gl.GL_TRIANGLE_STRIP) program = gloo.Program(vertex, fragment, count=4) program['position'] = [(-1,-1), (-1,+1), (+1,-1), (+1,+1)] program['texcoord'] = [( 0, 1), ( 0, 0), ( 1, 1), ( 1, 0)] log.info("Caching texture fonts") manager = FontManager() for size in range(8,25): font = manager.get("OpenSans-Regular.ttf", size=size, mode='agg') font.load(""" !\"#$%&'()*+,-./0123456789:;<=>?""" """@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_""" """`abcdefghijklmnopqrstuvwxyz{|}~""") program['texture'] = manager.atlas_agg app.run()
"One, two! One, two! And through and through\n" " The vorpal blade went snicker-snack!\n" "He left it dead, and with its head\n" " He went galumphing back.\n" "\"And, has thou slain the Jabberwock?\n" " Come to my arms, my beamish boy!\n" "O frabjous day! Callooh! Callay!'\n" " He chortled in his joy.\n" "\n" "`Twas brillig, and the slithy toves\n" " Did gyre and gimble in the wabe;\n" "All mimsy were the borogoves,\n" " And the mome raths outgrabe.\n") window = app.Window(width=700, height=700, color=(1, 1, 1, 1)) @window.event def on_draw(dt): window.clear() glyphs.draw() glyphs = GlyphCollection(transform=Trackball(Position())) glyphs.append(jabberwocky, FontManager.get("Roboto-Regular.ttf")) window.attach(glyphs["transform"]) window.attach(glyphs["viewport"]) app.run()
# ----------------------------------------------------------------------------- # Copyright (c) 2009-2016 Nicolas P. Rougier. All rights reserved. # Distributed under the (new) BSD License. # ----------------------------------------------------------------------------- from glumpy import app, gl, gloo, glm, data from glumpy.graphics.text import FontManager from glumpy.graphics.collections import GlyphCollection from glumpy.transforms import Position, OrthographicProjection window = app.Window(width=512, height=512) @window.event def on_draw(dt): window.clear() label.draw() x,y,z = 256,256,0 font = FontManager.get("OpenSans-Regular.ttf", 64, mode='agg') label = GlyphCollection('agg', transform=OrthographicProjection(Position())) label.append("Hello World !", font, anchor_x = 'center', anchor_y = 'center', origin=(x,y,z), color=(1,1,1,1)) window.attach(label["transform"]) app.run()
"He left it dead, and with its head\n" " He went galumphing back.\n" "\"And, has thou slain the Jabberwock?\n" " Come to my arms, my beamish boy!\n" "O frabjous day! Callooh! Callay!'\n" " He chortled in his joy.\n" "\n" "`Twas brillig, and the slithy toves\n" " Did gyre and gimble in the wabe;\n" "All mimsy were the borogoves,\n" " And the mome raths outgrabe.\n") window = app.Window(width=700, height=700, title="hello", color=(1, 1, 1, 1)) @window.event def on_draw(dt): window.clear() glyphs.draw() glyphs = GlyphCollection(transform=Trackball(Position())) glyphs.append(jabberwocky, FontManager.get("c:/windows/fonts/arial.ttf")) window.attach(glyphs["transform"]) window.attach(glyphs["viewport"]) app.run()