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

Chapter 2. Drawing Shapes and Applying Textures

The previous chapter was all about setting up our project to use different types of libraries, such as GLFW, GLEW, SMFL, and SDL. In this chapter, we'll go beyond the setup part and learn to implement some really cool OpenGL stuff. We'll learn about shaders and how to use them to create various shapes. Then, we'll move on to learn how to create a separate shader file and reference that in our code. We'll also discuss how to apply different textures to shapes using the SOIL library.

In this chapter, we'll cover the following topics in detail:

  • Learning to draw a triangle using a shader
  • Creating a separate shader file and referencing it in the main code
  • Drawing a rectangle and applying textures to it using the SOIL library

This chapter will initiate you into OpenGL coding and you'll learn a lot of concepts related to it.

Before we get started with coding, there a few things that we need to understand. Firstly, the code we’ll be writing from now on...