예제 #1
0
 def _bind_texture(self, i):
     gl.glActiveTexture((gl.GL_TEXTURE0, gl.GL_TEXTURE1, gl.GL_TEXTURE2)[i])
     gl.glEnable(gl.GL_TEXTURE_2D)
     gl.glBindTexture(gl.GL_TEXTURE_2D, self.texture[i].id)
     gl.glTexEnvf(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_COMBINE)
     gl.glTexEnvf(gl.GL_TEXTURE_ENV, gl.GL_COMBINE_ALPHA, gl.GL_REPLACE if i == 0 else gl.GL_ADD)
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
파일: graphics.py 프로젝트: Knio/miru
    def set_state(self):
        gl.glPushAttrib( gl.GL_ENABLE_BIT )
        gl.glBindTexture( gl.GL_TEXTURE_2D, self.texture.id )
        gl.glEnable( gl.GL_POINT_SPRITE )
        gl.glDisable( gl.GL_LIGHTING )

        if self.attenuate:
            quadratic = (gl.GLfloat * 3)()
            quadratic[:] = (1.0, 0.0, 0.01)
            gl.glPointParameterfv( gl.GL_POINT_DISTANCE_ATTENUATION, quadratic )

        max_size = gl.GLfloat()
        gl.glGetFloatv( gl.GL_POINT_SIZE_MAX, max_size )

        gl.glPointParameterf( gl.GL_POINT_FADE_THRESHOLD_SIZE, 60.0 )

        gl.glPointParameterf( gl.GL_POINT_SIZE_MIN, 1.0 )
        gl.glPointParameterf( gl.GL_POINT_SIZE_MAX, max_size )

        gl.glTexEnvf( gl.GL_POINT_SPRITE, gl.GL_COORD_REPLACE, gl.GL_TRUE )
        gl.glPointSize( self.point_size )
예제 #5
0
    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)