Example #1
0
  def __setup_data_buffer(self):
    data_ptr = ct.cast( np.ctypeslib.as_ctypes(self.__data),
        ct.POINTER(ct.c_float) )

    self.__data_buffer = util.buffer()
    gl.glBindBuffer(gl.GL_TEXTURE_BUFFER, self.__data_buffer.value)
    gl.glBufferData(gl.GL_TEXTURE_BUFFER, 
        ct.sizeof(ct.c_float)*self.__data.size,
        data_ptr,
        gl.GL_STATIC_DRAW)

    if self.__data_texture is None:
      self.__data_texture = util.texture()
    gl.glActiveTexture(gl.GL_TEXTURE0)
    gl.glBindTexture(gl.GL_TEXTURE_BUFFER, self.__data_texture.value)

    gl.glTexBuffer(gl.GL_TEXTURE_BUFFER, gl.GL_R32F, 
        self.__data_buffer.value)

    self.__data_altered = False
Example #2
0
  def __setup_geometry_buffer(self):
    data_buffer = ((ct.c_float*3)*36)()
    # {{{ vertex data for cube
    v0 = ( .5, .5, .5 )
    v1 = ( -.5, .5, .5 )
    v2 = ( -.5, -.5, .5 )
    v3 = ( .5, -.5, .5 )
    v4 = ( .5, .5, -.5 )
    v5 = ( -.5, .5, -.5 )
    v6 = ( -.5, -.5, -.5 )
    v7 = ( .5, -.5, -.5 )

    data_buffer[0:3] = (v4, v0, v7)
    data_buffer[3:6] = (v0, v3, v7)
    data_buffer[6:9] = (v0, v1, v2)
    data_buffer[9:12] = (v0, v2, v3)
    data_buffer[12:15] = (v5, v1, v0)
    data_buffer[15:18] = (v5, v0, v4)
    data_buffer[18:21] = (v3, v6, v7)
    data_buffer[21:24] = (v3, v2, v6)
    data_buffer[24:27] = (v2, v1, v6)
    data_buffer[27:30] = (v6, v1, v5)
    data_buffer[30:33] = (v4, v6, v5)
    data_buffer[33:36] = (v7, v6, v4)
    # }}}

    data_ptr = ct.cast(ct.pointer(data_buffer),
        ct.POINTER(ct.c_float))

    # create GL buffer
    self.__geom_buffer = util.buffer()
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.__geom_buffer.value)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, ct.sizeof(data_buffer),
        data_ptr,
        gl.GL_STATIC_DRAW)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)