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 now! 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
Conferences
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
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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

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 : 9781789537345
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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : May 03, 2019
Length: 420 pages
Edition : 1st
Language : English
ISBN-13 : 9781789537345
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

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

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.