This folder contains a Verilator simulation to accompany the Project F blog post: Lines and Triangles.
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 Lines and Triangles README for build instructions.
There is one demo that can draw a line, cube, or triangles.
Triangles 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/lines-and-triangles/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 110 in top_demo
, then rerun make.
render_line
- single diagonal linerender_edge
- line around the edge of the screen bufferrender_cube
- cube outline from nine linesrender_triangles
- three triangle outlines
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.