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

Combining light


In this section, we're going to be looking at combining our light sources. So far we've covered directional lights, point lights, and spotlights in the previous sections. The following is a brief overview of what they are:

  • Directional light: A directional light is a light that has a particular direction. It shines light in a particular direction. But it doesn't have a location, a position. It's just infinitely far away from everything.
  • Point light: A point light has a position, but it shines light in every single direction. Depending on what you're doing and what sort of game you've got, you could potentially have the sun or a star' as a directional light, but if you could go into space, go around your star or get near it, then you'd probably want a point light.
  • Spotlight: A spotlight essentially is like a lamp. It casts a light in an initial position, and then in a direction as well. So it's like a combination of the preceding two types of light.

In the previous sections, we...