Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenGL Game Development By Example

You're reading from   OpenGL Game Development By Example Design and code your own 2D and 3D games efficiently using OpenGL and C++

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781783288199
Length 340 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Robert Madsen Robert Madsen
Author Profile Icon Robert Madsen
Robert Madsen
Stephen Madsen Stephen Madsen
Author Profile Icon Stephen Madsen
Stephen Madsen
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Cleaning up the house


We have a pretty complete game. Sure, it's not going to set any records or make anyone rich, but if this is your first game, then congratulations!

We have been remiss in one area: good programming dictates that any time we create an object, we delete it when we are done using it. Up to now, you may be wondering if we were ever going to do this! Well, now is the time.

We made a placeholder for all of these operations in the EndGame function. Now, we will add the necessary code to properly release our resources.

Release sprites

Let's start by clearing out our sprites. It is important to remember that when we remove any resource, we need to make sure that it is also releasing its own resources. This is the purpose of the class destructor. Let's use the Sprite class as an example. Open Sprite.cpp and you should see a destructor defined using the following code:

Sprite::~Sprite()
{
  for (int i = 0; i < m_textureIndex; i++)
  {
    glDeleteTextures(1, &m_textures[i]);...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime