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

Abstracting the shaders


Let's take a look at shaders in this section, even though we've looked at shaders in the previous section while creating the triangle and using a shader to color it. What we're going to do in this section is to abstract the shader code into a vertex shader file and a fragment shader file so that it's a lot neater and more reusable. And, we're also going to abstract out the loading of the shader, as once we've abstracted that out, we probablywon't need to change it at all, or at least there won't be too many changes to it. Further, in our projects, we'll just use these files to load the shaders in our code, which will make it easy to use.

 

 

Creating the shader files

Follow these steps to create the files:

  1. We'll begin by creating two new empty files in our project IDE and name those two files core.vs and core.frag. Here, vs stands for vector shader file and frag stands for fragment shader file.

Note

It doesn't actually matter what you name these as long as you refer to the...