本文整理匯總了Python中OpenGL.arrays.vbo.VBO屬性的典型用法代碼示例。如果您正苦於以下問題:Python vbo.VBO屬性的具體用法?Python vbo.VBO怎麽用?Python vbo.VBO使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類OpenGL.arrays.vbo
的用法示例。
在下文中一共展示了vbo.VBO屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: paintGL
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def paintGL(self):
"""Paint the scene.
"""
self.update_buffer()
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
if (np.mod(self.enctime,4)==0 or ENC==0 or 1):
if (1):
gl.glBindTexture(gl.GL_TEXTURE_2D, self.idtexgl)
gl.glEnable(gl.GL_TEXTURE_2D)
gl.glBegin(gl.GL_QUADS)
gl.glTexCoord2f(0.0, 0.0)
gl.glVertex2f(0, 0);
gl.glTexCoord2f(1.0, 0.0)
gl.glVertex2f( 1.0, 0);
gl.glTexCoord2f(1.0, 1.0)
gl.glVertex2f( 1.0, 1.0);
gl.glTexCoord2f(0.0, 1.0)
gl.glVertex2f(0, 1.0);
gl.glEnd()
else:
gl.glColor4d(0.5,0.7,0.8,0.04)
gl.glEnable(gl.GL_BLEND)
gl.glBlendEquationSeparate( gl.GL_FUNC_ADD, gl.GL_FUNC_ADD);
gl.glBlendFuncSeparate(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_ONE, gl.GL_ONE, gl.GL_ZERO);
# bind the VBO
self.glbuf.bind()
# tell OpenGL that the VBO contains an array of vertices
gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
# these vertices contain 2 simple precision coordinates
gl.glVertexPointer(2, gl.GL_FLOAT, 0, self.glbuf)
# draw "count" points from the VBO
gl.glDrawArrays(gl.GL_POINTS, 0, self.count)
self.update()
示例2: __init__
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def __init__(self, vertex, fragment, total_vertex, texture=None):
"""Funcion constructora"""
if isinstance(vertex, vbo.VBO) and isinstance(fragment, vbo.VBO):
if isinstance(total_vertex, types.IntType):
self.vertex = vertex
self.fragment = fragment
self.totalVertex = total_vertex
self.texture = texture
if self.texture is None:
self.texlen = 0
else:
self.texlen = len(self.texture)
else:
raise Exception("total_vertex debe ser del tipo int")
else:
raise Exception(
"vertex y fragment deben ser del tipo VBO (OpenGL.arrays.vbo)")
示例3: updateColorChoiceBuffers
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def updateColorChoiceBuffers(self):
#Remake color and vertex buffers
if self.colorPosVBO:
self.colorPosVBO.delete()
if self.colorColorVBO:
self.colorColorVBO.delete()
N = len(self.colorChoices)
Pos = np.zeros((N, 3))
Colors = np.zeros((N, 3))
i = 0
for idx in self.colorChoices:
Pos[i, :] = self.mesh.VPos[idx, :]
Colors[i, :] = self.colorChoices[idx]/255.0
i += 1
self.colorPosVBO = vbo.VBO(np.array(Pos, dtype=np.float32))
self.colorColorVBO = vbo.VBO(np.array(Colors, dtype=np.float32))
示例4: _draw_pixels
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def _draw_pixels(self, frame_buffer=0):
""" Draw stars as pixels.
frame_buffer: int
OpenGL frame buffer id.
"""
glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer)
self._bind_star_vbo()
# Choose appropriate shader program
if self.use_adaptative_opacity:
glUseProgram(self._ao_shader_program)
glUniform1f(glGetUniformLocation(self._ao_shader_program, 'opacity_factor'),
self._calc_opacity_factor())
else:
glUseProgram(0)
# Draw "count" points from the VBO
glDrawArrays(GL_POINTS, 0, self._star_count)
示例5: add_array_buffer
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def add_array_buffer(self, format, vbo):
"""
Register a vbo in the VAO. This can be called multiple times.
This can be one or multiple buffers (interleaved or not)
:param format: The format of the buffer
:param vbo: The vbo object
"""
if not isinstance(vbo, VBO):
raise VAOError("vbo parameter must be an OpenGL.arrays.vbo.VBO instance")
# Check that the buffer target is sane
if vbo.target not in ["GL_ARRAY_BUFFER", "GL_TRANSFORM_FEEDBACK_BUFFER"]:
raise VAOError("VBO must have target GL_ARRAY_BUFFER or GL_TRANSFORM_FEEDBACK_BUFFER, "
"not {}".format(vbo.target))
self.array_buffer_map[id(vbo)] = ArrayBuffer(format, vbo)
示例6: set_element_buffer
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def set_element_buffer(self, format, vbo):
"""
Set the index buffer for this VAO
:param format: The format of the element buffer
:param vbo: the vbo object
"""
if not isinstance(vbo, VBO):
raise VAOError("vbo parameter must be an OpenGL.arrays.vbo.VBO instance")
if vbo.target not in ["GL_ELEMENT_ARRAY_BUFFER"]:
raise VAOError("Element buffers must have target=GL_ELEMENT_ARRAY_BUFFER")
if format not in [GL.GL_UNSIGNED_INT]:
raise VAOError("Format can currently only be GL_UNSIGNED_INT")
self.element_buffer = ArrayBuffer(format, vbo)
示例7: map_buffer
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def map_buffer(self, vbo, attrib_name, components):
"""
Map parts of the vbos to an attribute name.
This can be called multiple times to describe hos the buffers map to attribute names.
If the same vbo is passed more than once it must be an interleaved buffer.
:param vbo: The vbo
:param attrib_name: Name of the attribute in the shader
:param components: Number of components (for example 3 for a x, y, x position)
"""
if not isinstance(vbo, VBO):
raise VAOError("vbo parameter must be an OpenGL.arrays.vbo.VBO instance")
ab = self.array_buffer_map.get(id(vbo))
if not ab:
raise VAOError("VBO {} not previously added as an array map. "
"Forgot to call add_arrray_buffer(..)?".format(id(vbo)))
# FIXME: Determine byte size based on data type in VBO
offset = ab.stride
ab.stride += components * type_size(ab.format)
am = ArrayMapping(ab, attrib_name, components, offset)
self.array_mapping.append(am)
self.array_mapping_map[attrib_name] = am
示例8: points_random_3d
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def points_random_3d(count, range_x=(-10.0, 10.0), range_y=(-10.0, 10.0), range_z=(-10.0, 10.0), seed=None):
"""
Generates random positions
:param count: Number of points
:param range_x: min-max range for x axis
:param range_y: min-max range for y axis
:param range_z: min-max range for z axis
:param seed: The random seed to be used
"""
random.seed(seed)
def gen():
for i in range(count):
yield random.uniform(*range_x)
yield random.uniform(*range_y)
yield random.uniform(*range_z)
data = numpy.fromiter(gen(), count=count * 3, dtype=numpy.float32)
pos = VBO(data)
vao = VAO("geometry:points_random_3d", mode=GL.GL_POINTS)
vao.add_array_buffer(GL.GL_FLOAT, pos)
vao.map_buffer(pos, "in_position", 3)
vao.build()
return vao
示例9: initializeGL
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def initializeGL(self):
super().initializeGL('sb05a.shaders')
v = np.array([
0.25, -0.25, 0.50, 1.0, 0.0, 0.0,
-0.25, -0.25, 0.50, 0.0, 1.0, 0.0,
0.00, 0.25, 0.50, 0.0, 0.0, 1.0], dtype=np.float32)
vertex_b = vbo.VBO(v)
vertex_b.bind()
glVertexAttribPointer(self.program.A['position_vs'], 3, GL_FLOAT, GL_FALSE, 24, None)
glEnableVertexAttribArray(0)
glVertexAttribPointer(self.program.A['color_vs'], 3, GL_FLOAT, GL_FALSE, 24, ctypes.c_void_p(12))
glEnableVertexAttribArray(1)
print('initialization done')
示例10: __enter__
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def __enter__(self):
# Create the VBO
vertices = np.array([
[1, 1, 0, 1, 1],
[1, -1, 0, 1, -1],
[-1, -1, 0, -1, -1],
[-1, 1, 0, -1, 1]], dtype='f')
self.vertexPositions = vbo.VBO(vertices)
# Create the index buffer object
indices = np.array([[0, 1, 2], [0, 2, 3]], dtype=np.int32)
self.index_positions = vbo.VBO(indices,
target=GL.GL_ELEMENT_ARRAY_BUFFER)
self.shader = shaders.compileProgram(self.vertex_shader,
self.fragment_shader)
self.create_texture()
uConnectedLoc = GL.glGetUniformLocation(self.shader, 'connected')
GL.glUniform1i(uConnectedLoc, 1 if self.connected else 0)
return self
示例11: __get_position_index
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def __get_position_index(self, point):
"""
Get the index in the point VBO for a given Point2 coordinate
:type point: pcbre.matrix.Point2
:param point:
:return:
"""
norm_pos = point.intTuple()
try:
return self.__position_lookup[norm_pos]
except KeyError:
self.__position_lookup[norm_pos] = len(self.__position_list)
self.__position_list.append(norm_pos)
self.__vert_vbo_current = False
return self.__position_lookup[norm_pos]
示例12: __build_trace
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def __build_trace(self):
# Update trace VBO
self.working_array["vertex"][0] = (0,0)
self.working_array["ptid"][0] = 0
self.working_array["vertex"][1] = (0,0)
self.working_array["ptid"][1] = 1
end = Vec2(1,0)
for i in range(0, NUM_ENDCAP_SEGMENTS):
theta = math.pi * i/(NUM_ENDCAP_SEGMENTS - 1) + math.pi/2
m = rotate(theta).dot(end.homol())
self.working_array["vertex"][2 + i] = m[:2]
self.working_array["ptid"][2 + i] = 0
self.working_array["vertex"][2 + i + NUM_ENDCAP_SEGMENTS] = -m[:2]
self.working_array["ptid"][2 + i + NUM_ENDCAP_SEGMENTS] = 1
# Force data copy
self.trace_vbo.copied = False
self.trace_vbo.bind()
示例13: __init__
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def __init__(self, **kwds):
GLGraphicsItem.__init__(self)
glopts = kwds.pop('glOptions', 'additive')
self.setGLOptions(glopts)
self.pos = []
self.size = 10
self.color = [1.0,1.0,1.0,0.5]
self.pxMode = True
#self.vbo = {} ## VBO does not appear to improve performance very much.
self.setData(**kwds)
示例14: initializeGL
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def initializeGL(self):
## Generate texture for rendering points
w = 64
def fn(x,y):
r = ((x-w/2.)**2 + (y-w/2.)**2) ** 0.5
return 255 * (w/2. - np.clip(r, w/2.-1.0, w/2.))
pData = np.empty((w, w, 4))
pData[:] = 255
pData[:,:,3] = np.fromfunction(fn, pData.shape[:2])
#print pData.shape, pData.min(), pData.max()
pData = pData.astype(np.ubyte)
if getattr(self, "pointTexture", None) is None:
self.pointTexture = glGenTextures(1)
glActiveTexture(GL_TEXTURE0)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, self.pointTexture)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pData.shape[0], pData.shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, pData)
self.shader = shaders.getShaderProgram('pointSprite')
#def getVBO(self, name):
#if name not in self.vbo:
#self.vbo[name] = vbo.VBO(getattr(self, name).astype('f'))
#return self.vbo[name]
#def setupGLState(self):
#"""Prepare OpenGL state for drawing. This function is called immediately before painting."""
##glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ## requires z-sorting to render properly.
#glBlendFunc(GL_SRC_ALPHA, GL_ONE)
#glEnable( GL_BLEND )
#glEnable( GL_ALPHA_TEST )
#glDisable( GL_DEPTH_TEST )
##glEnable( GL_POINT_SMOOTH )
##glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)
##glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, (0, 0, -1e-3))
##glPointParameterfv(GL_POINT_SIZE_MAX, (65500,))
##glPointParameterfv(GL_POINT_SIZE_MIN, (0,))
示例15: initializeGL
# 需要導入模塊: from OpenGL.arrays import vbo [as 別名]
# 或者: from OpenGL.arrays.vbo import VBO [as 別名]
def initializeGL(self):
"""Initialize OpenGL, VBOs, upload data on the GPU, etc.
"""
# background color
gl.glClearColor(0,0,0,0)
# create a Vertex Buffer Object with the specified data
self.vbo = glvbo.VBO(self.data)