I’ve finally gotten around to learning C++ after getting out of programming for about 15 years. It’s taken unlearning a lot of bad habits and learning a new paradigm, but I’m starting to feel fairly comfortable in the language.
What I’d like to learn next is how to implement simple 2D graphics into my programs. A practical first exercise would be creating a graphic interface for a card game. Let’s keep the underlying code simple and say blackjack.
Now, on an old Commodore 64 (where I originally learned programming, both BASIC and some assembly), it’s a piece of cake. But a lot has changed since those days and, quite frankly, I feel like I’m relearning computers from scratch. So, what’s the best next step? Is there a lot I need to learn before I can even contemplate incorporating graphics? Is there a book you can recommend for the next step? I like taking baby steps, so don’t throw me into the deep end with 3D graphics and all that.
What platform are you talking about? I can tell you a little about Windows.
Really, if you’re in Windows, I’d suggest learning C# for .Net - it is very clean, everything’s in the System.Drawing or System.Drawing2D namespace, and then if you want to ratchet up the speed go back to C++.
Windows for a compact device? Get the libraries you need (free download) for Ink and Strokes (forget the library name - it’s for echoing and interpreting stylus input).
Do you want to learn the fastest rendering possible? If so, you probably want to learn DirectDraw (AFAIK, just for Windows).
Yes, Windows. I kind of want to keep everything in the same language to keep from confusing myself, but I’d be willing to try C#. I mean, I do understand that there are a lot of similarities between many of these languages, but it’d be nice to know one language really well rather than bits and pieces of other languages.
I didn’t expect this to be an easy task, and any step-by-step handholding would definitely be appreciated. Are there tutorials that do this? So far I’ve learned my C++ through “Beginning C++ Game Programming.” The pace of the book was a little bit slow for me, but very thorough and it taught me C++ syntax and general programming strategies in a practical manner that I could actually retain.
So you don’t think I’ll be confusing myself by jumping into C# after learning the basics of C++?
The standard for graphics nowadays is an API called OpenGL. It can do 2D or 3D graphics. OpenGL works with C++ quite well. Here is a link to their Getting Started FAQ. Most of what you need is already loaded into Windows, but their may be a couple of other header files you need. There are links to various tutorials, but good place to start is the Red Book, the official OpenGL programmer’s guide. You can buy a copy, but the whole thing is legitimately available as PDF or HTML for free, so the purchased copy is just a convenience.
On the windows-only side is Microsofts DirectX, which does it all (2d, 3d, sound, input, networking, etc). It’s probably what the “Beginning C++ Game Programming” book used, so you might already be familiar with it. If you’re not worried about cross-platform, there’s no reason not to continue with it. There are tons of tutorials out there.
OpenGL is cross-platform. You can use it in such a way as to get 2d out of it, but it’s designed for 3d. It may be a bit much to dive right into. But it’s pretty well integrated with other cross-platform development libraries like SDL.
SDL does 2D graphics, keyboard mouse and joystick input, etc. Pretty easy to pick up, “is written in C, but works with C++ natively” and (again) cross-platform. There are also a ton of add-on libraries for things like fonts, networking, etc. If you’re not going to go with DirectX for whatever reason, then I’d recommend SDL. I was able to knock together a tetris clone without too much trouble, and if I can do it must be pretty easy
Check out GameDev.Net for a pretty active & helpful community. Personally, I would recommend spending some time at the GameDev site no matter which API you decide to go with.
I’m a non-practicing member. Every now and again I go over & read the forums, but I rarely post. Between the job & the family, I just don’t have time to program as a hobby.
I will write a real game one day though. (I can drean, can’t I?)
No, the book employed no graphics–strictly text only. That’s fine, it was perfect for learning logic (I grew up with procedural programming, so getting my mind around OOL and other paradigms is a bit of reinventing the wheel for me) and getting me used to the syntax.
I downloaded the OpenGL, got it installed, and it compiles and runs fine on the free compiler I’m using (Dev Bloodshed C++), but it does seem like squashing an ant with a sledgehammer for what I want to do now. I’ll check out SDL…sounds more up my alley.
Definitely go with SDL, it will let you quickly get into the 2D basics. Also download the SDL_image library to load images without having to know anything about graphic file formats. Within a few function calls you’ll have a window open with the image of your choice in it.
Much as I hate to plug micro$oft products I’d say directX would be easiest. Even if you do only want use it for 2D stuff. IMO It is much easier to learn than OpenGL, has I nice high level C++ interface, and gives all sorts of nice samples and a demo frameword (the price you pay is of course it is part of the Microsoft empire so if you ever want to know whats happening under the hood or run on a non-windows system you’re SOL) http://msdn.microsoft.com/directx/
An alternative would be use Java rather than C++, that would enable you program these browser based 2D games you see everywhere nowadays. I’ve not used it myself by the latest all-singing all-dancing version of Java is available for Beta download:
All those browser-based 2D games you see everywhere on the web now are done with Macromedia Flash, which you can program using their ActionScript (based on ECMAScript, based on Javascript). THe Java applet as we grew to know it in the 1990s is more or less dead.