A lightweight, fast, and minimalistic image viewer built in C using
SDL2 and SDL2_image.
Designed for browsing individual images or entire folders, with smooth
navigation, window-resizing support, and background preloading for
seamless image transitions.
- Introduction
- Features
- Dependencies
- Building
- Usage
- Configuration
- How It Works
- Troubleshooting
- Future Improvements
- License
ImageViewer is a compact SDL2-based utility that loads one image or an entire directory of images and displays them in a resizable window. It uses background threads to preload textures for fast navigation and maintains an internal texture array for cycling through images.
This project is ideal as a reference or starting point for anyone learning SDL2, texture handling, directory iteration, or threaded loading.
- Open a single image or a whole directory
- Background thread-based image preloading for fast switching
- Stores textures in a dynamically allocated array
- Window resizing support
- Keyboard navigation
- Image cycling using modulo logic
- Graceful handling of empty folders or load errors
- Clean SDL shutdown
- SDL2
- SDL2_image
- pthreads (for background loading)
gcc -Wall -Wextra -O2 `sdl2-config --cflags` -o iv main.c src/dirscan.c src/imageload.c src/bg_thread.c src/utils.c `sdl2-config --libs` -lSDL2_image -pthread
./iv path/to/image_or_directory
- LEFT / h → previous
- RIGHT / l → next
- ESC → quit
- Initializes SDL, window, renderer
- Loads file or iterates directory
- Preloads textures in background thread
- Stores all images in texture array
- Scales textures to window size
- Cycles through images with modulo logic
- Black window: usually missing texture or render call
- Some images won't load: extension unsupported
- Crashes: bounds or NULL texture checks missing
- Fullscreen toggle
- EXIF rotation
- Zoom/pan
- Animated GIF support