Skip to content

[gg] Add texture filtering controls for pixel-perfect rendering #24934

@ejstembler

Description

@ejstembler

Feature Request: Texture Filtering Controls in gg Module

Problem

The gg graphics module currently doesn't expose texture filtering controls, making it difficult to achieve pixel-perfect rendering for pixel art games. When scaling images using draw_image_part(), the graphics
backend applies linear filtering by default, causing blurriness and anti-aliasing artifacts that are undesirable for pixel art.

Current Behavior

// This scales a 16x16 tile to 32x32 but results in blurry/filtered output
dst_rect := gg.Rect{x, y, 32.0, 32.0}
src_rect := gg.Rect{src_x, src_y, 16.0, 16.0}
ctx.draw_image_part(dst_rect, src_rect, &img)

Even with sample_count: 1 to disable anti-aliasing, the texture filtering still causes blurriness when scaling images.

Desired Behavior

Add texture filtering options to either:

  1. gg.Config for global texture filtering:
gg.new_context(
    sample_count: 1
    texture_filter: .nearest  // or .linear (default)
)
  1. Per-image filtering when creating images:
img := ctx.create_image_with_filter(path, .nearest) or { panic(err) }
  1. Per-draw-call filtering:
ctx.draw_image_part_filtered(dst_rect, src_rect, &img, .nearest)

Workarounds Attempted

  • Setting sample_count: 1 (helps with anti-aliasing but not texture filtering)
  • Manual pixel-by-pixel rendering (performance issues and complexity)
  • Integer-only coordinates (doesn't solve the core filtering issue)

Similar APIs

  • OpenGL: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
  • SDL: SDL_SetTextureScaleMode(texture, SDL_ScaleModeNearest)
  • Raylib: SetTextureFilter(texture, TEXTURE_FILTER_POINT)

Would it be possible to expose the underlying graphics backend's texture filtering controls through the gg module?

Use Case

This is essential for:

  • Pixel art games and applications
  • Retro-style graphics that need crisp, unfiltered scaling
  • Any application requiring precise pixel control

Version used

0.4.11 e3b07d9

Environment details (OS name and version, etc.)

macOS 15.5 (24F74)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Unit: gg/sokolA video, sound, rendering, or fonts related issue.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions