Skip to content

patrickluzdev/go-ppm-renderer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-ppm-renderer

A minimal software renderer written in Go that generates images in the PPM (Portable Pixmap) format using a CPU-based framebuffer.

Overview

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.

Features

  • Framebuffer management with fill/clear support
  • Rectangle drawing
  • Line drawing via Bresenham's line algorithm
  • PPM P6 (binary) file output

Getting Started

Prerequisites

  • Go 1.25+

Run

go run main.go

This generates an image.ppm file in the current directory.

View the output

Most image viewers support PPM files. Alternatively, convert it with ImageMagick:

convert image.ppm image.png

Project Structure

main.go       # All rendering logic and entry point
image.ppm     # Generated output image
go.mod        # Go module definition

API

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

License

MIT

About

Minimal CPU-based software renderer in Go that generates images in PPM format

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages