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

Arrow left icon
Profile Icon Siddharth Shekar
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3 (7 Ratings)
Paperback May 2019 420 pages 1st Edition
eBook
$17.99 $26.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Siddharth Shekar
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3 (7 Ratings)
Paperback May 2019 420 pages 1st Edition
eBook
$17.99 $26.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$17.99 $26.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781789535303
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

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
$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 $5 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 $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 127.97
C++ Data Structures and Algorithm Design Principles
$43.99
Beginning C++ Game Programming
$44.99
C++ Game Development By Example
$38.99
Total $ 127.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.