• Advertisement
Sign in to follow this  

How do I start C++ game programming?

This topic is 3954 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, this is my first post, I think I put it in the right forum, but please move it if it is not. OK, so I have used C++ for a bit and I have worked through 'Teach yourself C++ in 21 Days' and built some programs using that, but I would like to move on to making some simple 2D games and then some 3D games. How do I start? What program should I use? I am using 3 different IDEs, VS C++ Express, Code::Blocks and Dev C++, so I need it to work easily with them. I would also like it to be cross platform (I am switching my computer over to Linux soon). Also, I would prefer it to handle as many things as possible (graphics, sound etc) but that is not necessary, and as small as possible (in memory size). Almost finally, it would be better if it was low cost, I am 14, so I don't have a lot of money and my parents hate paying for stuff off the internet. Finally, how do you make normal C++ GUIs that are cross platform? (A little off topic, maybe I should start a new thread on it) I hope these things are not to unreasonable, I don't mind changing some of my requests a bit. Thanks, Sophie

Share this post


Link to post
Share on other sites
Advertisement
Hi and welcome! Great to see a 14year old girl interested in game programming!

If you already know about C++ that's already a very good start, most people ask how to code game before knowing the language. It help to know more advanced stuff like class inheritance and more important memory manipulation (new / delete / pointers / function arguments by pointer, reference or by value).

Once you know all that and what you seem to be asking is where to go. What you need is to use a graphical library. Theres plenty of them out there.

For non-commercial games lot of people use SDL, it's principally 2D and it's cross-platform. It also offer support for input and sounds :
http://www.libsdl.org/

Then there's OpenGL. It's the major cross-platform 3d library. the .lib/.h files to use it come with VC++ and most linux distribution.I started to learn with it some years ago using nehe tutorials:
http://nehe.gamedev.net/

Still, for commercial games OpenGL is kinda dead. Nearly every games today use DirectX and if you want to learn something why not start with the real thing? It's powerful and allow you to use all the latest video cards features. Sure it's not cross-platform but do you really care? I don't :P It work flawlessly with visual studio. DirectX contain Direct3D for graphics but also DirectSound, DirectInput, etc. To use it you must download the February 2007 DirectX SDK. Some example and tutorials comes with it.
http://msdn.microsoft.com/directx/
This might help for better tutorials : http://www.codesampler.com/source.htm

Then there's XNA Game Studio, Microsoft new baby for beginners. It force you to code in C# and use DirectX underneath but it's a lot easier.

Share this post


Link to post
Share on other sites
Quote:
Original post by PowerPython
Hello, this is my first post, I think I put it in the right forum, but please move it if it is not.

Perfect forum, as far as I'm concerned.

Quote:

OK, so I have used C++ for a bit and I have worked through 'Teach yourself C++ in 21 Days' and built some programs using that, but I would like to move on to making some simple 2D games and then some 3D games. How do I start? What program should I use?

I am using 3 different IDEs, VS C++ Express, Code::Blocks and Dev C++, so I need it to work easily with them. I would also like it to be cross platform (I am switching my computer over to Linux soon).

Also, I would prefer it to handle as many things as possible (graphics, sound etc) but that is not necessary,

A free IDE and compiler + a bunch of free libraries is all you need. But I would warn you against doing as much as you can do - it's a lot of work, and it's more likely to become frustrating in the end. You'd better use existing libraries to handle things that are difficult to code (image files reading/writing, physics or collision handling, and so on). The faster you'll get a small game, the better you'll feel, and the easier it will be to begin a bigger project in which you'll code more things by yourself.

It's quite easy find 2D or 3D engines out there (but be careful about 3D: 3D models are hard to get, and in fact you need a lot more content to make a 3D game than to make a 2D game. Creating content is not difficult - you have the right age to learn 3D modeling and content creation - but it's quite slow, especially if you also do the coding).

You'll also easily find free 3D modelers (blender comes to mind) and 2D image manipulation programs (for example, The Gimp).

In fact, everything you need can be found on the intarweb.

and as small as possible (in memory size).
As of today, there is no real need for memory constraints - unless you end with a software that use several gygabytes of memory, which is quite rae [smile].

