Professional Documents
Culture Documents
The Fundamentals of C C Game Programming Using Target based Development on SBC s 1st Edition Brian Beuken 2024 scribd download
The Fundamentals of C C Game Programming Using Target based Development on SBC s 1st Edition Brian Beuken 2024 scribd download
The Fundamentals of C C Game Programming Using Target based Development on SBC s 1st Edition Brian Beuken 2024 scribd download
OR CLICK LINK
https://textbookfull.com/product/the-fundamentals-
of-c-c-game-programming-using-target-based-
development-on-sbc-s-1st-edition-brian-beuken/
Read with Our Free App Audiobook Free Format PFD EBook, Ebooks dowload PDF
with Andible trial, Real book, online, KINDLE , Download[PDF] and Read and Read
Read book Format PDF Ebook, Dowload online, Read book Format PDF Ebook,
[PDF] and Real ONLINE Dowload [PDF] and Real ONLINE
More products digital (pdf, epub, mobi) instant
download maybe you interests ...
https://textbookfull.com/product/the-fundamentals-of-c-c-game-
development-using-target-based-development-on-sbc-s-first-
edition-beuken/
C++ Programming D. S
https://textbookfull.com/product/c-programming-d-s/
https://textbookfull.com/product/c-programming-complete-guide-to-
learn-the-basics-of-c-programming-in-7-days-2nd-edition-xavier-s-
martin/
https://textbookfull.com/product/programming-principles-and-
practice-using-c-second-edition-stroustrup/
Programming Principles and Practice Using C 3rd
Edition Stroustrup
https://textbookfull.com/product/programming-principles-and-
practice-using-c-3rd-edition-stroustrup/
https://textbookfull.com/product/data-parallel-c-mastering-dpc-
for-programming-of-heterogeneous-systems-using-c-and-sycl-1st-
edition-james-reinders/
https://textbookfull.com/product/hands-on-game-development-
patterns-with-unity-2019-create-engaging-games-by-using-industry-
standard-design-patterns-with-c-1st-edition-david-baron/
https://textbookfull.com/product/programming-principles-and-
practice-using-c-third-edition-bjarne-stroustrup/
https://textbookfull.com/product/unity-game-development-
programming-c-in-unity-engine-a-guide-book-for-beginners-1nd-
edition-2020-kathleen-peterson/
The Fundamentals of C/C++
Game Programming
The Fundamentals of C/C++
Game Programming
Using Target-Based Development on SBC’s
Brian Beuken
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to
publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or
the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced
in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright
material has not been acknowledged please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any
form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and
recording, or in any information storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.
copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400.
CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been
granted a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification
and explanation without intent to infringe.
1. Getting Started 1
Mine Looks Different? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
First Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
Setting Things Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
Introducing Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
Hello Place of My Choosing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
vii
Getting the Machines to Talk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Sending Our First Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
Debugger Hangs Too Much? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
viii Contents
Did We Hit It? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101
Box Checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .102
Circle Checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .102
Give Me Shelter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104
So Which Is Better? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110
Final Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110
Simple Text Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .111
A Simple Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113
How Did We Do? The Infamous Postmortem . . . . . . . . . . . . . . . . . . . . . . . . . .118
Fix Question 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .119
A Pat on the Back . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Kamikazi Invaders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123
The Ship . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Da Baddies! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .130
Now We’re Talking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
Make Them Move . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135
Get Them Flying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .136
A Nice Arc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Step by Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141
Dive Dive Dive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .142
Bombs Away . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .144
Get Back to Where You Once Belonged . . . . . . . . . . . . . . . . . . . . . . .145
Home Again! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .145
Vectors, Our Flexible Friends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .146
Lets Get Lethal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .151
Bombs Away for Real Now . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Danger UXB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .161
Stepping Back, Deciding When to Go . . . . . . . . . . . . . . . . . . . . . . . .162
Breaker Breaker Rubber Duck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .167
Fred Reacts! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169
Tidy Up the Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .173
Twiddles and Tweaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .173
Postmortem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .173
Jumping around a Bit Though? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174
Crawling Over, Time for Baby Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .175
Object-Oriented Programming Is Not an Error . . . . . . . . . . . . . . . . . . . . . . . . .175
Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .176
Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .176
Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .176
Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .176
Start the Music . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .176
Welcome to OpenAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .177
Installing OpenAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .177
Getting OpenAL Working . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .179
Contents ix
Dealing with Sound as Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .182
How Does OpenAL Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .183
How Does Alut Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184
Horrible Earworms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Streaming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .191
The War against Sloppy Code Storage! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .192
Our Own Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .193
Using This New Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .196
Lets Get a Bit More Compiler Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .198
5 .2 Tiles and Backgrounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .198
What Do We Mean by Tiles? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .199
Working with Tiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .199
What a Wonderful World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .199
Homing in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Wrapping It Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .211
Is This All We Need? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .211
5 .3 Single-Screen Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .214
A World with Gravity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .214
Routine Bad Guys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .221
Point-to-Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .221
Patrolling Enemy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Homing Enemy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Ladders and Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Data, Our Flexible Friend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Loading Our Maps (and Other Resources) . . . . . . . . . . . . . . . . . . . .235
5 .4 Lets Scroll This . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .239
Simple Scrolling Shooter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Let Them Eat Lead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Bring on the Bad Guys! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Process Everything? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .251
No More Mr Nice Guy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .252
What Will Make It Better? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
There’s No Wrong Way…But There Are Always Better Ways . . . . . . . . . . . . . .255
For a FireWork, Life Is Short But Sweet! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .255
A New Dawn for Particle Kind! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .261
There’s Always a Price to Pay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .270
Handling Large Numbers of Objects . . . . . . . . . . . . . . . . . . . . . . . . .271
Locking the Frame Rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .271
Recapping the 2D Experience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .272
x Contents
Installing a Maths Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Danger, Will Robinson! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Normal Programming Resumes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Three Types of Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .291
Model Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .291
View Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .291
Projection Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
The Relationship of These Three Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Other Matrix Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .295
Moving Around . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Revisiting Hello Triangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Let’s Try a Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Mistakes Waiting to Happen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
A Quick Word about Using Quaternions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
HelloCubes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
I Thought We Could Move 100’s of Thousands of Them? . . . . . . . . . . . . . . . . . . 306
How the GPU Gets Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Buffers, Buffers Everywhere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
Vertex Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Attribute Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .311
Texture Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .312
Frame Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .312
Render Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .313
Buffers Are Not Free . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .313
Let’s Get Back to It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .314
Time to Texture Our Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .315
The Fixed Pipeline Isn’t Quite Dead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .318
Mapping a Texture to Our Faces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .319
Choose the Size to Suit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Limited Numbers of Textures? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Everyone Loves a Triangle But! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .322
3D Lets Get into the Heart of Our GPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .325
What Else You Got? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .325
Loading Models (OBJ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .327
Locate and Install an OBJ Model Loader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .327
Installing and Using TinyObjLoader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .329
Do We Care about the Data? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .330
Lights Camera Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .332
The Return of the Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .335
Dot Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .335
Another Fun Vector Fact-Cross Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .336
Who’s to Say Whats Normal? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .336
Types of Light . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .338
Light Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .339
Shadows, a Place Where Danger Hides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .339
Shaders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
So What Is a Shader? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
Contents xi
Keeping Track of Them . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Introducing the Shader Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Let’s Light It Up! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
The Camera Never Lies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .350
But What Does It All Do? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .351
In Space, No One Can Hear You Smashing Your Keyboard As You Scream
Why “Don’t You Work!!!” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .353
xii Contents
Render Culling! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .398
Adding the Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
Physics, More Scary Maths Stuff? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .401
Subtitle…More Long Winded Explanations! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .401
Introducing Bullet Physics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
How It Works, and Finally Quaternions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
Let’s Get to It, at Last . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Setting Things Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Stepping Through . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Visualizing Things . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Force, Torque, and Impulse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .410
Collisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .412
The Downside . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .415
Basic Racing Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .416
Getting and Making the Car Controllable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .417
I Like to Move It, Move It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .418
Staying on Track . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .421
Using Bullet to Collide with the Terrain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
Can’t Find My Way Home? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Other Optimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
Other Performance Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .431
Contents xiii
Expanding to an SDK? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .461
The Last Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
Ready-Made or Roll Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
Limitations of Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
Cross-Platform Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
Appendix I 477
Where Files Live on Non-Raspberry Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
Appendix II 479
Updating versus New SD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .479
Appendix IV 483
Bits Bytes and Nibbles Make You Hungry! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Appendix V 485
OpenGLES3 .0+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
Appendix VI 487
The Libs We Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
On the PC End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
Index 493
xiv Contents
“From Hello World to
Halo—It’s Just Code!”
xv
are doing rather than the specific functions . If you still don’t understand the syntax of the
code, you should undertake a beginners’ coding course, there are several online .
In addition, despite the title, this isn’t a book solely about programming Single Board
Computers (SBCs) . The use of a cheap target system is a means to an end to encourage the
reader to limit expectations and work within tight constraints, which game programmers,
especially console programmers have to work with . I want primarily to focus on gameplay
concepts and game structures, which will let us get games up and running really quickly .
However, we do have to introduce some technical concepts later, when we’re a bit more
comfortable, because most of these technical concepts will have a direct impact on the
performance of your games . You will need to know just enough to avoid some pitfalls and
get things up and running correctly .
SBCs are usually quite simple systems, so building a working knowledge of the fairly
generic hardware to produce graphics, sound, and data storage is generally easier to learn
on them, than it would be on your up to the minute PC, which will shield you from errors
by virtue of massive processing performance and near unlimited memory .
Once understood, all of the concepts and projects in this book are easily transferrable
to any development target where the reader can stretch their growing skills on more pow-
erful systems while still being mindful of the need to work within constraints of hardware,
which are hard to push, and personal limits, which should always be pushed .
But SBCs are really fun to work with, cheap to acquire, and present a real sense of
achievement when you make them to do more than just act as media servers or control units .
Most important, this is not a how to do x, with y kind of book . I want to take you
through a journey of discovery, mine as well as yours, and provide suggestions and work-
ing examples on how to do things that games need, and let you decide if the approach I’ve
taken is valid . I want to make you question things and hopefully come to different conclu-
sions, using what I supply as a base for debate and expansion rather than a gospel to be
followed . When working with beginners, I don’t believe in imposing the right way, I prefer
to have faith in, “this works for me, can I make it better?” The right way, for you at least,
will come with practice and the joy of achievement .
2π | !2π
Ok, let’s stop beating about the bush, after all the section heading gives it away . I chose
the Raspberry Pi, because it’s cheap, it’s freely available all over the world, it connects to
a PC via network cables or wirelessly, it has consistent hardware, so what works on one is
sure to work on another even if a few differences in speed happen, and in my opinion, it’s
a machine that has largely been ignored by the games development community . So you’re
going to be treading in largely virgin sand, that’s quite exciting .
I need a consistent, fun bit of hardware, with sufficient power, reasonable graphic
abilities, and onboard memory to create a range of decent little games to learn with . The
Raspberry Pi gives me all that, and most of its clones are close enough to also give us some
insight into the fragmentation issues in a small enough scale to cope!
Now it also has to be said, once I settled on the Raspberry machine I had my eyes
opened up to the fact that there are several Raspberry Pi-type machines out there; in fact,
there is a thriving community of similar small board System on Chip (SoC) machine’s
with their own communities . So I expanded my remit a little to include as many of the
main ones as I could find with a simple limit of cost . I only looked at units I could buy for
under U .S .$100 .
So if you have one of these other systems then it’s only fair that I make sure what we
do here are going to work on them too, so long as they run some form of Linux and have
OpenGLES2 .0 for their Graphics systems . We should be able to get our games to work on
them too . I’ll try to give a summary of machines I’ve tried, and maintain an update on the
support site .
Of course, technology never stands still, and as I was a quarter of the way in writing
this book, the Raspberry Pi foundation announced a new model, the Raspberry Pi 3, and
as usual it sold out within hours of its announcement . Not quite as big a leap in perfor-
mance as the 2 was over the 1, but still another boost in performance for the same price is
much appreciated .
So I guess most of you will now be on model 4 by the time this comes out . But the nice
thing about the Raspberry range is that aside from memory and speed, they all are based
on the same hardware principles and they have maintained the mantra of compatibility .
So even though I’m going to continue with my Raspberry Pi Model 2B for now, swapping
over to the Model 3B quite soon I am sure, everything in this book will be checked on the
latest models before it goes to the printers .
I should say to owners of earlier Raspberry Pi models, all the things in this book will
work for you, but the later explanations on multicore processing will be useless as earlier
The Target
We need an SBC of course; for the most part I will assume Raspberry Pi, 12 million+ users
would indicate that most of you are using that . So that’s your first purchase, if you haven’t
done so already, you need to do this now . At the time of writing, I’m using the current
model, a Raspberry Pi 2 Model B, but am soon going to plug-in my new Raspberry Pi 3
Model B . I will do the odd sanity check with older Raspberry Pi Model A+/B+/Zeroes
I have to hand . I also have picked up quite a few of the so-called Raspberry Pi beaters
1. Write your own interface between Visual Studio and a Linux-based Raspberry Pi
I’m pretty sure you will opt for option 2 . If you went for option 1 . Close the book now, go
write your interface, and be sure to write to me in a few months’ time when you’re ready
to start again .
Kmicicin oli niin vaikea olla, että hän suorastaan tunsi tuskia,
mutta hän ei olisi kuitenkaan mistään hinnasta tässä maailmassa
luopunut paikastaan. Hän kuunteli naapurinsa puvun kahinaa,
seurasi salaa hänen liikkeitään, tunsi hänen sykähtelevän
läheisyytensä, ja kaikki tämä tuotti hänelle jonkinlaista tuskallista
kärsimystä.
Tuokion kuluttua hän huomasi ja tunsi, että Oleńkakin samalla
tavalla seurasi hänen liikkeitään ja ajatuksiaan, vaikk'ei
vähimmässäkään määrässä ilmaissut sitä. Kmicicin valtasi
voittamaton halu katsoa naapuriinsa, ja hän käänsi katseensa
sivulle, kunnes näki kirkkaan otsan, tummain kulmakarvain
kaartamat silmät ja kalpeat kasvot, joilla ei ollut ihomaalia, kuten
muilla naisilla.
Yht'äkkiä hän kuitenkin tunsi, että jos tuo »joku muu» olisi edes
yrittänyt käyttää hyväkseen hänen lupaansa, olisi hän silponut
miehen palasiksi. Pelkkä ajatuskin siitä saattoi herättää hänessä
hurjan vihan. Ja hän rauhoittui vasta sitten, kun muisti, että hän
itsehän siinä istuikin eikä kukaan muu ja ettei ainakaan nyt kukaan
edes yrittänytkään voittaa neidon suosiota.
— Ruhtinaan malja!
Sitten hän otti toisen kirjeen. Tuskin hän oli avannut sen ja
silmäillyt sitä, kun hänen kasvonsa kirkastuivat ja niille nousi voiton
ja ilon hymy.
— Sieradzin vojevodakunta on alistunut ruotsalaisten ylivaltaan! —
huusi hän. — Se on seurannut Suur-Puolan esimerkkiä ja asettunut
Kaarle Kustaan suojeluksen alaiseksi.
— Niin.