Setting Things Up!
Reading time: 3 mins.This lesson is WIP (Feb. 2024) and is currently being developped.
While Scratchapixel's approach to teaching—offering self-contained programs that are easy to compile—is beneficial, many of you new to computer graphics and programming might not know how to compile and run these programs. We aim to address this here.
What Programming Language Will We Use?
All our sample programs are written in C++. While other languages like Swift, Objective-C, Rust, Go, or C# are popular, C++ remains the most commonly used language in graphics applications. It becomes an extraordinary tool once you get the hang of it.
Since Scratchapixel is not a platform for learning C++ and there are ample resources available, either in books or online, we won't cover it here. We recommend searching online for recommendations and finding a resource that suits your needs (preferably in your native language, if available). We strongly advocate for getting a book—yes, one of those substantial items with printed pages you carry around in your bag.
Windows, macOS, and Linux
Most, if not all, examples are tested on Windows OS. However, the way we compile our programs is compatible with macOS and Linux. Instead of using something like Microsoft Visual Studio to write and compile code, we use a simple text editor. For compilation, we utilize a terminal (using GitBash on Windows; terminals are integral to Linux and macOS environments) and a cross-platform compiler such as gcc or clang (our preference).
Hardware
Any computer will suffice. You don't need a GPU - just a CPU. If you're on a tight budget, consider a Raspberry Pi, though you'll still require a screen, keyboard, mouse, etc.
Software
Windows
-
Install Git on your computer to access GitBash Terminals.
-
Install Microsoft Visual Studio. The Community version is free. While we won't use it directly, MS Visual Studio includes C/C++ header files and libraries necessary for compilation. Ensure the C/C++ options are selected during installation.
-
Choose any text editor you like. We recommend Notepad++.
-
We suggest downloading clang++ as your compiler.
MacOS
-
Install Xcode, which includes clang++. Terminals are part of the MacOS since it is Unix-based.
Linux
If you're using Linux, you likely already have a compiler installed and know how to use a terminal.
Testing Your Work Environment
-
Open a terminal.
-
Navigate to the directory where you want to write your code:
cd c:/Users/Romeo/Desktop/dev
-
Using your chosen text editor, create a file named
test.cc
with the following content:#include <iostream> int main() { std::cerr << "Hello world!" << std::endl; return 0; }
-
Compile the program:
clang++ -o test.exe test.cc
-
Run the program with
./test.exe
.