Book Image

Game Programming using Qt 5 Beginner's Guide - Second Edition

Book Image

Game Programming using Qt 5 Beginner's Guide - Second Edition

Overview of this book

Qt is the leading cross-platform toolkit for all significant desktop, mobile, and embedded platforms and is becoming popular by the day, especially on mobile and embedded devices. It's a powerful tool that perfectly fits the needs of game developers. This book will help you learn the basics of Qt and will equip you with the necessary toolsets to build apps and games. The book begins by how to create an application and prepare a working environment for both desktop and mobile platforms. You will learn how to use built-in Qt widgets and Form Editor to create a GUI application and then learn the basics of creating graphical interfaces and Qt's core concepts. Further, you'll learn to enrich your games by implementing network connectivity and employing scripting. You will learn about Qt's capabilities for handling strings and files, data storage, and serialization. Moving on, you will learn about the new Qt Gamepad module and how to add it in your game and then delve into OpenGL and Vulcan, and how it can be used in Qt applications to implement hardware-accelerated 2D and 3D graphics. You will then explore various facets of Qt Quick: how it can be used in games to add game logic, add game physics, and build astonishing UIs for your games. By the end of this book, you will have developed the skillset to develop interesting games with Qt.
Table of Contents (18 chapters)
16
Pop quiz answers

Painting text

Drawing text using QPainter deserves a separate explanation, not because it is complicated, but because Qt offers much flexibility in this regard. In general, painting text takes place by calling QPainter::drawText() or QPainter::drawStaticText(). Let's focus on the former first, which allows the drawing of generic text.

The most basic call to paint some text is a variant of this method, which takes x and y coordinates and the text to draw:

painter.drawText(10, 20, "Drawing some text at (10, 20)"); 

The preceding call draws the given text at position 10 horizontally and places the baseline of the text at position 20 vertically. The text is drawn using the painter's current font and pen. The coordinates can alternatively be passed as QPoint instances, instead of being given x and y values separately. The problem with this method is that it allows...