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

Graphical User Interface

It is now time to turn our attention to the graphical user interface, or GUI. The GUI allows us to control other elements of the game, such as starting or stopping the game, or setting various options.

In this section, you will learn how to create buttons on the screen that can be clicked by the mouse. We'll keep it simple by adding a single button to pause the game. While we are at it, we will learn important lessons about game state.

Creating a button

A button is nothing more than a texture that is being displayed on the screen. However, we have to perform some special coding to detect whether or not the button is being clicked. We will add this functionality to the sprite class so that our buttons are being handled by the same class that handles other image in our game.

We will actually create two buttons: one to Pause and one to Resume. I have used a simple graphics program to create the following two buttons:

Creating a button

I have saved these buttons as, you guessed it, pause...

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