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

Adding an object and a light source


In this section, will discuss how to apply colors to your cube object. We'll also learn how to create shader files for light and for a source of light such as a lamp. And then we'll learn how to add the cube and the light source to our game world. 

So, let's begin by creating new shader files for the light and the lamp.   

 

Creating  lighting and lamp shader files

Here we'll learn how to create shader files for a light source and a lamp and explore the code that will go into the vertex shaders and the fragment shaders. Perform the following steps to learn how create these shader files: 

  1. First of all, for rename core.vs and core.frag from the previous chapters to lighting.vs and lighting.core.
  2. Now let's begin with the modifications to the code of these newly renamed files. First of all, we'll modify lighting.vs.  What we're going to do here is get rid of the texture coordinate because we're not going to render a texture in here, and we'll also get rid of the...