本文整理汇总了Python中bgl.glReadPixels方法的典型用法代码示例。如果您正苦于以下问题:Python bgl.glReadPixels方法的具体用法?Python bgl.glReadPixels怎么用?Python bgl.glReadPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bgl
的用法示例。
在下文中一共展示了bgl.glReadPixels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_opengl_image
# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import glReadPixels [as 别名]
def render_opengl_image(image_name, cam, point_size):
draw_manager = DrawManager.get_singleton()
coords, colors = draw_manager.get_coords_and_colors()
scene = bpy.context.scene
render = bpy.context.scene.render
width = render.resolution_x
height = render.resolution_y
# TODO Provide an option to render from the 3D view perspective
# width = bpy.context.region.width
# height = bpy.context.region.height
offscreen = gpu.types.GPUOffScreen(width, height)
with offscreen.bind():
bgl.glPointSize(point_size)
#bgl.glClear(bgl.GL_COLOR_BUFFER_BIT)
#bgl.glClear(bgl.GL_DEPTH_BUFFER_BIT)
view_matrix = cam.matrix_world.inverted()
projection_matrix = cam.calc_matrix_camera(
bpy.context.evaluated_depsgraph_get(),
x=width,
y=height)
perspective_matrix = projection_matrix @ view_matrix
gpu.matrix.load_matrix(perspective_matrix)
gpu.matrix.load_projection_matrix(Matrix.Identity(4))
shader = gpu.shader.from_builtin('3D_FLAT_COLOR')
shader.bind()
batch = batch_for_shader(shader, "POINTS", {"pos": coords, "color": colors})
batch.draw(shader)
buffer = bgl.Buffer(bgl.GL_BYTE, width * height * 4)
bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer)
offscreen.free()
image = create_image_lazy(image_name, width, height)
copy_buffer_to_pixel(buffer, image)