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

Loading and applying textures to the shape


In this section, we'll look how to load textures in our code and learn to apply these textures to our objects. Textures is an image which is used add detail to an object. Imagine object such as cube and if we apply wooden texture to it, then it will look like a wooden box in our game world.

For this section, our object will be a rectangle. So first we'll learn how to draw rectangle shape in OpenGL and then understand how to apply textures to it. To apply texture to the shape, we'll prefer when using SOIL library, which is the Simple OpenGL Image Library. If you wish, you can use other libraries such as libpng which, as the name suggests, just supports PNG format images. But in this section, we'll only learn about SOIL, actually about SOIL2.

SOIL is a cross-platform library and it's supported on Android and iOS as part of game development. GLFW doesn't have any image loading methods built in, that is the reason why we are going to use SOIL library...