Book Image

Learn OpenGL

By : Frahaan Hussain
Book Image

Learn OpenGL

By: Frahaan Hussain

Overview of this book

Learn OpenGL is your one-stop reference guide to get started with OpenGL and C++ for game development. From setting up the development environment to getting started with basics of drawing and shaders, along with concepts such as lighting, model loading, and cube mapping, this book will get you up to speed with the fundamentals. You begin by setting up your development environment to use OpenGL on Windows and macOS. With GLFW and GLEW set up using absolute and relative linking done, you are ready to setup SDL and SFML for both the operating systems. Now that your development environment is set up, you'll learn to draw using simple shaders as well as make the shader more adaptable and reusable. Then we move on to more advanced topics like texturing your objects with images and transforming your objects using translate, rotate and scale. With these concepts covered, we'll move on to topics like lighting to enable you to incorporate amazing dynamic lights in your game world. By the end of the book, you'll learn about model loading, right from setting up ASSIMP to learning about the model class and loading a model in your game environment. We will conclude by understanding cube mapping to bring advance worlds to your game.
Table of Contents (13 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Lightmaps


Let's discuss lightmaps in this section. But first, let's try to understand what a lighting map is. Well, in the real world, if you have, let's say, a crate that is partly metal and  partly wood, similar to the following screenshot: 

The wooden parts of it will react differently to the light compared to the metal parts. It might sound obvious, but OpenGL (or any other sort of 3D graphics API) doesn't have a concept of wood or metal or plastic, or anything else and as a result, we need to program that in. We need to use other techniques to help illustrate that visually as the wood should be less shiny than the metal parts of the crate. If you search on lighting maps, you'll get a bunch of information. You can create them in various tools. You can use Maya or Photoshop to create them. So, without further ado, let's get down to the coding.

Making modifications to shader files

Follow the below mentioned steps:  

  1. So, what you want to do is go to the lighting vertex shader. We need to make...