Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
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 Benjamin move
What just happened?
Parallax scrolling
Time for action – moving the background
What just happened?
Have a go hero – adding new background layers
QObject and items
Time for action – using properties, signals, and slots with items
Property animations
Time for action – using animations to move items smoothly
What just happened?
Have a go hero – letting the scene handle Benjamin's jump
Time for action – keeping multiple animations in sync
What just happened?
Item collision detection
Time for action – making the coins explode
What just happened?
Setting up the playing field
Have a go hero – extending the game
A third way of animation
Widgets inside Graphics View
Optimization
A binary space partition tree
Caching the item's paint function
Optimizing the view
Pop quiz – mastering Graphics View
Summary
7. Networking
QNetworkAccessManager
Downloading files over HTTP
Time for action – downloading a file
Have a go hero – extending the basic file downloader
Error handling
Time for action – displaying a proper error message
Downloading files over FTP
Downloading files in parallel
The finished signal
Time for action – writing the OOP conform code using QSignalMapper
What just happened?
The error signal
The readyRead signal
The downloadProgress method
Time for action – showing the download progress
What just happened?
Using a proxy
Connecting to Google, Facebook, Twitter, and co.
Time for action – using Google's Distance Matrix API
Time for action – constructing the query
Time for action – parsing the server's reply
Have a go hero – choosing XML as the reply's format
Controlling the connectivity state
QNetworkConfigurationManager
QNetworkConfiguration
QNetworkSession
QNetworkInterface
Communicating between games
Time for action – realizing a simple chat program
The server – QTcpServer
Time for action – setting up the server
What just happened?
Time for action – reacting on a new pending connection
What just happened?
Time for action – forwarding a new message
Have a go hero – using QSignalMapper
Time for action – detecting a disconnect
What just happened?
The client
Time for action – setting up the client
What just happened?
Time for action – receiving text messages
Time for action – sending text messages
Have a go hero – extending the chat with a user list
Improvements
Using UDP
Time for action – sending a text via UDP
Have a go hero – connecting players of the Benjamin game
Pop quiz – test your knowledge
Summary
8. Scripting
Why script?
The basics of Qt Script
Evaluating JavaScript expressions
Time for action – creating a Qt Script editor
What just happened?
Time for action – sandboxed script evaluation
What just happened?
Integrating Qt and Qt Script
Exposing objects
Time for action – employing scripting for npc AI
What just happened?
Have a go hero – extending the Dungeons & Dragons game
Exposing functions
Exposing C++ functions to scripts
Exposing script functions to C++
Time for action – storing the script
What just happened?
Time for action – providing an initialization function
What just happened?
Time for action – implementing the heartbeat event
What just happened?
Have a go hero – defending against attacks
Using signals and slots in scripts
Have a go hero – triggering defense using signals and slots
Creating Qt objects in scripts
Error recovery and debugging
Extensions
The other Qt JavaScript environment
Alternatives to JavaScript
Python
Time for action – writing a Qt wrapper for embedding Python
What just happened?
Time for action – converting data between C++ and Python
What just happened?
Have a go hero – implementing the remaining conversions
Time for action – calling functions and returning values
What just happened?
Have a go hero – wrapping Qt objects into Python objects
Pop quiz – scripting
Summary
9. Qt Quick Basics
Fluid user interfaces
Declarative UI programming
Element properties
Group properties
Object hierarchies
Time for action – creating a button component
What just happened?
Time for action – adding button content
What just happened?
Time for action – sizing the button properly
What just happened?
Time for action – making the button a reusable component
What just happened?
Event handlers
Mouse input
Time for action – making the button clickable
What just happened?
Time for action – visualizing button states
What just happened?
Time for action – notifying the environment about button states
What just happened?
Touch input
Time for action – dragging an item around
What just happened?
Time for action – rotating and scaling a picture by pinching
What just happened?
Have a go hero – rotating and scaling with a mouse
Keyboard input
Have a go hero – practicing key-event propagation
Using components in Qt Quick
Time for action – a simple analog clock application
What just happened?
Time for action – adding needles to the clock
What just happened?
Time for action – making the clock functional
What just happened?
Dynamic objects
Using components in detail
Creating objects on request
Delaying item creation
Accessing your item's component functionality
Imperative painting
Time for action – preparing Canvas for heartbeat visualization
What just happened?
Time for action – drawing a heartbeat
What just happened?
Time for action – making the diagram more colorful
What just happened?
Qt Quick and C++
Creating QML objects from C++
Pulling QML objects to C++
Pushing C++ objects to QML
Time for action – self-updating car dashboard
What just happened?
Time for action – grouping engine properties
What just happened?
Extending QML
Registering classes as QML elements
Time for action – making CarInfo instantiable from QML
What just happened?
Custom Qt Quick items
OpenGL items
Time for action – creating a regular polygon item
What just happened?
Have a go hero – creating a supporting border for RegularPolygon
Painted items
Time for action – creating an item for drawing outlined text
What just happened?
Summary
10. Qt Quick
Bringing life into static user interfaces
Animating elements
Generic animations
Time for action – scene for an action game
What just happened?
Time for action – animating the sun's horizontal movement
What just happened?
Composing animations
Time for action – making the sun rise and set
What just happened?
Non-linear animations
Time for action – improving the path of the sun
What just happened?
Property value sources
Time for action – adjusting the sun's color
What just happened?
Time for action – furnishing sun animation
What just happened?
Have a go hero – animating the sun's rays
Behaviors
Time for action – animating the car dashboard
What just happened?
States and transitions
More animation types
Quick game programming
Game loops
Time for action – character navigation
What just happened?
Time for action – another approach to character navigation
What just happened?
Have a go hero – polishing the animation
Time for action – generating coins
What just happened?
Sprite animation
Time for action – implementing simple character animation
What just happened?
Time for action – animating characters using sprites
What just happened?
Time for action – adding jumping with sprite transitions
What just happened?
Have a go hero – making Benjamin wiggle his tail in anticipation
Parallax scrolling
Time for action – revisiting parallax scrolling
What just happened?
Have a go hero – vertical parallax sliding
Collision detection
Time for action – collecting coins
What just happened?
Notes on collision detection
Eye candy
Auto-scaling user interfaces
Graphical effects
Have a go hero – the blur parallax scrolled game view
Particle systems
Tuning the emitter
Rendering particles
Making particles move
Time for action – vanishing coins spawning particles
What just happened?
Summary
A. Pop Quiz Answers
Chapter 3, Qt GUI Programming
Pop quiz – making signal-slot connections
Pop quiz – using widgets
Chapter 4, Qt Core Essentials
Pop quiz – Qt core essentials
Chapter 6, Graphics View
Pop quiz – mastering Graphics View
Chapter 7, Networking
Pop quiz – testing your knowledge
Chapter 8, Scripting
Pop quiz – scripting
Chapter 11, Miscellaneous and Advanced Concepts
Pop quiz – testing your knowledge
Index
← Prev
Back
Next →
← Prev
Back
Next →