This folder contains a Verilator simulation to accompany the Project F blog post: 2D Shapes.
Verilator creates C++ simulations of Verilog designs, while SDL produces simple cross-platform graphics applications. By combining the two, you can simulate a hardware design on your PC: no dev board required! Verilator is fast, but it's still much slower than an FPGA. However, for these simple designs, you can reach 60 FPS on a modern PC.
If you're new to graphics simulations check out the blog post on Verilog Simulation with Verilator and SDL.
If you have a dev board, see the main 2D Shapes README for build instructions.
There is one demo top module that can draw different things.
Filled circles drawn by sim demo.
This simulation has been tested with:
- Verilator 4.038 (Ubuntu 22.04 amd64)
- Verilator 5.006 (macOS 13 arm64)
If this is the first time you've used Verilator and SDL, you need to install dependencies.
Make sure you're in the sim directory projf-explore/graphics/2d-shapes/sim
.
Build the demo:
make demo
Run the simulation executable from obj_dir
:
./obj_dir/demo
You can quit the simulation by pressing the Q key.
To switch between the different demos, change the render instance near line 115 in top_demo
, then rerun make.
render_rects
- many rectangles inside rectanglesrender_rects_fill
- overlapping filled rectanglesrender_triangles_fill
- three filled trianglesrender_cube_fill
- filled cube from six trianglesrender_circles
- circles inside circlesrender_circles_fill
- filled circles inside circles
To run in fullscreen mode, edit main_demo.cpp
so that FULLSCREEN = true
, then rebuild.
To build the simulations, you need:
- C++ Toolchain
- Verilator
- SDL
The simulations should work on any modern platform, but I've confined my instructions to Linux and macOS. Windows installation depends on your choice of compiler, but the sims should work fine there too. For advice on SDL development on Windows, see Lazy Foo' - Setting up SDL on Windows.
For Debian and Ubuntu-based distros, you can use the following. Other distros will be similar.
Install a C++ toolchain via 'build-essential':
apt update
apt install build-essential
Install packages for Verilator and the dev version of SDL:
apt install verilator libsdl2-dev
That's it!
If you want to build the latest version of Verilator yourself, see Building Verilator for Linux.
Install the Homebrew package manager; this will also install Xcode Command Line Tools.
With Homebrew installed, you can run:
brew install verilator sdl2
And you're ready to go.