本文整理汇总了Python中OpenGL.arrays.vbo.VBO.set_array方法的典型用法代码示例。如果您正苦于以下问题:Python VBO.set_array方法的具体用法?Python VBO.set_array怎么用?Python VBO.set_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenGL.arrays.vbo.VBO
的用法示例。
在下文中一共展示了VBO.set_array方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RenderBatch
# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import set_array [as 别名]
class RenderBatch(object):
def __init__(self, draw_type=GL_QUADS):
self.count = 0
self.color_data = []
self.position_data = []
self.color_buffer = VBO(np.array([]))
self.position_buffer = VBO(np.array([]))
self.draw_type = draw_type
def draw2d(self, points, color=(0, 0, 0, 1), rotation=0, center=(0, 0)):
n = len(points)
self.count += n
if not isinstance(color[0], (tuple, list)):
color = [color]*n
if rotation:
transform = psi.calc.rotation_matrix(rotation)
temp = np.array(points) - center
temp = transform.dot(temp.T).T + center
points = temp.tolist()
self.color_data.extend(color)
self.position_data.extend(points)
def clear(self):
self.position_data = []
self.color_data = []
self.count = 0
def render(self):
self.color_buffer.set_array(np.array(self.color_data, dtype='float32'))
self.position_buffer.set_array(np.array(self.position_data, dtype='float32'))
self.color_buffer.bind()
glColorPointer(4, GL_FLOAT, 0, self.color_buffer)
self.position_buffer.bind()
glVertexPointer(2, GL_FLOAT, 0, self.position_buffer)
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_COLOR_ARRAY)
glDrawArrays(self.draw_type, 0, self.count)
glDisableClientState(GL_COLOR_ARRAY)
glDisableClientState(GL_VERTEX_ARRAY)
示例2: RenderBatchOpt
# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import set_array [as 别名]
class RenderBatchOpt(object):
def __init__(self, draw_type=GL_QUADS):
self.count = 0
self.color_buffer = VBO(np.array([]))
self.vertex_buffer = VBO(np.array([]))
self.draw_type = draw_type
def draw2d(self, points, color=(0, 0, 0, 1), rotation=0, center=(0, 0)):
n = points.shape[0]
self.count += n
if rotation:
transform = psi.calc.rotation_matrix(rotation)
temp = points - center
temp = transform.dot(temp.T).T + center
points = temp.tolist()
self.color_buffer.set_array(color)
self.vertex_buffer.set_array(points)
def clear(self):
self.color_buffer.set_array(np.array([]))
self.vertex_buffer.set_array(np.array([]))
self.count = 0
def render(self):
self.color_buffer.bind()
glColorPointer(4, GL_FLOAT, 0, self.color_buffer)
self.vertex_buffer.bind()
glVertexPointer(2, GL_FLOAT, 0, self.vertex_buffer)
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_COLOR_ARRAY)
glDrawArrays(self.draw_type, 0, self.count)
glDisableClientState(GL_COLOR_ARRAY)
glDisableClientState(GL_VERTEX_ARRAY)
示例3: RectAlignmentControllerView
# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import set_array [as 别名]
#.........这里部分代码省略.........
delta = (b-a).norm()
normal = Point2(rotate(math.pi / 2)[:2,:2].dot(delta))
if always_above:
if numpy.cross(Vec2(1,0), normal) > 0:
normal = -normal
res = numpy.array([
a + normal * 8,
a + normal * 20,
a + normal * 15,
b + normal * 15,
b + normal * 8,
b + normal * 20,
])
return res
def render(self, vs):
self.viewState = vs
disabled = not self.active or self.model_overall.view_mode
# Perimeter is defined by the first 4 handles
self.vbo_per_dim_ar["vertex"][:4] = [self.im2V(pt) for pt in self.model.align_handles[:4]]
# Generate the dimension lines. For ease of use, we always draw the dim-lines above when dims are manual
# or below when dims are unlocked
self.vbo_per_dim_ar["vertex"][4:10] = self.gen_dim(0, not self.model.dims_locked)
self.vbo_per_dim_ar["vertex"][10:16] = self.gen_dim(2, not self.model.dims_locked)
self.vbo_per_dim.set_array(self.vbo_per_dim_ar)
# Ugh..... PyOpenGL isn't smart enough to bind the data when it needs to be copied
with self.vbo_per_dim:
self.vbo_per_dim.copy_data()
GL.glDisable(GL.GL_BLEND)
# ... and draw the perimeter
with self.vao_per_dim, self.prog:
GL.glUniformMatrix3fv(self.mat_loc, 1, True, self.viewState.glWMatrix.astype(numpy.float32))
# Draw the outer perimeter
if disabled:
GL.glUniform4f(self.col_loc, 0.8, 0.8, 0.8, 1)
else:
GL.glUniform4f(self.col_loc, 0.8, 0.8, 0, 1)
GL.glDrawArrays(GL.GL_LINE_LOOP, 0, 4)
# Draw the dimensions
GL.glUniform4f(self.col_loc, 0.8, 0.0, 0.0, 1)
GL.glDrawArrays(GL.GL_LINES, 4, 6)
GL.glUniform4f(self.col_loc, 0.0, 0.0, 0.8, 1)
GL.glDrawArrays(GL.GL_LINES, 10, 6)
if disabled:
return
# Now draw a handle at each corner
with self.vao_handles, self.prog:
for n, i in enumerate(self.model.align_handles):