def render_opengl_image(image_name, cam, coords, colors, point_size):
    """Render the given coordinates with :code:`OpenGL`."""

    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():
        gpu.state.point_size_set(point_size)

        previous_depth_mask_value = gpu.state.depth_mask_get()
        previous_depth_test_value = gpu.state.depth_test_get()
        gpu.state.depth_mask_set(True)
        gpu.state.depth_test_set("LESS_EQUAL")

        frame_buffer = gpu.state.active_framebuffer_get()
        frame_buffer.clear(color=(0.0, 0.0, 0.0, 0.0), depth=1.0)

        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)

        gpu.state.depth_mask_set(previous_depth_mask_value)
        gpu.state.depth_test_set(previous_depth_test_value)

        buffer = frame_buffer.read_color(0, 0, width, height, 4, 0, "UBYTE")

    offscreen.free()

    image = _create_image_lazy(image_name, width, height)
    _copy_buffer_to_pixel(buffer, image, width, height)
Render the given coordinates with :code:`OpenGL`.
photogrammetry_importer/opengl/utility.py