Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learn OpenGL
Learn OpenGL

Learn OpenGL: Beginner's guide to 3D rendering and game development with OpenGL and C++

Arrow left icon
Profile Icon Frahaan Hussain
Arrow right icon
€18.99 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5 (4 Ratings)
Paperback Aug 2018 208 pages 1st Edition
eBook
€13.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Frahaan Hussain
Arrow right icon
€18.99 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5 (4 Ratings)
Paperback Aug 2018 208 pages 1st Edition
eBook
€13.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€13.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Learn OpenGL

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...

Drawing a triangle

In this section, we’ll be looking at how to draw a triangle in OpenGL using the GLFW library. To begin with, let’s go to the file in which we wrote code to create an OpenGL rendering window using the GLFW library in the previous chapter, and make the necessary changes to it. Let's take a look at the following steps to understand the code required to draw a triangle:

  1. We'll begin by including the essential header files in our code:
#include <iostream>
// GLEW
#define GLEW_STATIC
#include <GL/glew.h>
// GLFW
#include <GLFW/glfw3.h>
// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;
  1. To create shapes in modern OpenGL, we need to create shaders. So, let’s begin by adding some shaders to our code. Firstly, we’ll add a constant, GLchar *, and we’ll call it vertexShaderSource. This is going to be a...

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 probably won'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

...

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...

Summary

In this chapter, we learned how to draw various shapes using shaders. We began by drawing a triangle and adding color to it. Then, we used the triangle concept to draw our quadrilateral and learned how to apply texture to it.

In the next chapter, we'll learn how to apply transformations such as translation and rotation to our shape, and learn to draw a cube and apply texture to it. We'll also explore the concepts of projections: Perspective and Orthographic, and how to implement those in our world.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn the basics of drawing along with fundamentals of shading to create amazing objects.
  • Get in-depth knowledge of lighting and materials to make realistic objects.
  • Understand the fundamentals of model loading and cube mapping.

Description

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.

Who is this book for?

This book is targeted towards anyone and everyone who is interested in creating games, learning how game engines work and most importantly for anyone who is interested in learning OpenGL. The ideal reader for this book would be anyone with a passion for learning game development or looking out for an OpenGL reference guide. The skills that you'll learn in this book will be applicable to all your game development needs. You'll require a strong foundation in C++ to understand and apply the concepts of this book.

What you will learn

  • Set up GLFW and GLEW on Windows and macOS with absolute, relative Linking
  • Set up SDL and SFML on your system using absolute and relative Linking
  • Draw using the simple shaders
  • Create a camera and learn to populate your game world with objects
  • Learn about color and lighting concepts to create an amazing game world
  • Understand model loading and cube mapping to advance your game

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 31, 2018
Length: 208 pages
Edition : 1st
Language : English
ISBN-13 : 9781789340365
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Aug 31, 2018
Length: 208 pages
Edition : 1st
Language : English
ISBN-13 : 9781789340365
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 111.97
Learn OpenGL
€24.99
OpenGL Game Development By Example
€49.99
OpenGL 4 Shading Language Cookbook
€36.99
Total 111.97 Stars icon

Table of Contents

7 Chapters
Setting Up OpenGL Chevron down icon Chevron up icon
Drawing Shapes and Applying Textures Chevron down icon Chevron up icon
Transformations, Projections, and Camera Chevron down icon Chevron up icon
Effects of lighting , Materials and Lightmaps Chevron down icon Chevron up icon
Types of light sources and combining of lights Chevron down icon Chevron up icon
Implementing a Skybox Using a Cubemap Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5
(4 Ratings)
5 star 25%
4 star 0%
3 star 25%
2 star 0%
1 star 50%
sandra Apr 05, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Ottima guida per iniziare
Amazon Verified review Amazon
Nate Nov 12, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
The author's style of writing is to literally say the function and arguments you're about to write and then he shows the code with minimal explanation. In fact, he regularly says "you should google this" for anything that needs a more thorough explanation. I've definitely learned more from Googling the individual functions than I have from his exposition.Here's an example of his walkthroughs: Then, we'll add function glBindTexture(). And for this function, we pass GL_TEXTURE_2D and texture. glBindTexture( GL_TEXTURE_2D, texture );He never explained `glBindTexture` nor `GL_TEXTURE_2D`, he just says we're using them.Ultimately, the book was $10 on packtpub.com and I don't mind it given that price. But I'd rather pay $30-$50 for a book that does a much better job.
Amazon Verified review Amazon
Juli Dec 06, 2022
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Leider sind alle Bilder nicht nur schwarz-weiß sondern zum Teil auch in schlechter Qualität gedruckt (pixelig und verschwommen). Das Inhaltsverzeichnis ist folgendermaßen Aufgeteilt:S 1-44 Setting up OpenGLS 45-76 Drawing Shapes and Applying TexturesS 77-111 Transformations, Projections, and CameraS 113-146 Effects of lighting, Materials and LightmapsS 147-182 Types of light sources and combining of lightsS 183-192 Implementing a Skybox Using a CubemapDie Schriftgröße ist zu groß. Alles in allem bietet das Buch zu wenig Informationen.Ich empfehle lieber ein Online Tutorial zu machen.Zumal mich das Beispiel mit den schwebenden Kisten im Buch auch sehr an ein Tutorial erinnert das ich Online gefunden habe.
Amazon Verified review Amazon
W. Guest Oct 27, 2020
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
This is an unfortunate example of why creators can't put their work out in the open -- some (like this 'author') then take all that work (effectively word for word) and claim authorship and ownership. The 'author' here did the same thing with the UDEMY course, too.It's like someone taking out-of-copyright stories -- say, 'A Christmas Carol' -- copying it into a new format, and then claiming they wrote that story. It's absurd... but it's happening here.Purchaser beware!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.