![]() |
C Game Programming |
C Game Programming tips and AdviceIntroductionThe C language for game programming is a very popular, many commercial titles such as Quake were written in this language. The reason C has been so widely used is because of its power. The language will allow you to do anything, from optimising your system level rendering code to easily crashing the system. If you are just starting out programming and thinking of C as a game programming language, be warned, it is not an easy language learn. You will spend countless time wondering what is wrong with your command syntax and then trying to figure out the cryptic error messages the compiler will give you. Take a class or get a good book. Though if you feel that you are ready to move on from something like Visual Basic or Delphi then C is an excellent choice. If you a serious about game programming you ‘will’ want to learn this language. The increased things you can do in you game projects will be a big benefit and if you should want a career in game programming or other parts of the computing industry this language is the way to go. Another advantange of the C language is the API's (Application Programmers Interface) that you can use. For graphics you have the 2 most popular: DirectX and OpenGL. For sound there is a great one available called FMod. After you have a firm grasp on this language learning C++ is just one more step. It uses the same syntax but it adds structure by using ‘classes’. C++ allows you to write object orientated programs that allow you to more easily manage large projects.
Getting started To get started you will need to get a compiler. There are quite a few around, a commercial one is best but there are some freeware ones too. DOS is dead technology, I wouldn’t recommend bothering too much with it, so make sure you can compile Windows code when picking a compiler. The freeware ones have the disadvantage of lack of support and generally don’t have a nice GUI so commands will have to be typed in a DOS prompt. It’s tough to find books and examples that will work without a lot of tinkering. My recommendation is Microsoft’s Visual C++. It is used throughout the industry and has every feature you can think of. It is a C++ compiler, but is, of course, able to compile straight C code. Many books use this for their examples and so do most webpages. Taking classes is a good way to learn the language, but there are also many books available. You can also try learning a few things off web page examples. My copy of Visual C++ came with an e-book on learning the language.
Graphics As for adding graphics to your games, C game programming has the pick of the crop with DirectX and OpenGL. There are many arguments on which is better, but they both perform relatively the same. OpenGL has a simpler syntax and I feel it is easier to learn. The good thing is once you have learnt one the other isn't too hard to pick up. Check out the projects and games on the main page, they were all done with OpenGL. You could optionally use something like Allegro, while it is good and is more than just a graphics library, it hasn't caught on to the extent of the others.
Sound When adding sound to your C programs DirectX doesn't make things very easy. There is a library called FMOD that I have found too easy to use and is available on most platforms including consoles. It is free to use unless you are going to make money off your games. You only need to make an initialization in your program, then call a function to play your sound file.
Source Code Want some source code examples of some C game programming in action?
The Future C/C++ is the industry standard for game programming at the moment. The only real looking competitor is Java but that still looks like a long shot. Looks like C game programming will be in action for a while yet.
|