Teek::SDL2::Texture Class
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):
#update— upload pixel data from a String#width— texture width in pixels#height— texture height in pixels#blend_mode=— set the texture blend mode#blend_mode— get the current blend mode#destroy— free GPU resources#destroyed?— check if the texture has been destroyed
Inherits: Object
Class Methods ↑
from_file(renderer, path)
Load an image file into a GPU texture via SDL2_image.
Parameters
rendererRenderer— the renderer that owns this texturepathString— 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
rendererRenderer— the renderer that owns this texturewidthInteger— width in pixelsheightInteger— 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
rendererRenderer— the renderer that owns this texturewidthInteger— width in pixelsheightInteger— 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
modeSymbol, 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
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_dataString— raw pixel bytes
Returns self
width
Returns Integer — texture width in pixels