Will Briggs
Lynchburg, VA, USA
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/9781484251867 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-5186-7 e-ISBN 978-1-4842-5187-4
https://doi.org/10.1007/978-1-4842-5187-4
Will Briggs 2019
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
Introduction
Surely theres no shortage of C++ intro texts. Why write yet another?
Im glad you asked.
Ever since moving from Pascal to C++ (back when dinosaurs roamed the Earth), Ive been underwhelmed by available resources. I wanted something quirky and fun to read, with sufficient coverage and fun examples, like the old Oh! Pascal! text by Cooper and Clancy.
Its about time we had this again. Even a perfectly accurate text with broad coverage gives you nothing if you fall asleep when you read it. Well, nothing but a sore neck.
But the other reason, of course, is to promote laziness.
We all want our projects to be done more quickly, with less wailing and gnashing of teeth. Sometimes, its said, you have to put your nose to the grindstone. Maybe, but I like my nose too well for that. Id rather do things the easy way.
But the easy way isnt procrastinating and dragging my feet: its to find something I love doing and do it so well that it feels relatively effortless. Its producing something robust enough that when it does break down, it tells me exactly what the problem is, so I dont have to spend a week pleading with it to explain itself. Its writing code that I can use again and again, adapting it to a new use in hours instead of days.
Youll benefit from this book if youre a beginning programmer or one who hasnt yet learned C++ or its descendants like Java or C#; if you already know a C++-like language, you can go a little faster.
Heres what you can expect:
A pleasant reading experience.
Adequate coverage.
Games, that is, use of the SDL graphics library, which makes it easy to get graphics programs working quickly and easily. It isnt fair that Python and Visual Basic should get all the eye candy.. After that well use more standard (but less visually interesting) I/O, so we can also get practice with the more common console programs.
and an easy introduction to SDLs graphical magic, using the SSDL library (see below).
Sufficient examples, and they wont all be about actuarial tables or how to organize an address book. (See pleasant reading experience earlier.)
Antibugging sections throughout the text to point out common or difficult-to-trace errors and how to prevent them.
Compatibility with g++ and Microsoft Visual Studio.
Compliance with C++17, the latest standard, and the nice goodies it provides.
For g++ programmers, instructions on using g++, the ddd/gdb debugger system, and Makefiles; for Visual Studio, use of the debugger and project files.
An appreciation of laziness.
A cool title. Maybe I could have tried to write a For Dummies book, but after seeing Bioinformatics for Dummies Im not sure I have what it takes.
Why SDL?
Its surely more enjoyable to make programs with graphics and WIMP ).
Figure 1
A game of Freeciv, which uses the SDL library.
Why SSDL?
but although SDL is relatively simple, its not simple enough to start with on day 1 of programming with C++. SSDL ( Simple SDL) saves you from needing to know things we dont get to until Chapter ). It also hides the initialization and cleanup code thats pretty much the same every time you write a program, and makes error handling less cumbersome.
You may want to keep using SSDL as is after youre done with this book, but if you decide to go on with SDL, youll find you know a lot of it already, with almost nothing to unlearn: most SSDL function names are names from SDL with another S stuck on the front. Well go into greater depth on moving forward with SDL in Chapter .
Software You Will Need
Your compiler, plus various free SDL libraries (SDL2, SDL2_Image, SDL2_TTF, and SDL2_Mixer), my free SSDL library, and (for Chapter .
SSDL is available at www.apress.com/9781484251867 , as is my sample code.
In Unix, you may choose to install the GNU Free Fonts library, or msttcorefonts, Microsoft Core Fonts for the Web . Look for ttf-mscore-fonts and fonts-freefont-ttf (Debian and Ubuntu systems) and gnu-free-fonts-common and msttcore-fonts- (Red Hat and Fedora), remembering that systems differ, standards change, and Unix is hard. But if youre using Unix, you knew that. I use Microsoft Core Fonts for the Web in the example programs.
Programming with sound may not be practical over remote connections, because of the difficulty of streaming sound. If using Unix emulation, you might check the emulators sound capabilities say, by playing a video.