Quote:
Almost finally, it would be better if it was low cost, I am 14, so I don't have a lot of money and my parents hate paying for stuff off the internet.

You can develop games for 0 bucks - you only need time (which is also a valuable resource, but the investment is up to you).

Quote:
Finally, how do you make normal C++ GUIs that are cross platform? (A little off topic, maybe I should start a new thread on it)

Keep it in that thread - we don't mind answering multiple related questions in one single thread.

There are different C++ GUI libraries out there: wxwidget is one of them (open source). You can search for many other GUI on the intarweb as well.

Quote:
I hope these things are not to unreasonable, I don't mind changing some of my requests a bit.

Thanks,
Sophie

Asking for World Peace in unreasonable. Asking for free software and information isn't [smile].

Good luck with your projects!

Share this post


Link to post
Share on other sites
I'd definitely recommend SDL. It's a cross-platform 2D library, and it also includes optional libraries for stuff like image loading, sound, and even networking.

I'd advise that you stick with 2D until you have more experienced; don't jump into 3D yet. 3D is much more complicated and has more setup involved. It's better to get experience making games in 2D and have some completed projects, instead of trying to jump right into DirectX.

Share this post


Link to post
Share on other sites
Actually, you need the Platform SDK for OpenGL on Windows. You can find this on MSDN.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dunge
For non-commercial games lot of people use SDL...
Are you sure that no commercial games use SDL?
Quote:
Still, for commercial games OpenGL is kinda dead. Nearly every games today use DirectX and if you want to learn something why not start with the real thing? It's powerful and allow you to use all the latest video cards features. Sure it's not cross-platform but do you really care? I don't :P It work flawlessly with visual studio. DirectX contain Direct3D for graphics but also DirectSound, DirectInput, etc. To use it you must download the February 2007 DirectX SDK. Some example and tutorials comes with it.
From the OP's post:
Quote:
I would also like it to be cross platform (I am switching my computer over to Linux soon). [emphasis mine]
Keep in mind that many people do in fact care about portability and the ability to target multiple platforms :)

Share this post


Link to post
Share on other sites
For GUI:s take a look at GTK+, QT or wxWidgets. And for game programming I suggest SDL, at least in the beginning. SDL is quite easy to understand and crossplatform.

Some links:
http://www.gtk.org/
http://www.wxwidgets.org/
http://www.trolltech.com/products/qt/
http://www.libsdl.org/

Good luck with the programming!

P.S I'm just one year older than you. I thought I nearly was the only one interested in programming at that age. :P

Share this post


Link to post
Share on other sites
A girl interesting in game programming, it's strange :d.

So as others has said, SDL is a good point if you know C++, but you'll be limited in 2D. Then you can move on with 3D with OpenGL ! There is a very good website in French that teaches you SDL, but it's in French :/ (maybe you understand : http://www.siteduzero.com/tuto-3-8-0-apprenez-a-programmer-en-c-c.html#part_1544 ).

Share this post


Link to post
Share on other sites
Quote:
Original post by Adam4444
For GUI:s take a look at GTK+, QT or wxWidgets. And for game programming I suggest SDL, at least in the beginning. SDL is quite easy to understand and crossplatform.

Some links:
http://www.gtk.org/
http://www.wxwidgets.org/
http://www.trolltech.com/products/qt/
http://www.libsdl.org/

Good luck with the programming!

P.S I'm just one year older than you. I thought I nearly was the only one interested in programming at that age. :P


More to say about these: GTK+ is a pure C library, although you may find C++ bindings. Architecture-wise, it's a bit overengineered, and really not easy to use. I somewhat dislike it (and that's not because I don't know it: I used to be the GTK+ FAQ maintainer, and I've dived into the code quite often).

Qt is a fairly good library - I used it for many personnal AND professional projects. But it's doomed with a problem: if you intend to distribute your program, you will only have two solutions:
1) pay for a license. Be aware that It Costs A Lot.
2) distribute your software under the terms of the GPL.
Of course, if you don't distribute your work, you can use it freely.
But It's really great software - and the Qt Designer will help you to build your graphical interface fastly. Their signal/slot mechanism is a bit awkward at a first glance, but it was designed before the standard compliant compiler era, so forgive them [smile].

