Anton's OpenGL 4 Tutorials book - Demo Code
This series of demos accompanies the e-book "Anton's OpenGL 4 Tutorials": antongerdelan.net/opengl
See LICENCE.txt
for licence information.
Each chapter with major demonstration code has a corresponding demo here. There is also an example of code for Hello Triangle for OpenGL 2.1 for reference.
Each demo has easy-to-read Makefiles for Linux, MacOS, and Windows.
You may need to download newer versions of the libraries in the third_party/
folder.
This code is some years old now and builds may fall out of date. I try to maintain this so that it functions, but be aware that Makefiles and build details may differ slightly from book text for this reason.
build-essential
bundle package via the package manager on your distribution.
E.g. for Ubuntu:sudo apt install build-essential
Install the GLEW, GLFW3, FreeType, and Assimp development libraries:
sudo apt install libglew-dev libglfw3-dev libfreetype-dev libassimp-dev
Open a terminal and cd
to the demo of choice, then:
make -f Makefile.linux64
To build all the demos you can run ./build_all_linux_osx.sh
from the main directory.
Install Clang or GNU compiler and tools - usually by installing Apple XCode through the App Store.
You will probably wish to install libraries via Homebrew, similarly to Linux, above.
brew install glew glfw assimp freetype
Open a terminal and cd
to the demo of choice:
make -f Makefile.osx
To build all the demos you can run ./build_all_linux_osx.sh
from the main directory.
Create a new Empty, C++, Console project. You can then easily install the required libraries with NuGet, under the Project menu of a new C++ project, and you're ready to draw a triangle in 5 minutes.
glfw
, and glew
. For later tutorials you can also find assimp
, and freetype
, when required.opengl32.lib
to your linker input string. You can find this in Project->Properties->Configuration Properties->Linker->Input->Additional Dependencies. Just add opengl32.lib;
to the front of the long string of dependencies so that it changes to opengl32.lib;kernel32.lib;user32;...
.If you would rather do things the old fashioned way, without using a package manager, I have recorded a 2020 video stream tutorial where I show how to get Visual Studio set up and start programming OpenGL, including downloading and setting up libraries.
Tutorial: Intro to 3D Graphics Programming with OpenGL 4 (with Anton). Stream Recording.
This includes a very verbose set-up of Visual Studio 2019 with helper libraries.
cd
to the demo of choice.make -f Makefile.win64
If you have trouble linking supporting libraries you may need to download and recompile GLFW, GLEW, AssImp, and FreeType. It's a good idea to do this anyway to stay up to date.
gl_utils.cpp
to avoid cluttering main.cpp
. This means that gl_utils.cpp
is not necessarily the same in each demo, but is built up gradually.Special thanks to all the readers over the years that have submitted additions, bug reports, fixes, and feedback. If you have submitted a correction and don't mind having your name/@ printed here please let me know (or if you'd like to change these details).