The 3D Graphics Rendering Cookbook is your one-stop-shop practical guide to learning modern graphics rendering algorithms and techniques using the C++ programming language and APIs such as OpenGL and Vulkan. Starting with the configuration of your OpenGL and Vulkan development environment, you will immerse yourself in various common graphics development aspects, including shader development and handling geometrical data, among others. Going further, the book delves into building a 3D rendering engine, guiding you step by step through a number of small yet self-contained recipes. After each recipe, you will be able to incrementally add features to your code base while learning how to integrate numerous possible 3D graphics methods and algorithms into one big project. The book dives deep into the discussion of the relevant graphics techniques, such as physically-based rendering, image-based rendering, and CPU/GPU geometry culling, to name a few. You will be introduced to common techniques and solutions when dealing with large datasets for 2D and 3D rendering and will apply optimization techniques to build high-performance and feature-rich graphics applications. By the end of this book, you will be able to create fast and versatile 3D rendering frameworks, and have a solid understanding of best practices in modern graphics API programming.

This book is about rendering and will be focusing on modern, real-time, GPU-accelerated rendering techniques rather than on just one specific graphics API. Nonetheless, we will use the latest version of OpenGL, a programming interface for creating real-time 3D graphics, with a flavor of the Approaching Zero Driver Overheads philosophy. Some parallels with Vulkan will be drawn to demonstrate the differences between these two APIs and how all the rendering concepts and techniques discussed in the book can be implemented using both programming interfaces.

Who this book is for

We expect our readers to have a good grasp of real-time 3D graphics. The opening chapters explain what you need to get started with OpenGL and Vulkan. However, we will not focus for long on the basics and will quickly move forward to cover more sophisticated content instead. If you are familiar with OpenGL 3 or OpenGL ES 2 and want to learn more about modern rendering approaches and migration paths toward present-day rendering APIs, this book is probably a good fit for you.

Even though graphics programming might seem an easy and fun way to get into software development, it actually requires the mastery of numerous advanced programming concepts. The reader is expected to have a thorough understanding of modern C++ and some math skills, such as basic linear algebra and computational geometry.

What this book covers

This book is divided into distinct chapters. Each chapter covers specific aspects of 3D rendering and contributes more material to build a versatile 3D graphics demo by the end of the book, starting from the basics, then exposing more complicated approaches, and finally adding some advanced rendering techniques to the code:

Chapter 1, Establishing a Build Environment, explains the current state of OpenGL, its place in the computer world, and how it compares to Vulkan. The reader will learn which tools and dependencies are necessary to work with the source code of this book, as well as how to set them up.

Chapter 2, Using Essential Libraries, contains a set of recipes for the rapid building of minimalistic graphical applications in pure OpenGL and Vulkan from scratch using popular open source libraries, such as GLFW, GLM, STB, ImGui, EasyProfiler, Optick, AssImp, Etc2Comp, TaskFlow, and MeshOptimizer.

Chapter 3, Getting Started with OpenGL and Vulkan, covers basic aspects of rendering APIs, such as intercepting API calls, working with buffers and textures, converting between different texture formats, implementing programmable vertex pulling, and compiling Vulkan shaders to SPIR-V at runtime.

Chapter 4, Adding User Interaction and Productivity Tools, focuses primarily on debugging, profiling, and user interaction mechanisms. The reader will learn how to debug and profile graphical applications in different ways, starting with onscreen counters and graphs, then going into open source instrumenting profilers, and finishing with useful helper classes to allow interactive application debugging.

Chapter 5, Working with Geometry Data, teaches you how to deal with geometry data in a modern 3D rendering pipeline and also how to get comfortable with advanced topics such as geometry Level of Detail (LOD) and tessellation. Besides that, some GL shading language techniques will be discussed to show how various utility functions for geometry rendering can be implemented.

Chapter 6, Physically Based Rendering Using the glTF2 Shading Model, presents the glTF2 physically-based shading model and the ways to render it using the GL shading language in OpenGL and Vulkan. Different aspects of data preprocessing techniques will be covered, including the precalculation of Bidirectional Reflectance Distribution Function (BRDF) look-up tables and irradiance maps.

Chapter 7, Graphics Rendering Pipeline, goes into the representation of complex 3D scene data with multiple internal dependencies and cross-references. You will learn how to apply performance-oriented techniques such as data-oriented design to build a high-performance 3D rendering system. This is where the real OpenGL and Vulkan stuff begins to happen.

Chapter 8, Image-Based Techniques, contains a series of recipes on how to improve graphics rendering realism by using image-based techniques, such as screen space ambient occlusion, high dynamic range rendering with light adaptation, and projective shadow mapping.

Chapter 9, Working with Scene Graph, extends the series of scene graph-related recipes by showing how to modify scene data and extend it with components showing potential ways of scaling this approach to build a real-world graphics engine. This is followed by a short discussion on how to use a physics engine with a rendering engine.

Chapter 10, Advanced Rendering Techniques and Optimization, dives deeper into approaches to the construction of GPU-driven rendering pipelines, multithreaded rendering, and other advanced techniques for feature-rich graphics applications. Here, we conclude the book by combining numerous recipes and techniques into a single application.

To get the most out of this book

You will need a machine supporting OpenGL 4.6 and Vulkan 1.2 with the latest GPU drivers. All code examples in this book have been tested using Visual Studio 2019 on Windows 10 and GCC 8 on Linux. macOS users will be able to run only the very first demos from this book due to the lack of API support. To run our Bootstrap dependency downloader script, Python 3.x is required. CMake is used to build the source code.

We advise you to download the source code from the GitHub repository ( Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at If there's an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here:

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "After setting the project name, this macro uses the GLOB_RECURSE function to collect all source and header files into the SRC_FILES and HEADER_FILES variables."

A block of code is set as follows:

macro(SETUP_GROUPS src_files)

  foreach(FILE ${src_files})

    get_filename_component(PARENT_DIR "${FILE}" PATH)

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

macro(SETUP_APP projname)

  set(PROJ_NAME ${projname})


Any command-line input or output is written as follows:

sudo apt-get update

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Choose Custom Installation and make sure that the pip box is checked."

Tips or important notes

Appear like this.


In this book, you will find several headings that appear frequently (Getting ready, How to do it..., How it works..., There's more..., and See also).

To give clear instructions on how to complete a recipe, use these sections as follows:

Getting ready

This section tells you what to expect in the recipe and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make you more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit

Share Your Thoughts

Once you've read 3D Graphics Rendering Cookbook, we'd love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.