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

Lighting up objects 


In this section, we'll be looking at basics of lighting because so far, if you look at the results from our previous section, which just discussed colors, what we've got is the cube and the light source. At the moment, the entire color in the cube output just looks uniform. It almost doesn't look like a cube, a six-sided shape figure, and the lighting doesn't look very realistic too. Because realistically, in our example, the light source doesn't emit light onto our cube and there is no effect of light and shadow on the cube. So, in this section we'll discuss the basics of lighting and effect on the cube. We'll focus on improving the lighting system so we can have a more realistic effect.

So, let's get started. As usual, we'll begin making modifications to our shader files.

Updating the shaders

Check out the following steps to understand the changes made to the shaders:

  1. We're not going to be changing anything in the lamp shader files because we're happy with the actual light...