Framebuffer

FrameBuffer

class arcade.gl.Framebuffer(ctx: Context, *, color_attachments=None, depth_attachment=None)[source]

Bases: object

An offscreen render target also called a Framebuffer Object in OpenGL. This implementation is using texture attachments. When creating a Framebuffer we supply it with textures we want our scene rendered into. The advantage of using texture attachments is the ability we get to keep working on the contents of the framebuffer.

The best way to create framebuffer is through arcade.gl.Context.framebuffer():

# Create a 100 x 100 framebuffer with one attachment
ctx.framebuffer(color_attachments=[ctx.texture((100, 100), components=4)])

# Create a 100 x 100 framebuffer with two attachments
# Shaders can be configured writing to the different layers
ctx.framebuffer(
    color_attachments=[
        ctx.texture((100, 100), components=4),
        ctx.texture((100, 100), components=4),
    ]
)
Parameters
  • ctx (Context) – The context this framebuffer belongs to

  • color_attachments (List[arcade.gl.Texture]) – List of color attachments.

  • depth_attachment (arcade.gl.Texture) – A depth attachment (optional)

activate()[source]

Context manager for binding the framebuffer.

Unlike the default context manager in this class this support nested framebuffer binding.

clear(color=(0.0, 0.0, 0.0, 0.0), *, depth: float = 1.0, normalized: bool = False)[source]

Clears the framebuffer:

# Clear framebuffer using the color red in normalized form
fbo.clear(color=(1.0, 0.0, 0.0, 1.0), normalized=True)
# Clear the framebuffer using arcade's colors (not normalized)
fb.clear(color=arcade.color.WHITE)

If the background color is an RGB value instead of RGBA` we assume alpha value 255.

Parameters
  • color (tuple) – A 3 or 4 component tuple containing the color

  • depth (float) – Value to clear the depth buffer (unused)

  • normalized (bool) – If the color values are normalized or not

property color_attachments: List[arcade.gl.texture.Texture]

A list of color attachments

Type

list of arcade.gl.Texture

property ctx: Context

The context this object belongs to.

Type

arcade.gl.Context

delete()[source]

Destroy the underlying OpenGL resource. Don’t use this unless you know exactly what you are doing.

static delete_glo(ctx, framebuffer_id)[source]

Destroys the framebuffer object

Parameters
  • ctx – OpenGL context

  • framebuffer_id – Framebuffer to destroy (glo)

property depth_attachment: arcade.gl.texture.Texture

Depth attachment

Type

arcade.gl.Texture

property depth_mask: bool

Get or set the depth mask (default: True). It determines if depth values should be written to the depth texture when depth testing is enabled.

The depth mask value is persistent all will automatically be applies every time the framebuffer is bound.

Type

bool

property glo: ctypes.c_uint

The OpenGL id/name of the framebuffer

Type

GLuint

property height: int

The height of the framebuffer in pixels

Type

int

is_default = False

Is this the default framebuffer? (window buffer)

read(*, viewport=None, components=3, attachment=0, dtype='f1') bytearray[source]

Read framebuffer pixels

Parameters
  • Tuple[int,int,int,int] (viewport) – The x, y, with, height to read

  • attachment (int) – The attachment id to read from

  • dtype (str) – The data type to read

Returns

pixel data as a bytearray

resize()[source]

Detects size changes in attachments. This will reset the viewport to 0, 0, width, height.

property samples: int

Number of samples (MSAA)

Type

int

property size: Tuple[int, int]

Size as a (w, h) tuple

Type

tuple (int, int)

use(*, force: bool = False)[source]

Bind the framebuffer making it the target of all redering commands

Parameters

force (bool) – Force the framebuffer binding even if the system already believes it’s already bound.

property viewport: Tuple[int, int, int, int]

Get or set the framebuffer’s viewport. The viewport parameter are (x, y, width, height). It determines what part of the framebuffer should be redered to. By default the viewport is (0, 0, width, height).

The viewport value is persistent all will automatically be applies every time the framebuffer is bound.

Two or four integer values can be assigned:

# Explicitly set x, y, width, height
fb.viewport = 100, 100, 200, 200
# Implies 0, 0, 100, 100
fb.viewport = 100, 100
property width: int

The width of the framebuffer in pixels

Type

int

DefaultFrameBuffer

class arcade.gl.framebuffer.DefaultFrameBuffer(ctx: Context)[source]

Bases: arcade.gl.framebuffer.Framebuffer

Represents the default framebuffer

is_default = True

Is this the default framebuffer? (window buffer)