Game Programming Using Qt
Table of Contents
Game Programming Using Qt
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Time for action β heading
What just happened?
Pop quiz β heading
Have a go hero β heading
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Introduction to Qt
The cross-platform programming
What just happened?
Qt Platform Abstraction
Supported platforms
A journey through time
New in Qt 5
Restructured codebase
Qt Essentials
Qt Add-ons
Qt Quick 2.0
Meta-objects
C++11 support
Choosing the right license
An open source license
A commercial license
Summary
2. Installation
Installing the Qt SDK
Time for action β installing Qt using an online installer
What just happened?
Setting up Qt Creator
Time for action β loading an example project
What just happened?
Time for action β running the Affine Transformations project
What just happened?
Building Qt from sources
Time for action β setting up Qt sources using Git
What just happened?
Time for action β configuring and building Qt
What just happened?
Summary
3. Qt GUI Programming
Windows and dialogs
Creating a Qt project
Time for action β creating a Qt Desktop project
What just happened?
Adding child widgets to a window
Managing widget content
Time for action β implementing a tic-tac-toe game board
What just happened?
Qt meta-objects
Signals and slots
Pop quiz β making signal-slot connections
Time for action β functionality of a tic-tac-toe board
Properties
Declaring a property
Using a property
Time for action β adding properties to the board class
What just happened?
Designing GUIs
Time for action β designing the game configuration dialog
What just happened?
Time for action β polishing the dialog
Accelerators and label buddies
The tab order
Signals and slots
What just happened?
Using designer forms
Direct approach
The multiple-inheritance approach
The single inheritance approach
Time for action β the logic of the dialog
An application's main window
The Qt resource system
Time for action β the main window of the application
What just happened?
Time for action β adding a pull-down menu
What just happened?
Time for action β creating a toolbar
What just happened?
Time for action β filling in the central widget
What just happened?
Time for action β putting it all together
What just happened?
Have a go hero β extending the game
Pop quiz β using widgets
Summary
4. Qt Core Essentials
Text handling
Manipulating strings
Encoding and decoding text
Basic string operations
The string search and lookup
Dissecting strings
Converting between numbers and strings
Using arguments in strings
Regular expressions
Time for action β a simple quiz game
What just happened?
Extracting information out of a string
Finding all pattern occurrences
Data storage
Files and devices
Traversing directories
Getting access to the basic file
Devices
Time for action β implementing a device to encrypt data
What just happened?
Have a go hero β a GUI for the Caesar cipher
Text streams
Data serialization
Binary streams
Time for action β serialization of a custom structure
What just happened?
XML streams
Time for action β implementing an XML parser for player data
What just happened?
Have a go hero β an XML serializer for player data
JSON files
Time for action β the player data JSON serializer
Time for action β implementing a JSON parser
What just happened?
QSettings
Pop quiz β Qt core essentials
Summary
5. Graphics with Qt
Raster painting
Painter attributes
Widget painting
Time for action β custom-painted widgets
What just happened?
Time for action β transforming the viewport
What just happened?
Time for action β drawing an oscillogram
Input events
Time for action β making oscillograms selectable
Have a go hero β reacting only to the left mouse button
Working with images
Loading
Modifying
Painting
Painting text
Static text
Rich text
Optimized drawing
Time for action β optimizing oscillogram drawing
What just happened?
Have a go hero β implementing a double-buffered oscillogram
Time for action β developing the game architecture
What just happened?
Time for action β implementing the game board class
What just happened?
Time for action β understanding the ChessView class
What just happened?
Time for action β rendering the pieces
What just happened?
Time for action β making the chess game interactive
What just happened?
Time for action β connecting the game algorithm
What just happened?
Have a go hero β implementing the UI around the chess board
Have a go hero β connecting a UCI-compliant chess engine
OpenGL
Introduction to OpenGL with Qt
Time for action β drawing a triangle using Qt and OpenGL
Time for action β scene-based rendering
What just happened?
Time for action β drawing a textured cube
Have a go hero β animating a cube
Modern OpenGL with Qt
Shaders
Time for action β shaded objects
GL buffers
Off-screen rendering
Summary
6. Graphics View
Graphics View architecture
Items
Parent child relationship
Appearance
Time for action β creating a black, rectangular item
What just happened?
Time for action β reacting to an item's selection state
What just happened?
Time for action β making the item's size definable
What just happened?
Have a go hero β customizing the item
Standard items
Coordinate system of the items
Time for action β creating items with different origins
What just happened?
Time for action β rotating an item
What just happened?
Have a go hero β applying multiple transformations
Scenes
Adding items to the scene
Time for action β adding an item to a scene
What just happened?
Interacting with items on the scene
Rendering
Time for action β rendering the scene's content to an image
What just happened?
Have a go hero β rendering only specific parts of a scene
Coordinate system of the scene
Time for action β transforming parent items and child items
What just happened?
Have a go hero β playing with the z value
View
Time for action β putting it all together!
What just happened?
Showing specific areas of the scene
Transforming the scene
Time for action β creating an item where transformations can easily be seen
What just happened?
Time for action β implementing the ability to scale the scene
What just happened?
Time for action β implementing the ability to move the scene
What just happened?
Time for action β taking the zoom level into account
What just happened?
Questions you should keep in mind
The jumping elephant or how to animate the scene
The game play
The player item
Time for action β creating an item for Benjamin
What just happened?
The playing field
The scene
Time for action β making Be...