def textAsTexture(self, text, color=(0, 0, 0, 1), bgcolor=(1, 1, 1, 0), font_size=None, font_name=None, halign='left', width=None, rotate=0): label = self.text(text, color=color, font_size=font_size, font_name=font_name, halign=halign, width=width, valign='top') label.width w = int(width or label.width) h = font_size * len(label.lines) #int(label.height) x = c_int() def _f(): glPushAttrib(GL_COLOR_BUFFER_BIT|GL_ENABLE_BIT|GL_CURRENT_BIT) glEnable(GL_TEXTURE_2D) glDisable(GL_DEPTH_TEST) glClearColor(*bgcolor) glClear(GL_COLOR_BUFFER_BIT) glPushMatrix() if rotate == 0: glTranslatef(0, h, 0) if rotate: glRotatef(rotate, 0, 0, 1) if rotate == 270: glTranslatef(-w, h, 0) if rotate == 180: glTranslatef(-w, 0, 0) # prevent the text's alpha channel being written into the new # texture glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE) label.draw() glPopMatrix() glPopAttrib() if rotate in (0, 180): return util.renderToTexture(w, h, _f) else: return util.renderToTexture(h, w, _f)
def textAsTexture(self, text, color=(0, 0, 0, 1), bgcolor=(1, 1, 1, 0), font_size=None, font_name=None, halign='left', width=None, rotate=0): label = self.text(text, color=color, font_size=font_size, font_name=font_name, halign=halign, width=width, valign='top') label.width w = int(width or label.width) h = font_size * len(label.lines) #int(label.height) x = c_int() def _f(): glPushAttrib(GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT) glEnable(GL_TEXTURE_2D) glDisable(GL_DEPTH_TEST) glClearColor(*bgcolor) glClear(GL_COLOR_BUFFER_BIT) glPushMatrix() if rotate == 0: glTranslatef(0, h, 0) if rotate: glRotatef(rotate, 0, 0, 1) if rotate == 270: glTranslatef(-w, h, 0) if rotate == 180: glTranslatef(-w, 0, 0) # prevent the text's alpha channel being written into the new # texture glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE) label.draw() glPopMatrix() glPopAttrib() if rotate in (0, 180): return util.renderToTexture(w, h, _f) else: return util.renderToTexture(h, w, _f)
def xhtmlAsTexture(layout): h = int(layout.view.canvas_height) w = int(layout.view.canvas_width) def _f(): glPushAttrib(GL_CURRENT_BIT|GL_COLOR_BUFFER_BIT|GL_ENABLE_BIT) # always draw onto solid white glClearColor(1, 1, 1, 1) glClear(GL_COLOR_BUFFER_BIT) glPushMatrix() glLoadIdentity() glTranslatef(0, h, 0) # ... and blend with solid white glColor4f(1, 1, 1, 1) layout.view.draw() glPopMatrix() glPopAttrib() return util.renderToTexture(w, h, _f)
def xhtmlAsTexture(layout): h = int(layout.view.canvas_height) w = int(layout.view.canvas_width) def _f(): glPushAttrib(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT) # always draw onto solid white glClearColor(1, 1, 1, 1) glClear(GL_COLOR_BUFFER_BIT) glPushMatrix() glLoadIdentity() glTranslatef(0, h, 0) # ... and blend with solid white glColor4f(1, 1, 1, 1) layout.view.draw() glPopMatrix() glPopAttrib() return util.renderToTexture(w, h, _f)