WxWidget is also a good cross platform libary, with concepts similar to the MFC (Microsoft Foundation Class). It's not limited by any restriction, and is now very mature. It's worth a try.

Regards,

Share this post


Link to post
Share on other sites
Many people have suggested using SDL and I can only agree with them. Using SDL is pretty easy and there are some nice tutorials out there. The largest advantage of SDL is that you'll probably end up with some nice results in a short amount of time. I can't comment on your patience, of course, but I always find it very valuable to see results quickly because they motivate me to continue with something. Undoubtedly the same goes for many people.

As for OpenGL, I would not start using that yet. OpenGL is a great API, don't get me wrong here, but it's designed with the purpose of showing 3D graphics in mind, and using it for 2D graphics to start with might be confusing as you probably won't care so much about projections etc. yet. Also, OpenGL requires you to either know how to create windows for a certain platform (winAPI for windows, XLib for UNIX systems...) or use external libraries that set up windows for you. SDL doesn't have all these sources of confusion - SDL handles all that itself so it's much quicker to get started with game coding, rather than 'set-up' coding.

Having said that, I realise this post would be pretty useless without a link to a good tutorial. I am surprised nobody mentioned Lazy Foo's tutorials for SDL yet, but I think you will find them very handy - at least, I did.

You can find Lazy Foo's tutorials here!

Regards,

Rogier

Share this post


Link to post
Share on other sites
Quote:
Original post by Dunge
-snip-
Still, for commercial games OpenGL is kinda dead. Nearly every games today use DirectX and if you want to learn something why not start with the real thing?
-snip-


How much did microsoft pay you to say that ?

virtually every single game for the PS3 and MacOSX Platforms use OpenGL or OpenGL:ES while DX is only fully supported by Windows Vista. (Not even the 360 has full DX support).

Other than those simple facts OpenGL has the exact same features as D3D10 (Except with OpenGL you can access those features on WindowsXP, MacOSX, GNU/Linux and any other system that has appropriate drivers for the hardware).

Thus claiming that DX is "The real thing" is pure ERASED - I know you're a valuable guy, but try to restrain your vocabulary when you discuss with younger guy/girls.

