def write_text(self, text): #gl.glTexEnvf( gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE ) #gl.glEnable( gl.GL_DEPTH_TEST ) gl.glEnable(gl.GL_BLEND) #gl.glEnable( gl.GL_COLOR_MATERIAL ) #gl.glColorMaterial( gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE ) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_TEXTURE_2D) gl.glBindTexture(gl.GL_TEXTURE_2D, self.texture_id) gl.glColor4f(1, 1, 0, 1) gl.glPushMatrix() gl.glLoadIdentity() gl.glScalef(0.003, 0.003, 0) #gl.glTranslatef(10, 100, 0) gl.glPushMatrix() gl.glListBase(self.base) gl.glCallLists(len(text), gl.GL_UNSIGNED_BYTE, bytes(text, 'utf-8')) #for c in text: # gl.glCallList(self.base + 1 + ord(c)) gl.glPopMatrix() gl.glPopMatrix() gl.glDisable(gl.GL_BLEND) gl.glDisable(gl.GL_TEXTURE_2D)
def _text_glyphs_gl(self): if not self._text_dlist: dl_index = glGenLists(1) glNewList(dl_index, GL_COMPILE) # stime=getTime() # self._text_box._te_start_gl() ### glActiveTexture(GL_TEXTURE0) glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, self._text_box._current_glfont.atlas.texid) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) glTranslatef(self._position[0], -self._position[1], 0) glPushMatrix() ### getLineInfoByIndex = self._text_document.getLineInfoByIndex active_text_style_dlist = self._current_font_display_lists.get cell_width, cell_height = self._cell_size num_cols, num_rows = self._shape line_spacing = self._text_box._getPixelTextLineSpacing() line_count = self.getRowCountWithText() glColor4f(*self._text_box._toRGBA(self._font_color)) for r in range(line_count): cline, line_length, line_display_list, line_ords = getLineInfoByIndex( r) if line_display_list[0] == 0: line_display_list[0:line_length] = [ active_text_style_dlist(c) for c in line_ords ] glTranslatef( cline._trans_left * cell_width, -int(line_spacing / 2.0 + cline._trans_top * cell_height), 0) glCallLists(line_length, GL_UNSIGNED_INT, line_display_list[0:line_length].ctypes) cline._trans_left = 0 glTranslatef( -line_length * cell_width - cline._trans_left * cell_width, -cell_height + int(line_spacing / 2.0 + cline._trans_top * cell_height), 0) ### glPopMatrix() glBindTexture(GL_TEXTURE_2D, 0) glDisable(GL_TEXTURE_2D) glEndList() self._text_dlist = dl_index glCallList(self._text_dlist)
def _text_glyphs_gl(self): if not self._text_dlist: dl_index = glGenLists(1) glNewList(dl_index, GL_COMPILE) # stime=getTime() # self._text_box._te_start_gl() ### glActiveTexture(GL_TEXTURE0) glEnable(GL_TEXTURE_2D) glBindTexture( GL_TEXTURE_2D, self._text_box._current_glfont.atlas.texid) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) glTranslatef(self._position[0], -self._position[1], 0) glPushMatrix() ### getLineInfoByIndex = self._text_document.getLineInfoByIndex active_text_style_dlist = self._current_font_display_lists.get cell_width, cell_height = self._cell_size num_cols, num_rows = self._shape line_spacing = self._text_box._getPixelTextLineSpacing() line_count = self.getRowCountWithText() glColor4f(*self._text_box._toRGBA(self._font_color)) for r in range(line_count): cline, line_length, line_display_list, line_ords = getLineInfoByIndex( r) if line_display_list[0] == 0: line_display_list[0:line_length] = [ active_text_style_dlist(c) for c in line_ords] glTranslatef(cline._trans_left * cell_width, - int(line_spacing/2.0 + cline._trans_top * cell_height), 0) glCallLists(line_length, GL_UNSIGNED_INT, line_display_list[0:line_length].ctypes) cline._trans_left = 0 glTranslatef(-line_length * cell_width - cline._trans_left * cell_width, - cell_height + int(line_spacing/2.0 + cline._trans_top * cell_height), 0) ### glPopMatrix() glBindTexture(GL_TEXTURE_2D, 0) glDisable(GL_TEXTURE_2D) glEndList() self._text_dlist = dl_index glCallList(self._text_dlist)
def _text_glyphs_gl(self): if not self._text_dlist: dl_index = glGenLists(1) glNewList(dl_index, GL_COMPILE) #stime=getTime() #self._text_box._te_start_gl() ### glActiveTexture(GL_TEXTURE0) glEnable( GL_TEXTURE_2D ) glBindTexture( GL_TEXTURE_2D, self._text_box._current_glfont.atlas.texid) glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE ) glTranslatef( self._position[0], -self._position[1], 0 ) glPushMatrix() ### hjust=self._horz_justification vjust=self._vert_justification pad_left_proportion=0 pad_top_proportion=0 if hjust=='center': pad_left_proportion=0.5 elif hjust=='right': pad_left_proportion=1.0 if vjust=='center': pad_top_proportion=0.5 elif vjust=='bottom': pad_top_proportion=1.0 getLineInfoByIndex=self._text_document.getLineInfoByIndex active_text_style_dlist=self._current_font_display_lists.get cell_width,cell_height=self._cell_size num_cols,num_rows=self._shape line_spacing=self._text_box._getPixelTextLineSpacing() line_count=min(num_rows,self._text_document.getParsedLineCount()) apply_padding=pad_left_proportion or (pad_top_proportion and line_count>1) trans_left=0 trans_top=0 glColor4f(*self._text_box._toRGBA(self._font_color)) for r in range(line_count): line_length,line_display_list,line_ords=getLineInfoByIndex(r) if line_display_list[0]==0: line_display_list[0:line_length]=[active_text_style_dlist(c) for c in line_ords] if apply_padding: empty_cell_count=num_cols-line_length empty_line_count=num_rows-line_count trans_left=int((empty_cell_count+1)*pad_left_proportion)*cell_width trans_top=int(empty_line_count*pad_top_proportion)*cell_height glTranslatef(trans_left,-int(line_spacing/2.0+trans_top),0) glCallLists(line_length,GL_UNSIGNED_INT,line_display_list[0:line_length].ctypes) glTranslatef(-line_length*cell_width-trans_left,-cell_height+int(line_spacing/2.0+trans_top),0) ### glPopMatrix() glBindTexture( GL_TEXTURE_2D,0 ) glDisable( GL_TEXTURE_2D ) glEndList() #print 'GL_TIME: %.3f'%((etime-stime)*1000.0) self._text_dlist=dl_index glCallList(self._text_dlist)