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
Free Learning
Arrow right icon
C++ Game Development By Example
C++ Game Development By Example

C++ Game Development By Example: Learn to build games and graphics with SFML, OpenGL, and Vulkan using C++ programming

eBook
€8.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

C++ Game Development By Example

C++ Concepts

In this chapter, we will explore the basics of writing a C++ program. Here, we will cover just enough to wrap our heads around the capabilities of the C++ programming language. This will be required to understand the code used in this book.

To run the examples, use Visual Studio 2017. You can download the community version for free at https://visualstudio.microsoft.com/vs/:

The topics covered in this chapter are as follows:

  • Program basics
  • Variables
  • Operators
  • Statements
  • Iteration
  • Functions
  • Arrays and pointers
  • Struct and Enum
  • Classes and inheritance

Program basics

C++ is a programming language, but what exactly is a program? A program is a set of instructions executed in sequence to give a desired output.

Let's look at our first program:

#include <iostream> 
// Program prints out "Hello, World" to screen 
int main() 
{ 
    std::cout<< "Hello, World."<<std::endl; 
    return 0; 
} 

We can look at this code line by line.

The hash (#) include is used when we want to include anything that is using valid C++ syntax. In this case, we are including a standard C++ library in our program. The file we want to include is then specified inside the <> angle brackets. Here, we are including a file called iostream.h. This file handles the input and output of data to the console/screen.

On the second line, the // double slash marks the initiation of a code comment. Comments in code are not...

Summary

In this chapter, we covered the basics of programming—from what variables are and how to store values in them, to looking at operators and statements, to how to decide when each is required. After that, we looked at iterators and functions, which can be used to make our job simpler and automate the code as much as possible. Arrays and pointers help us to group and store data of a similar type, and with struct and enum we can create custom data types. Finally, we looked at classes and inheritance, which is the crux of using C++ and makes it convenient to define our data types with custom properties.

In the next chapter, we will look at the foundation of graphics programming and explore how three-dimensional and two-dimensional objects are displayed on the screen.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn how you can build basic 2D and complex 3D games with C++
  • Understand shadows, texturing, lighting, and rendering in 3D game development using OpenGL
  • Uncover modern graphics programming techniques and GPU compute methods using the Vulkan API

Description

Although numerous languages are currently being used to develop games, C++ remains the standard for fabricating expert libraries and tool chains for game development. This book introduces you to the world of game development with C++. C++ Game Development By Example starts by touching upon the basic concepts of math, programming, and computer graphics and creating a simple side-scrolling action 2D game. You'll build a solid foundation by studying basic game concepts such as creating game loops, rendering 2D game scenes using SFML, 2D sprite creation and animation, and collision detection. The book will help you advance to creating a 3D physics puzzle game using modern OpenGL and the Bullet physics engine. You'll understand the graphics pipeline, which entails creating 3D objects using vertex and index buffers and rendering them to the scene using vertex and fragment shaders. Finally, you'll create a basic project using the Vulkan library that'll help you get to grips with creating swap chains, image views, render passes, and frame buffers for building high-performance graphics in your games. By the end of this book, you’ll be ready with 3 compelling projects created with SFML, the Vulkan API, and OpenGL, and you'll be able take your game and graphics programming skills to the next level.

Who is this book for?

If you’re a developer keen to learn game development with C++ or get up to date with game development, this book is for you. Some knowledge of C++ programming is assumed.

What you will learn

  • Understand shaders and how to write a basic vertex and fragment shader
  • Build a Visual Studio project and add SFML to it
  • Discover how to create sprite animations and a game character class
  • Add sound effects and background music to your game
  • Grasp how to integrate Vulkan into Visual Studio
  • Create shaders and convert them to the SPIR-V binary format
Estimated delivery fee Deliver to Malta

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 03, 2019
Length: 420 pages
Edition : 1st
Language : English
ISBN-13 : 9781789535303
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Malta

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Publication date : May 03, 2019
Length: 420 pages
Edition : 1st
Language : English
ISBN-13 : 9781789535303
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 96.97
C++ Data Structures and Algorithm Design Principles
€32.99
Beginning C++ Game Programming
€33.99
C++ Game Development By Example
€29.99
Total 96.97 Stars icon
Banner background image

Table of Contents

17 Chapters
Section 1: Basic Concepts Chevron down icon Chevron up icon
C++ Concepts Chevron down icon Chevron up icon
Mathematics and Graphics Concepts Chevron down icon Chevron up icon
Section 2: SFML 2D Game Development Chevron down icon Chevron up icon
Setting Up Your Game Chevron down icon Chevron up icon
Creating Your Game Chevron down icon Chevron up icon
Finalizing Your Game Chevron down icon Chevron up icon
Section 3: Modern OpenGL 3D Game Development Chevron down icon Chevron up icon
Getting Started with OpenGL Chevron down icon Chevron up icon
Building on the Game Objects Chevron down icon Chevron up icon
Enhancing Your Game with Collision, Loops, and Lighting Chevron down icon Chevron up icon
Section 4: Rendering 3D Objects with Vulkan Chevron down icon Chevron up icon
Getting Started with Vulkan Chevron down icon Chevron up icon
Preparing the Clear Screen Chevron down icon Chevron up icon
Creating Object Resources Chevron down icon Chevron up icon
Drawing Vulkan Objects Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3
(7 Ratings)
5 star 42.9%
4 star 0%
3 star 14.3%
2 star 28.6%
1 star 14.3%
Filter icon Filter
Top Reviews

Filter reviews by




Client d'Amazon May 29, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Bon livre, bien structuré, avec des exemples de code fournis. Je le recommande.
Amazon Verified review Amazon
Anshul Sharma Jan 07, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It, s so hard to install the software, it took me 2-3 weeks to install the softwares like SFML, and also hard to understand, the game physics and concept to hard..
Amazon Verified review Amazon
David Bulvan Jun 07, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
the link supplied both in the digital version and the hard copy have a bad link and can't find the images online...Update: You can however use the git link to download the samples and all the art assets are in each example
Amazon Verified review Amazon
Peter Shadbolt Feb 17, 2021
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
* By the end of the book, you will have programmed three graphical applications in C++ for the Windows operating system.* The programming language is C++11, compiled using the Visual Studio IDE for Windows.* The book was not written for multiple platforms, but the code does not make heavy use of Windows specific functionality, so it should work with a few minor adjustments.* The applications are simple games with limited functionality. This book focuses on the graphics and rendering, not the gameplay.* Each of the three applications are built upon a different graphics library: SFML, OpenGL, Vulkan.BEGINNERS BEWARE* I would recommend this book to advanced C++ programmers.* People with no knowledge of programming will struggle with this book. Read a beginner's guide book first.* Chapter 1 (C++ Concepts) is a good refresher, and may be suitable for beginner C++ programmers.* The majority of the book is advanced. I do not recommend this for beginner programmers, and it will probably go over the heads of intermediate programmers. To be a C++ developer, you need to know your stuff.MY SUCCESS WITH THIS BOOK* I (the reviewer) was able to follow this book and achieve all the results that the author achieved, with difficulty.* Here's my computer specs: * Windows 10.0.18362.0 * NVIDIA GeForce RTX 2070 Super * AMD Ryzen 7 3700X* Here's the tools I used: * Visual Studio Community 2019 version 16.8.4 * CMake 3.19.4 * Vulkan SDK 1.2.141.2 * and the C++ libraries mentioned in the book (URLs are included in the book).* I built the SFML game in x86 (32-bit) configuration, and I built the OpenGL and Vulkan games in x64 configuration.THE NITTY GRITTY* Important parts of the book require you to build third party libraries using CMake. The author expects you to know how, and assumes the libraries are already built. The libraries I had the most trouble with were for the OpenGL section: * Bullet (physics library) * Freetype* Throughout the book, the blocks of code have many minor spelling errors, which means that you cannot assume that the code is correct. If you copy and paste it, you need to fix the errors. I suppose this is to help you avoid plagiarizing. The overall architecture and program logic is correct, but there are a few parts of the program that are missing. Because of the format in which they sent me this book to review, I did not have access to the accompanying code repository of the final project files, but I managed to guess and fill in the blanks (and copy one or two bits from other tutorials).* The Vulkan section is the hardest and longest to produce a meaningful outcome (because Vulkan always takes long). One difference between this book and the online Vulkan Tutorial is that this book separates the logic into classes and methods, instead of one monolithic class of functions.* The author includes a constructor and destructor for every class, but they do nothing, so you should in fact remove the empty constructors and destructors from the headers and cpp files because they are not being used for proper RAII. The author's approach for lifetime semantics is member functions (e.g. init() and destroy()).* Because the author uses raw pointers (new and delete), it might be worth it to `=delete` the copy and move constructors and assignment operators, to avoid lifetime issues.* Unlike the author, I always group my includes in a specific order to prevent most issues. * #include <std-library-header> * #include <third-party-library-header> * #include "header-in-this-project" * #include "accompanying-header-of-this-cpp-file"* Instead of writing #define in the source code to configure headers, I add them as preprocessor definitions in the Project Properties. ( GLFW_INCLUDE_VULKAN;GLM_FORCE_RADIANS;GLM_FORCE_DEPTH_ZERO_TO_ONE ). This avoids the possibility of the header being compiled in a different file without the definition.* The author was not concerned about the safety of class invariants. Some member variables are public when they should be private. For a toy project such as this, it doesn't matter.CONCLUSIONThis is a book for intermediate-to-advanced C++ programmers looking for a challenge, willing to learn how to program graphical applications for Windows.
Amazon Verified review Amazon
A. Consumer Oct 06, 2019
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
The general concepts in the book are solid. The problem are the mistakes, both grammatical and coding. There are examples that are supposed to return a particular result but do not work in the real world. There are basic C++ concepts explained in the start that have fundamental flaws and mistakes that would result in code that either won't compile or won't run the way the book explains. These aren't complicated examples, they are basics on how classes in C++ works, namespaces and how they are used, and the list goes on from there. The publisher's website lists no errata at all for the book. If someone would have taken the time to double-check the code and grammar, this book would be a solid four stars.
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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela