A minimal software renderer written in Go that generates images in the PPM (Portable Pixmap) format using a CPU-based framebuffer.
This project implements a simple 2D rendering pipeline from scratch — no external graphics libraries. It writes pixels directly into an in-memory framebuffer and serializes the result as a binary PPM (P6) file.
- Framebuffer management with fill/clear support
- Rectangle drawing
- Line drawing via Bresenham's line algorithm
- PPM P6 (binary) file output
- Go 1.25+
go run main.goThis generates an image.ppm file in the current directory.
Most image viewers support PPM files. Alternatively, convert it with ImageMagick:
convert image.ppm image.pngmain.go # All rendering logic and entry point
image.ppm # Generated output image
go.mod # Go module definition
| Function | Description |
|---|---|
newColor(r, g, b) |
Creates an RGB color value |
clearBuffer(fb, color) |
Fills the entire framebuffer with a color |
writePixel(fb, x, y, color) |
Sets a single pixel (bounds-checked) |
drawRect(fb, x, y, w, h, color) |
Draws a filled rectangle |
drawLine(fb, x0, y0, x1, y1, color) |
Draws a line between two points |
savePPM(filename, fb) |
Writes the framebuffer to a PPM file |
MIT