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

Setting up OpenGL using SFML on Windows


In this section, we'll study how to set up OpenGL using SFML and GLEW on a Windows machine. But, first, let's understand what SFML is. SFML is a simple and fast multimedia library. It's a software development library designed for cross-platform use to provide a programming interface for various multimedia components on the system. It allows you to do stuff like handle or render windows, so we can draw our OpenGL and handle events, such as various inputs, and it also allows us to handle textures.

Downloading the SFML library

Let's download the SFML library onto your system by visiting https://www.sfml-dev.org/index.php. Then, go to Download, click on SFML 2.5.0, and then select whichever Visual C++ version matches your Visual Studio version and system compatibility, and accordingly click on the link. The file will be downloaded as a ZIP file onto your system. Next, go to the OpenGL folder (which we created in the previous sections) and inside it, create a folder called SFML to extract and place our SFML files.

Linking the SFML and GLEW libraries to the project

The steps to link the SFML and GLEW libraries to our project with absolute or relative linking are similar to what we discussed in the previous sections. The only difference will be in the step where we link up the .lib files. For that, go to Additional Dependenciesand in the textbox, just type in opengl32.lib. Then, we'll type glew32s.lib. And to link SFML libraries, we'll type sfml-graphics.lib, sfml-system.lib, and sfml-window.lib, and then click on OK.

Adding a DLL file to the project

As seen in the previous sections, before we begin with coding, we need to place the dynamic link library into our project. To do that, go to C:\OpenGL\SFML\bin\ and copy sfml-graphics-2.dll, sfml-system-2.dll, and sfml-window-2.dll, and paste them into the location in your system where the main.cpp file of your project is located. We'll also have to copy and paste the glew32.dll file here from the bin folder of the GLEW folder.

With this, we are all set to code our OpenGL rendering window using SFML.