示例#1
0
 def quick_change(self, new_string):
     """Method for quickly changing some characters within a previously
 generated String. i.e. for changing digits in a readout etc.
 
 NB: 1. if you use a variable width font there will be some distortion
 as characters are stretched or squashed to the original character's
 dimensions. 2. there is no account made of new line characters (TODO)
 3. you must make the original string long enough to fit any additional
 characters you add to new_string 4. you must make sure the Font as
 used for the String.__init__ contains all the glyphs you may need for
 subsequent changes.
 """
     import ctypes
     if new_string != self.string:
         new_string = new_string + ' ' * (len(self.string) -
                                          len(new_string))
         trunc_string = new_string[:self.maxlen]  #chop to length
         for i, c in enumerate(trunc_string):
             if c != self.string[i]:
                 stride = 8
                 offset = 6
                 texc = self.font.glyph_table[c][2]
                 for j, tc in enumerate(
                         texc):  #patch values directly into array_buffer
                     for k in [0, 1]:
                         self.buf[0].array_buffer[(i * 4 + j),
                                                  (offset + k)] = tc[k]
                 uvmod = True
         self.buf[0]._select()  #then just call glBufferData
         opengles.glBufferSubData(
             GL_ARRAY_BUFFER, 0, self.buf[0].array_buffer.nbytes,
             self.buf[0].array_buffer.ctypes.data_as(
                 ctypes.POINTER(ctypes.c_float)))
         self.string = new_string
示例#2
0
    def re_init(self, pts=None, texcoords=None, normals=None, offset=0):
        """Only reset the opengl buffer variables: vertices, tex_coords, normals
    (which will not be generated if not supplied)
    **NB this method will go horribly wrong if you change the size of the
    arrays supplied in the argument as the opengles buffers are reused
    At least one of pts, texcoords or normals must be a list**
    This method will run faster if the new data is passed as numpy 2D arrays.

      Arguments:
        *pts*
          numpy 2D array or list of (x,y,z) tuples, default None
        *texcoords*
          numpy 2D array or list of (u,v) tuples, default None
        *normals*
          numpy 2D array or list of (x,y,z) tuples, default None
        *offset*
          number of vertices offset from the start of vertices, default 0
    """
        if self.disp is None:
            return  # can't re_init until after initial drawing!
        if pts is not None:
            n = len(pts)
            if not (isinstance(pts, np.ndarray)):
                pts = np.array(pts)
            self.array_buffer[offset:(offset + n), 0:3] = pts[:, :]
        if normals is not None:
            n = len(normals)
            if not (isinstance(normals, np.ndarray)):
                normals = np.array(normals)
            self.array_buffer[offset:(offset + n), 3:6] = normals[:, :]
        if texcoords is not None:
            n = len(texcoords)
            if not (isinstance(texcoords, np.ndarray)):
                texcoords = np.array(texcoords)
            self.array_buffer[offset:(offset + n), 6:8] = texcoords[:, :]
        try:
            getattr(self, "vbuf")
        except:
            self.load_opengl(
            )  # vbuf and ebuf need to exist prior to _select()
        self._select()
        opengles.glBufferSubData(
            GL_ARRAY_BUFFER, 0, self.array_buffer.nbytes,
            self.array_buffer.ctypes.data_as(ctypes.POINTER(ctypes.c_float)))
示例#3
0
文件: Buffer.py 项目: tipam/pi3d
  def re_init(self, pts=None, texcoords=None, normals=None, offset=0):
    """Only reset the opengl buffer variables: vertices, tex_coords, normals
    (which will not be generated if not supplied)
    **NB this method will go horribly wrong if you change the size of the
    arrays supplied in the argument as the opengles buffers are reused
    At least one of pts, texcoords or normals must be a list**
    This method will run faster if the new data is passed as numpy 2D arrays.

      Arguments:
        *pts*
          numpy 2D array or list of (x,y,z) tuples, default None
        *texcoords*
          numpy 2D array or list of (u,v) tuples, default None
        *normals*
          numpy 2D array or list of (x,y,z) tuples, default None
        *offset*
          number of vertices offset from the start of vertices, default 0
    """
    if self.disp is None:
      return # can't re_init until after initial drawing!
    if pts is not None:
      n = len(pts)
      if not (isinstance(pts, np.ndarray)):
        pts = np.array(pts)
      self.array_buffer[offset:(offset + n), 0:3] = pts[:,:]
    if normals is not None:
      n = len(normals)
      if not (isinstance(normals, np.ndarray)):
        normals = np.array(normals)
      self.array_buffer[offset:(offset + n), 3:6] = normals[:,:]
    if texcoords is not None:
      n = len(texcoords)
      if not (isinstance(texcoords, np.ndarray)):
        texcoords = np.array(texcoords)
      self.array_buffer[offset:(offset + n), 6:8] = texcoords[:,:]
    try:
        getattr(self, "vbuf")
    except:
        self.load_opengl() # vbuf and ebuf need to exist prior to _select()
    self._select()
    opengles.glBufferSubData(GL_ARRAY_BUFFER, 0,
                      self.array_buffer.nbytes,
                      self.array_buffer.ctypes.data_as(ctypes.POINTER(ctypes.c_float)))