An open API service indexing awesome lists of open source software.

https://github.com/marginalhours/mandelbrot-renderer

C++/SDL2 Mandelbrot set renderer
https://github.com/marginalhours/mandelbrot-renderer

cpp cpp17 mandelbrot-fractal mandelbrot-viewer sdl2

Last synced: 3 months ago
JSON representation

C++/SDL2 Mandelbrot set renderer

Awesome Lists containing this project

README

          

# Mandelbrot Renderer

This is a (keyboard and mouse) interactive C++ renderer of the Mandelbrot set, using SDL2 for output.
The main thread maintains an array of pixel data in memory. A pool of rendering
threads are passed messages containing a reference to this pixel data and some bounds,
and compute new colour values for the pixels within those bounds as the user provides
new inputs for zoom level, iterations, and so on.

Realistically this parallelises so well only because each pixel value is truly independent
from all the other pixels -- so this work really belongs in a GPU shader rather than
on the CPU. It's fun to see how large the speedup from multithreading can be when the work
truly is parallelisable, though!

## Obligatory action shots

![](screenshot-2.bmp)
![](screenshot-3.bmp)
![](screenshot-4.bmp)

## Command-line flags

The program supports the following command line flags:

- `-h` / `--help`: prints help message and exits
- `-wx` / `--screen-width`: sets the image width in pixels
- `-hx` / `--screen-height`: sets the image height in pixels
- `-c` / `--concurrency`: set number of render threads. Default is the number of cpu cores, so
one thread per core.

## Viewer controls:

### Mouse

Click + drag to draw a rectangle to zoom into it.

### Keyboard

- space -- take screenshot (screenshots are saved to `screenshot-.bmp` in the current directory) (inc. trashy screen flash effect)
- r -- reset viewer
- c -- cycle colour scheme
- +/= -- zoom in
- - -- zoom out
- . -- increase detail (iterations)
- , -- decrease detail (iterations)
- , , , -- pan image
- ESC -- quit

## Dependencies for Running Locally
* cmake >= 3.7
* All OSes: [click here for installation instructions](https://cmake.org/install/)
* make >= 4.1 (Linux, Mac), 3.81 (Windows)
* Linux: make is installed by default on most Linux distros
* Mac: [install Xcode command line tools to get make](https://developer.apple.com/xcode/features/)
* Windows: [Click here for installation instructions](http://gnuwin32.sourceforge.net/packages/make.htm)
* SDL2 >= 2.0
* Installation instructions can be found [here](https://wiki.libsdl.org/Installation)
* Note that for Linux, an `apt` or `apt-get` installation is preferred to building from source.
* gcc/g++ >= 5.4
* Linux: gcc / g++ is installed by default on most Linux distros
* Mac: same deal as make - [install Xcode command line tools](https://developer.apple.com/xcode/features/)
* Windows: recommend using [MinGW](http://www.mingw.org/)

## Basic Build Instructions

1. Clone this repo.
2. Make a build directory in the top level directory: `mkdir build && cd build`
3. Compile: `cmake .. && make`
4. Run it: `./Mandelbrot`.