Teek API Documentation

GPU-resident pixel buffer backed by an SDL_Texture.

Textures are created through a Renderer, not directly instantiated. Use the convenience constructors .streaming and .target, or call Renderer#create_texture directly.

C-defined methods

These are defined in the C extension (sdl2surface.c):

Inherits: Object

Class Methods

from_file(renderer, path)

Load an image file into a GPU texture via SDL2_image.

Parameters
  • renderer Renderer — the renderer that owns this texture
  • path String — path to an image file (PNG, JPG, BMP, etc.)

Returns Texture

Example
sprite = Teek::SDL2::Texture.from_file(renderer, "assets/player.png")
renderer.copy(sprite)

streaming(renderer, width, height)

Create a streaming texture (lockable, CPU-updatable).

Parameters
  • renderer Renderer — the renderer that owns this texture
  • width Integer — width in pixels
  • height Integer — height in pixels

Returns Texture

Example
tex = Teek::SDL2::Texture.streaming(renderer, 256, 224)
tex.update(rgba_string)

target(renderer, width, height)

Create a target texture (can be rendered to via SDL_SetRenderTarget).

Parameters
  • renderer Renderer — the renderer that owns this texture
  • width Integer — width in pixels
  • height Integer — height in pixels

Returns Texture

Instance Methods

blend_mode

Returns Integer — current blend mode

blend_mode=(mode)

Set the blend mode used when this texture is drawn via Renderer#copy.

Built-in modes (Symbol): - :none — no blending (copy pixels as-is) - :blend — alpha blending (default for TTF-rendered textures) - :add — additive blending - :mod — color modulation

Pass an Integer from SDL2.compose_blend_mode for custom blend modes.

Parameters
  • mode Symbol, Integer — blend mode

Returns Symbol, Integer — the mode that was set

Example
# Inverse/invert effect (shows opposite of background)
inverse = Teek::SDL2.compose_blend_mode(
  :one_minus_dst_color, :one_minus_src_alpha, :add,
  :zero, :one, :add
)
white_text = font.render_text("Hello", 255, 255, 255)
white_text.blend_mode = inverse

destroy

Free this texture’s GPU resources.

Returns void

destroyed?

Returns Boolean — whether this texture has been destroyed

height

Returns Integer — texture height in pixels

size

Returns Array(Integer, Integer)[width, height]

update(pixel_data)

Upload pixel data to the texture. The data must be a binary String of ARGB8888 pixels (4 bytes per pixel, width * height * 4 total).

Parameters
  • pixel_data String — raw pixel bytes

Returns self

width

Returns Integer — texture width in pixels