This project is written in C++, with multi-threading support provided by the C++11 standard library to speed up rendering.
Copies of the source are provided for you to check your work and compare against. If you wish to build the provided source, this project uses CMake. To build, go to the root of the project directory and run the following commands to create the debug version of every executable:
$ cmake -B build
$ cmake --build build
You should run cmake -B build
whenever you change your project CMakeLists.txt
file (like when adding a new source file).
You can specify the target with the --target <program>
option, where the program may be inOneWeekend
, theNextWeek
, theRestOfYourLife
, or any of the demonstration programs. By default (with no --target
option), CMake will build all targets.
$ cmake --build build --target inOneWeekend
CMake supports Release and Debug configurations. These require slightly different invocations across Windows (MSVC) and Linux/macOS (using GCC or Clang). The following instructions will place optimized binaries under build/Release
and debug binaries (unoptimized and containing debug symbols) under build/Debug
:
On Windows:
$ cmake -B build
$ cmake --build build --config Release # Create release binaries in `build\Release`
$ cmake --build build --config Debug # Create debug binaries in `build\Debug`
On Linux / macOS:
# Configure and build release binaries under `build/Release`
$ cmake -B build/Release -DCMAKE_BUILD_TYPE=Release
$ cmake --build build/Release
# Configure and build debug binaries under `build/Debug`
$ cmake -B build/Debug -DCMAKE_BUILD_TYPE=Debug
$ cmake --build build/Debug
We recommend building and running the Release
version (especially before the final render) for the fastest results, unless you need the extra debug information provided by the (default) debug build.
You may choose to use the CMake GUI when building on windows.
- Open CMake GUI on Windows
- For "Where is the source code:", set to location of the copied directory. For example,
C:\Users\Peter\raytracing.github.io
. - Add the folder "build" within the location of the copied directory. For example,
C:\Users\Peter\raytracing.github.io\build
. - For "Where to build the binaries", set this to the newly-created "build" directory.
- Click "Configure".
- For "Specify the generator for this project", set this to your version of Visual Studio.
- Click "Done".
- Click "Configure" again.
- Click "Generate".
- In File Explorer, navigate to build directory and double click the newly-created
.sln
project. - Build in Visual Studio.
If the project is succesfully cloned and built, you can then use the native terminal of your operating system to simply print the image to file.
You can run the programs by executing the binaries placed in the build directory:
$ build\Debug\inOneWeekend > image.ppm
or, run the optimized version (if you compiled with the release configuration):
$ build\Release\inOneWeekend > image.ppm
The generated PPM file can be viewed directly as a regular computer image, if your operating system supports this image type. If your system doesn't handle PPM files, then you should be able to find PPM file viewers online. We like ImageMagick.