Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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
Can$12.99 Can$33.99
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5 (4 Ratings)
eBook Aug 2018 208 pages 1st Edition
eBook
Can$12.99 Can$33.99
Paperback
Can$41.99
Subscription
Free Trial
Arrow left icon
Profile Icon Frahaan Hussain
Arrow right icon
Can$12.99 Can$33.99
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5 (4 Ratings)
eBook Aug 2018 208 pages 1st Edition
eBook
Can$12.99 Can$33.99
Paperback
Can$41.99
Subscription
Free Trial
eBook
Can$12.99 Can$33.99
Paperback
Can$41.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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 : 9781789340860
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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 Can$6 each
Feature tick icon Exclusive print discounts
$279.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 Can$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Can$ 187.97
Learn OpenGL
Can$41.99
OpenGL Game Development By Example
Can$83.99
OpenGL 4 Shading Language Cookbook
Can$61.99
Total Can$ 187.97 Stars icon
Banner background image

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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.