Repository navigation
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
PXL
----
Minimal 2D graphics library in C99.
Features:
- 2D primitives: line, rect, circle, triangle (outline + filled)
- Canvas with scissor clipping, translation offset, color, clear, blit
- Text rendering with mono or proportional LSB bitmask fonts, including alignment
- Transformations: flip (horizontal, vertical) and scale for bitmasks and text during rendering
- Backends: SDL2, X11 (uses SHM, XIM/XIC extensions for performance and UTF-8 input)
- Keyboard/mouse input
Build:
make # Build libpxl.a (default backend: x11)
make PXL_BACKEND=sdl # Build with SDL2 backend
make lint # Static analysis with strict warnings (-Werror)
make test # Run unit tests found in test/
make demo # Build demos found in demo/
make tool # Build tools found in tool/
make clean # Remove build artifacts (incl. the ones in demo, tools and test)
Main configuration is defined in Makefile.inc. Copy 'config.mk.example' to 'config.mk' to customize
backend, CFLAGS, or library paths.
Quick start (Minimal PXL application):
pxl_app_t app = {
.title = "My App",
.width = 800,
.height = 600
};
if (pxl_app_init(&app) != PXL_SUCCESS) return 1;
while (pxl_app_advance_wait(&app)) {
if (pxl_app_was_pressed(&app, PXL_KEYB_ESCAPE)) break;
pxl_buf_t pb;
if (pxl_backend_begin_frame(&pb) == PXL_SUCCESS) {
pxl_canvas_t cnv;
pxl_canvas_init(&cnv, &pb);
pxl_canvas_clear(&cnv);
pxl_draw_str(&cnv, 100, 100, "Hello, PXL!");
(void)pxl_backend_end_frame();
}
}
pxl_app_deinit(&app);
Demos:
- demo_pong.c - Complete game: physics, input, rendering, interpolation
- demo_fontview.c - Bitmask font viewer
Architecture:
Core:
backend.h - Backend interface. All backends use ARGB8888 pixel format
buf.h - uint32_t pixel buffer with stride alignment
err.h - Error codes
geom.h - Geometry primitives (rect, span) and clipping
input.h - Input state handling (keyboard, mouse, window events)
Backend:
backend_sdl.c - SDL2 backend (do not activate VSYNC)
backend_x11.c - X11 backend (uses SHM, XIC extensions for performance)
Gfx:
bitmask.h - 1-bit per pixel mask for stencil/clip operations
blit.h/c - Pixel operations (blit, bitmask drawing, with optional flip/scale)
canvas.h - Drawing surface with color, scissor, translation offset, clear, blit
color.h - ARGB8888 color creation and component extraction
shape.h/c - 2D primitives (line, rect, circle, triangle, outline + filled)
text.h/c - Text rendering with mono or proportional LSB bitmask fonts, alignment, and transformations
text_basic.h/c - ASCII text rendering with built-in 8x8 font (char, string, bounds)
Framework:
app.h - App management: frame management, input, poll/wait event modes
layout.h - Layout helpers
stepper.h - Time-stepped physics loop helper (fixed timestep, interpolation)
Deprecated (will be removed in next version):
camera.h - Offset-based camera management helpers (use canvas offset directly)
tileset.h/c - Tile rendering: grid atlas (tileset) + animation frames (sprite) (use pxl_blit_rect directly)
timer.h - Countdown timer helpers (use a double variable directly)
pxl.h - umbrella header that includes all public headers. For finer
granularity, users may include individual headers directly.
Tools:
- bdf2pxl - Convert BDF font files to pxl_font_t C header
Example: bdf2pxl -n my_font -r U+0020-U+007F DejaVuSans.bdf > my_font.h
Testing:
Run tests: 'make test' or 'sh test-all.sh' to go through all available backends.
License:
MIT. See LICENSE.