[Edited by - Emmanuel Deloget on March 25, 2007 8:18:03 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by rogierpennink
Also, OpenGL requires you to either know how to create windows for a certain platform (winAPI for windows, XLib for UNIX systems...) or use external libraries that set up windows for you. SDL doesn't have all these sources of confusion - SDL handles all that itself so it's much quicker to get started with game coding, rather than 'set-up' coding.
Just to clarify this a little, SDL can create an OpenGL rendering context for you; you don't need to write any platform-specific code yourself in order to use OpenGL with SDL.

Share this post


Link to post
Share on other sites
I went through all the opengl tutorials on nehe's sight and never looked back. so far i've been able to do everything that i want in opengl with no problems. and as people have mentioned above, it's a lot easier to use SDL to set up the window than to do it yourself. (although you can also use the NeHeGL files to handle the window). so i'd highly recommend opengl.
for sound i use "fmod" which is quite easy to understand. "bass" is also good but it takes more steps to load a song and play it then fmod.
Good Luck, and have fun!

Share this post


Link to post
Share on other sites
SDL is actually pretty... er... C-like from what I've seen. It's workable, but it really could use some wrappers. Seems like everyone who uses it ends up either writing the same "managers" and RAII wrappers etc. as everyone else, or goes around in circles getting nothing of consequence done.

Then again, it seems like most 2D graphics APIs are like that. x.x

I'm tempted to do a full set of wrappers and do it really right, using Lazy Foo's tutorials as a checklist. But I don't really have the time :(

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Seems like everyone who uses it ends up either writing the same "managers" and RAII wrappers etc. as everyone else, or goes around in circles getting nothing of consequence done.
You are right about that (except perhaps for the 'getting nothing of consequence done' part :).

Still, building a decent object-oriented framework around SDL will in most cases be a less time-consuming task than writing an OO framework and writing oodles of platform-specific code for windowing, events, sound, image loading, and so on, so in my opinion using SDL is a still a clear win.

Share this post


Link to post
Share on other sites
I'd suggest the OP go a more middle route. I suggest doing 2D graphics with a 3D api. There are lots of tutorials out there showing how to render 2D sprites and such in opengl and direct3d. Despite what another poster said, setting up the projection matrix for 2D rendering isn't THAT hard (glOrtho). And this'll give enough of an intro to the api that moving over to 3D will be less painfull.

If you stick to c++, I recommend opengl and sdl, and following nehe's tutorials. OpenGL and SDL give a much more gentle introduction: it takes much less code to get a window created and to render some triangles. And direct3d's c++ api is very daunting to a new programmer.

If you decide to try c#, I recommend managed directx or xna. Both are much simpler and cleaner than their c++ counterpart.

[off topic]

Quote:
Original post by SimonForsman
How much did microsoft pay you to say that ?

virtually every single game for the PS3 and MacOSX Platforms use OpenGL or OpenGL:ES while DX is only fully supported by Windows Vista. (Not even the 360 has full DX support).

Other than those simple facts OpenGL has the exact same features as D3D10 (Except with OpenGL you can access those features on WindowsXP, MacOSX, GNU/Linux and any other system that has appropriate drivers for the hardware).

Thus claiming that DX is "The real thing" is pure ERASED - I know you're a valuable guy, but try to restrain your vocabulary when you discuss with younger guy/girls.


I'm not a microsoft fanboy, but most of what you say here is totally false. I don't mean to drive the thread off topic, but I hate to see flagrant misinformation go uncorrected.

First of all, DirectX isn't only supported on vista. It works for XP and a number of other versions. Yes OpenGL works on non-windows platforms, but those make up a much smaller portion of the market (not counting consoles of course). I'm not going to argue that one is better than the other, but the fact is that there are vastly more direct3d games out there than opengl ones.

The xbox 360 does support Direct3D, except that it lacks the fixed function pipeline. You just have to use shaders for everything. And modern games do that anyways.

At the moment opengl does not have all the features of direct3d 10. There are similarities, for example direct3D 10 no longer does kernel mode switching, something it has in common with opengl. But does opengl support geometry shaders or a unified pipeline? Nope, not yet. I'm sure it will though.

Let's not spread false information just because you don't like Microsoft, which I suspect is the case with you, judging from your first sentence.

[/off topic]

Share this post


Link to post
Share on other sites
Quote:
Original post by gharen2
I'd suggest the OP go a more middle route. I suggest doing 2D graphics with a 3D api. There are lots of tutorials out there showing how to render 2D sprites and such in opengl and direct3d. Despite what another poster said, setting up the projection matrix for 2D rendering isn't THAT hard (glOrtho). And this'll give enough of an intro to the api that moving over to 3D will be less painfull.

If you stick to c++, I recommend opengl and sdl, and following nehe's tutorials. OpenGL and SDL give a much more gentle introduction: it takes much less code to get a window created and to render some triangles. And direct3d's c++ api is very daunting to a new programmer.

If you decide to try c#, I recommend managed directx or xna. Both are much simpler and cleaner than their c++ counterpart.

[off topic]

Quote:
Original post by SimonForsman
How much did microsoft pay you to say that ?

virtually every single game for the PS3 and MacOSX Platforms use OpenGL or OpenGL:ES while DX is only fully supported by Windows Vista. (Not even the 360 has full DX support).

Other than those simple facts OpenGL has the exact same features as D3D10 (Except with OpenGL you can access those features on WindowsXP, MacOSX, GNU/Linux and any other system that has appropriate drivers for the hardware).

Thus claiming that DX is "The real thing" is pure ERASED - I know you're a valuable guy, but try to restrain your vocabulary when you discuss with younger guy/girls.


I'm not a microsoft fanboy, but most of what you say here is totally false. I don't mean to drive the thread off topic, but I hate to see flagrant misinformation go uncorrected.

First of all, DirectX isn't only supported on vista. It works for XP and a number of other versions. Yes OpenGL works on non-windows platforms, but those make up a much smaller portion of the market (not counting consoles of course). I'm not going to argue that one is better than the other, but the fact is that there are vastly more direct3d games out there than opengl ones.

The xbox 360 does support Direct3D, except that it lacks the fixed function pipeline. You just have to use shaders for everything. And modern games do that anyways.

At the moment opengl does not have all the features of direct3d 10. There are similarities, for example direct3D 10 no longer does kernel mode switching, something it has in common with opengl. But does opengl support geometry shaders or a unified pipeline? Nope, not yet. I'm sure it will though.

Let's not spread false information just because you don't like Microsoft, which I suspect is the case with you, judging from your first sentence.

[/off topic]


The current version of D3D (Version 10) (The only one that supports modern hardware) is only avaliable on Windows Vista.

if we should keep talking about deprecated API:s i could claim that DX works on any OS (as Wine does handle old DX versions (DX7 for example) very well.

OpenGL has geometry shaders through the
NV_geometry_program4
and
NV_geometry_shader4
extensions.

There are also new extensions for fragment(pixel) and vertex shaders.

The unified architecture is 100% driver managed and isn't really an issue.

so yes. OpenGL has support for those features if you have a card that support them.

And more importantly, OpenGL has support for those features on Windows XP (Which is the most important market right now). D3D doesn't. (As only obsolete D3D versions are avaliable for that OS (The same is true for the 360, though its not a big issue there as its D3D version is enough for its hardware)).

i have nothing against microsoft or their products, however i strongly dislike their attempts to convince the general public that you need Vista and D3D10 to use modern hardware. (Which is an outright lie)

I even use Windows XP daily, it is my favourite system for gaming and my main development OS. As such i wouldn't recomend an API that doesn't give that system full access to the latest hardware.

FYI , OpenGL had extensions for all G80 hardware features before D3D10 was released.

Share this post


Link to post
Share on other sites
Ok, you have good points. The one about the unified architecture being driver managed is certainly a valid one. And I agree, opengl will probably go through another golden age, as it will indeed allow direct3d 10 features on xp. Haha, I wouldn't be surprised if this causes microsoft to release an updated version of direct3D9 for xp.

I hadn't realised nvidia had implemented a geometry shader extension. That's pretty cool. The question is, how long will it take the ARB to accept it?

I personally still see Direct3D10 as "upcoming", rather than "modern". It's going to be a long time before Direct3D10 cards are a household item, and my money says it'll be a couple years before we see Direct3D10 only games. And vista also supports Direct3D9, so I don't consider it deprecated. Especially for new programmers like the OP.

Regardless, we're way off topic. Although I'm still inclined to disagree some, I think we both have valid points. I just think you're getting ahead of yourself. OpenGL games running on XP using Direct3D10 hardware being commonplace is probably a couple years off.

PS - I should mention that I too use XP, and when working in c++ I prefer opengl.

Anyways, /me shuts up now.

Share this post


Link to post
Share on other sites
Quote:
Then there's XNA Game Studio, Microsoft new baby for beginners. It force you to code in C# and use DirectX underneath but it's a lot easier.


I we're think that, I have trained my C++ a lot and win32 api skills some.
Like making windows and so on. But I wondered did I lost all my time for praticing those, If i want to move on XNA Game Studio and code on C#.

I Thought C++, win32 and DirectX is what it need to pratice, and I use
MS Visual Studio 2005.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ubernt
Quote:
Then there's XNA Game Studio, Microsoft new baby for beginners. It force you to code in C# and use DirectX underneath but it's a lot easier.


I we're think that, I have trained my C++ a lot and win32 api skills some.
Like making windows and so on. But I wondered did I lost all my time for praticing those, If i want to move on XNA Game Studio and code on C#.


Kmowledge is never lost.

You'll find similar concepts in C#. Of course, C# doesn't use the Win32 API (at least, not in a visible way), but with the API knowledge comes the implicit knowledge of how things are done - plus some training to learn how to learn, which is never bad.

Quote:
I Thought C++, win32 and DirectX is what it need to pratice, and I use
MS Visual Studio 2005.


Anything should be an occasion to practice. But don't take the mean for the end. As a beginner programmer, the end is to learn how to program, and the mean is to make programs that satisfy your curiosity, so that you can enjoy practicing. When you're no more a beginner (ro when you are a professionnal), the end is to make programs that works, and the mean is to sharpen your programming skills.

Best regards,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement