Пример #1
0
    def	makeRasterFont(self):
	GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
	self.fontOffset = GL.glGenLists(128)
	for i in range(32, 127):
	    GL.glNewList(i + self.fontOffset, GL.GL_COMPILE)
	    GL.glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, self.rasters[i-32])
	    GL.glEndList()
Пример #2
0
 def makeRasterFont(self):
     GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
     self.fontOffset = GL.glGenLists(128)
     for i in range(32, 127):
         GL.glNewList(i + self.fontOffset, GL.GL_COMPILE)
         GL.glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, self.rasters[i - 32])
         GL.glEndList()
Пример #3
0
 def drawGL(self,mode='wireframe',color=None):
     if self.color is not None:
         GL.glColor3fv(self.color)
     GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT,1)
     GL.glRasterPos3fv(self.pos)
     a =  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80
     b = 0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00
     bitmap = [b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,a,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b]
     GL.glBitmap(81,81,41,41,0,0,bitmap)
Пример #4
0
 def drawGL(self,**kargs):
     if self.color is not None:
         GL.glColor3fv(self.color)
     GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT,1)
     GL.glRasterPos3fv(self.pos)
     a =  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80
     b = 0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00
     bitmap = [b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,a,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b]
     GL.glBitmap(81,81,41,41,0,0,bitmap)
Пример #5
0
def use_pango_font(font, start, count, will_call_prepost=False):
    import gi
    gi.require_version('Pango', '1.0')
    gi.require_version('PangoCairo', '1.0')
    from gi.repository import Pango
    from gi.repository import PangoCairo
    #from gi.repository import Cairo as cairo
    import cairo

    fontDesc = Pango.FontDescription(font)
    a = array.array('b', itertools.repeat(0, 256 * 256))
    surface = cairo.ImageSurface.create_for_data(a, cairo.FORMAT_A8, 256, 256)
    context = cairo.Context(surface)
    pango_context = PangoCairo.create_context(context)
    layout = PangoCairo.create_layout(context)
    fontmap = PangoCairo.font_map_get_default()
    font = fontmap.load_font(fontmap.create_context(), fontDesc)
    layout.set_font_description(fontDesc)
    metrics = font.get_metrics()
    descent = metrics.get_descent()
    d = descent / Pango.SCALE
    linespace = metrics.get_ascent() + metrics.get_descent()
    width = metrics.get_approximate_char_width()

    GL.glPushClientAttrib(GL.GL_CLIENT_PIXEL_STORE_BIT)
    GL.glPixelStorei(GL.GL_UNPACK_SWAP_BYTES, 0)
    GL.glPixelStorei(GL.GL_UNPACK_LSB_FIRST, 1)
    GL.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, 256)
    GL.glPixelStorei(GL.GL_UNPACK_IMAGE_HEIGHT, 256)
    GL.glPixelStorei(GL.GL_UNPACK_SKIP_PIXELS, 0)
    GL.glPixelStorei(GL.GL_UNPACK_SKIP_ROWS, 0)
    GL.glPixelStorei(GL.GL_UNPACK_SKIP_IMAGES, 0)
    GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
    GL.glPixelZoom(1, -1)

    base = GL.glGenLists(count)
    for i in range(count):
        ch = chr(start + i)
        layout.set_text(ch, -1)
        w, h = layout.get_size()
        context.save()
        context.new_path()
        context.rectangle(0, 0, 256, 256)
        context.set_source_rgba(0., 0., 0., 0.)
        context.set_operator(cairo.OPERATOR_SOURCE)
        context.paint()
        context.restore()

        context.save()
        context.set_source_rgba(1., 1., 1., 1.)
        context.set_operator(cairo.OPERATOR_SOURCE)
        context.move_to(0, 0)
        PangoCairo.update_context(context, pango_context)
        PangoCairo.show_layout(context, layout)
        context.restore()
        w, h = int(w / Pango.SCALE), int(h / Pango.SCALE)
        GL.glNewList(base + i, GL.GL_COMPILE)
        GL.glBitmap(0, 0, 0, 0, 0, h - d, ''.encode())
        #glDrawPixels(0, 0, 0, 0, 0, h-d, '');
        if not will_call_prepost:
            pango_font_pre()
        if w and h:
            try:
                pass
                GL.glDrawPixels(w, h, GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE,
                                a.tobytes())
            except Exception as e:
                print("glnav Exception ", e)

        GL.glBitmap(0, 0, 0, 0, w, -h + d, ''.encode())
        if not will_call_prepost:
            pango_font_post()
        GL.glEndList()

    GL.glPopClientAttrib()
    return base, int(width / Pango.SCALE), int(linespace / Pango.SCALE)