PDA

View Full Version : Getting Started with C(++)


Eriond
05-22-2006, 11:53 PM
First, an introduction :p

What is a programming language?

Programming languages are a way to write a set of instructions which your computer can follow. However, you can't just type the code in a text file, and expect the computer to run and understand your commands. Most languages used for heavy-duty games these days are what are called compiled languages, meaning that in order for the computer to understand the code you've just written, you have to get a program, called a compiler to turn your text into binary commands, that the computer can understand. Essentially, everything on your computer was written in one programming language or another. Windows was written mainly in C, an early compiled language, with some of the more low-level functions coded in ASM (which is essentially hand-written binary). Most games these days are written in C++, C# or Java. (Games that don't need to be so fast are also written in Visual Basic)

What is C++?

C++ is a programming language, revered as the mother of all compiled languages (this is figurative. It's not actually the first compiled language, it's just viewed as the one that's best for game programming), and looked at as the perfect language for writing games, though this is now changing, as C# rises in popularity. I'm not going to go into that, since I don't know C#, and this tutorial is about C++. :D

IDE Installation

And here's the link to a C(++) compiler, along with a nice IDE (a nice text editor with a bunch of functions added into it) : http://prdownloads.sourceforge.net/dev-cpp/devcpp-4.9.9.2_setup.exe
(Some people say that Dev-C++ isn't that great an IDE, and they prefer the MSVC++, and I know that it's compiler does a better job of optimizing, and it has a better debugger, I'm just so damn used to Dev-C++, that's why I'm reccomending it. Check out the MSVC++)

Okay. That's pretty easy to install, you just double-click the exe, and follow through with the installation. Don't worry about any specifics that pop up. Just install as much as you can. Once it's installed, run it.

Coding

Now, if you're looking to write games, I'm afraid it's going to be a while before you can do that. You have to learn the basics of the language and whole bunch of other stuff before you can go on to write your perfect dream MMORPG. This is not exaclty a task for the faint of heart. To write an MMORPG, you need to master a graphics library, a networking library, a windowing library, or several wrappers which encompass one or more of those libraries.

However, this is not to say you can't write simple games like tic-tac-toe relatively fast. But you still need to know the basics. So, with that in mind, let's get started with coding.

Inside Dev-C++, go to

File --> New --> Project

Click console application, then click okay. Save the file where you want to save it, by default, it's in the Dev-Cpp folder, but you can save it anywhere.

Once that's done, you can start coding.

The place I learned to code from was:
http://www.cprogramming.com/tutorial/lesson1.html

That should get you started. You should be able to put stuff out into a command prompt after the first lesson. While that might not sound like much, it's a great step forward. Read through the tutorials on the cprogramming site. By the time you get to the... oh, I don't know, the inheritance tutorial, and you can do all the other stuff pretty much off the top of your head, you should be ready for the next step (which was in my case, Win32 programming, though it varies depending on what you want to do, or who you ask).

Anywho, if you can master the tutorials on that site, you'll be one step closer to writing your very own graphical game. And remember, even if you can't see how an aspect of the tutorial could possibly relate to gaming, trust me, it probably does. Just stick with it.

If you have any questions, just post here, and I'll be glad to answer to the best of my ability.

Important
I cannot stress enough that if you want to make a 3D RPG, MATH is required. Yes, math. I know. We all hate it. Math is stupid. It's never used, like, anywhere. Unfortunately this is like the one field where it's necessary. If you want to make a 3D or even 2D RPG, you should know the following:


Basic Trigonometry
Shape and Patterns of all the Basic Functions (x,sinx, absx, x^2, x^3, etc..)
Vectors
Basic Algebra
Matrix Math (3D Only)


Don't worry if you don't know some of these, just follow the link to the math site at the bottom of this post and it has a bunch of tutorials regarding the subjects.

Useful Links:

C++ Language Tutorials: http://www.cprogramming.com/
Very Nice Win32 API Tutorial by TheForger: http://www.winprog.org/tutorial/
Totally complete OpenGL tutorials, explaining all the basics behind the API : http://nehe.gamedev.net/
SDL Library, and Tutorial Index: http://www.libsdl.org/index.php
Networking Tutorials (on windows): http://www.madwizard.org/view.php?page=tutorials.networking.contents&lang=cpp
Math Tutorials: http://www.math.com/

Oh, and here's a nice tip from Elegy:

That's why I have also tooken up a habit to put a comment ( // or /* *\ - you will read about these in the first tutorial in the given link by Eriond) at the very end of my "Hello World" Project, to summarize what I have learned so far. I found this is a much easier way to go over what I have learned, instead of manually searching through the tutorials about it. I also noticed that the tutorial uses several different words that *may* throw some people off and confuse them.. if you don't understand a meaning, keep reading. You will eventually find out what it means or what it is used for.

Kevinboyz
05-23-2006, 12:04 AM
I think i would mess up my brain trying to learn those. It takes way too long >_< (8yrs) and double for me :(

MisterPoppet
05-23-2006, 12:06 AM
Nah.. Depending on how hard you worked on it, it would only take 2-3 years to get enough know-how to start doing games and such (especially if you focused on games).

-Bryan-

HopeDagger
05-23-2006, 01:16 AM
Sure; this works as sticky material for me. :)

I'm hoping to get a guide/tutorial system up soon, which Gabe has mentioned that this new forum is capable of doing. So this can remain stickified until we reach that point.

Thanks for the contribution, Eriond!

shemer77
05-23-2006, 08:07 PM
This is great thx.Does anybody have other tutorials? Link dosent work.

Eriond
05-23-2006, 08:31 PM
Odd that it doesn't work... just checked and it works fine for me. Oh well.

http://www.cplusplus.com/doc/tutorial/

There's another site. I'm not sure how good the tutorials are, but they look ok.

PowerGamer
05-25-2006, 05:23 PM
I tried learning C++.. got bored XD
if I choose to make games later in life, ill come back to C++
im only 14 now

shemer77
05-25-2006, 11:38 PM
lol not tutorial link.The other one to download it.Lucky i searched the thing on google and found it.Forgot link though sry:mad:

Eriond
05-26-2006, 06:12 PM
Ah yeah. Fixed that now :) The board decided to actually turn the URL into a string with ellipses in it... anyway. Yeah. Fixed.

shemer77
05-26-2006, 09:45 PM
Thanks.This really helped.

GhostManZero
05-28-2006, 05:28 PM
[reply Deleted]

Sman
05-29-2006, 10:54 PM
I'd like to meantion that the IDE recommended here is great. I used it for years and still check the site, but has not been update for a VERY long time, and is lagging behind various other projects. Due to that, I had to find something that was more stable. I would like to suggest anyone that finds Dev-C++ crashing a lot (like I eventually did) to try out Code::Blocks - site: http://www.codeblocks.org/ , it works with the same compiler(MinGW, a seperate product) included with Dev-C++ and is just as capable in the features and functions it supports.

naruto1327
06-19-2006, 05:10 PM
I tried learning C++.. got bored XD
if I choose to make games later in life, ill come back to C++
im only 14 now

Actually, starting early in life is actually kinda good. It can also be bad though...

PowerGamer
06-19-2006, 06:20 PM
Actually, starting early in life is actually kinda good. It can also be bad though...

I see you're good at contradicting yourself <.<

naruto1327
07-01-2006, 08:11 PM
Lets not get off-topic. ;)

Piggy-Bank
07-06-2006, 11:13 PM
when you say the folder DEV C++, is that the thing you get when you get a compiler?

Cj Shadows
07-10-2006, 02:04 AM
Ok one question i feel stupid now. I use Bloodshed Dev-C++ and i thought that was the compiler cause u write the code in it and hit the compile button. Do i still need that extra compiler because when i do try to compile it says cant run program?(and all the code is right)

Eriond
07-10-2006, 06:54 PM
when you say the folder DEV C++, is that the thing you get when you get a compiler?

Uh... it doesn't have to be the Dev-Cpp folder, it can be anywhere. But yes, the folder itself is created when you install the program.

Ok one question i feel stupid now. I use Bloodshed Dev-C++ and i thought that was the compiler cause u write the code in it and hit the compile button. Do i still need that extra compiler because when i do try to compile it says cant run program?(and all the code is right)

Dev-Cpp is the IDE. It goes over the compiler, which is the G++ (or GCC). They both come with Dev-Cpp and are installed along with the IDE. If your project isn't compiling, try exiting Dev-Cpp and restarting, then compiling again. It's happened to me once or twice, when a program crashed, that I can't recompile it. Just restart and it should work out.

Cj Shadows
07-10-2006, 07:28 PM
Uh... it doesn't have to be the Dev-Cpp folder, it can be anywhere. But yes, the folder itself is created when you install the program.



Dev-Cpp is the IDE. It goes over the compiler, which is the G++ (or GCC). They both come with Dev-Cpp and are installed along with the IDE. If your project isn't compiling, try exiting Dev-Cpp and restarting, then compiling again. It's happened to me once or twice, when a program crashed, that I can't recompile it. Just restart and it should work out.
oooo okay thanks! I was doing some stuff for Eternal-Lands and it wouldnt let me compile, so i went to the site again and it said to use the script for the client download this thing called Tortise CVS, do you know what that is and is used for?

Eriond
07-11-2006, 06:54 AM
I really dunno much about CVS. I just did a bit of reading, and it's a version control system. From what I understand, it helps keep track of who's developing what in a software project. Just google Tortoise CVS or Wikipedia it, and see what comes up.

Here's the website for the program itself:
http://www.tortoisecvs.org/

freespace2pilot
07-17-2006, 10:48 AM
hey, first post from me :)

i've been reading through the cprogramming tutorials for the passed couple of days, and i've pretty much got the hang of it, so, what next?

i've been using The Games Factory and MultiMedia Fusion prior to learning c++, and i'd like to be able to write something in c++ that's up the standard of a basic tgf game. so yeah, would someone point me in the direction of some 'win32 graphical programming for utter morons' tutorials? =3


EDIT: and look at me, i forced third page >w<

Eriond
07-17-2006, 08:08 PM
Lol, no problem. Hold on, let me dig something up. Well, if you wanna start directly with graphics programming, go for SDL. It's esay to setup and use, and it's got a bunch of tutorials about it. (Problem is, that along with the Win32 GDI+, it's slow). If you want speed, you're gonna have to go for OpenGL or DirectX.

Anyway, here are some tutorials for SDL and the GDI.

I learned Win32 and the GDI from here:
http://www.winprog.org/tutorial/

and SDL from here:
http://lazyfooproductions.com/SDL_tutorials/index.php

Anyway, that should help you get started :)

freespace2pilot
07-17-2006, 11:44 PM
thankyou muchley! ^^

dedge
07-18-2006, 10:27 PM
A Bunch Of Starting Stuff For OpenGL-

http://nehe.gamedev.net


-I Swear A Tear Will Fall From Your Eye When You Make A Polygon...

freespace2pilot
07-20-2006, 08:21 AM
and many tears before that whilst trying?

naruto1327
07-20-2006, 09:54 PM
lol.

10 tears for failing. =P

freespace2pilot
07-21-2006, 09:56 AM
hrm.. i didnt get close enough to even try - i keep getting some errors about a nonexistant library that the tutorials want linked. i'm using devc++ if anyone wants to shed some light on the matter..

naruto1327
07-21-2006, 09:26 PM
Did you shed a tear or perhaps some sweat whilst getting frustrated?

Eriond
07-21-2006, 11:44 PM
hrm.. i didnt get close enough to even try - i keep getting some errors about a nonexistant library that the tutorials want linked. i'm using devc++ if anyone wants to shed some light on the matter..

Let me guess... Glaux?

Stevz
07-27-2006, 12:41 AM
A Bunch Of Starting Stuff For OpenGL-

http://nehe.gamedev.net


-I Swear A Tear Will Fall From Your Eye When You Make A Polygon...

I assumed the same thing when I took a look at how you make a damned window.

You are truely a ledgend if you can do that. I might sit back and use Java... J/k. :p

Eriond
07-27-2006, 01:51 AM
Lol, it's not so bad. To be honest, you don't have to understand all of it to use it. Once you get some of the code, like window creation out of the way, it's out of the way for good :) (Usually, lol)

Dennis56
08-06-2006, 07:16 AM
and java dosent have any value anymore?lol I know games i java arent that common however i'm still willing to learn it

naruto1327
08-06-2006, 07:54 PM
For some reason, I don't like Java.

Jetto
08-22-2006, 04:43 PM
Great topic..Im trying to study it during my free0time and all..GREAT topic and erilond great stufff!

Elegy
09-14-2006, 01:52 AM
This post pretty much made me start wanting to learn C++. I have been wanting to attempt it since I was around 14-15, but never knew what the crap I was supposed to do, etc., and now I am 18 just starting it hehe :).

I've decided to try to work on 1 of Cprogrammings project every other day, as in one day, read through the tutorial and do what it says, take the quiz, and score myself, then the next day go over what I learned and study into it a bit more, and take the quiz, *hopefully* making better than the previous score. So far I missed 1 question on the first quiz, due to not remembering covering something hehe.

I just figured fellow newbies might find my method a helpful way in learning, so that's why I posted the above. I'm sure later on in c++ the tutorials will get harder, or my goals get harder, and be forced to take a much longer time completing the.... "assignment". That's why I have also tooken up a habit to put a comment ( // or /* *\ - you will read about these in the first tutorial in the given link by Eriond) at the very end of my "Hello World" Project, to summarize what I have learned so far. I found this is a much easier way to go over what I have learned, instead of manually searching through the tutorials about it. I also noticed that the tutorial uses several different words that *may* throw some people off and confuse them.. if you don't understand a meaning, keep reading. You will eventually find out what it means or what it is used for. Anyways, hope I helped a few fellow newbies with my methods, and thanks a TON for this very helpful post Eriond.

Eriond
09-14-2006, 03:33 AM
Hey. Thanks for the thanks :p I'll put your idea in the main post, it sounds like a good one :)

onrpgfan
09-15-2006, 01:51 PM
mr. edrion can you help me somtimes about some terms in C++, if i cant understand some of them can i ask u about it? thanks you gave me a great website for that tutorial , i bet it is very easy to understand thanks:p

onrpgfan
09-15-2006, 01:54 PM
sorry what i mean is mr. eriond thanks!!!

Eriond
09-16-2006, 03:27 AM
Lol, sure, whenever. Just add me on msn: aharriso56@hotmail.com

If you don't have MSN, just PM me over the forums, and I'll try to help you out :p

lamakila123
10-23-2006, 01:23 PM
to^^


i was just wondering what i should learn next after i get c++ down and win32 programing..... thanks........

pb_destiny
10-23-2006, 09:15 PM
Well it all depends on what type of programming your looking to get into, I would suggest learning SDL.

If you want to get into graphics programming, maybe even game development than you'll want to learn use a graphics API like Opengl or DirectX.

-PB

Eriond
10-24-2006, 03:35 AM
Well it all depends on what type of programming your looking to get into, I would suggest learning SDL.

If you want to get into graphics programming, maybe even game development than you'll want to learn use a graphics API like Opengl or DirectX.

-PB

Yeah, that's the exact route I went. C++, Console, Basic Windows, Win32 GDI, SDL then OpenGL. It's all be going over the span of a single game which keeps getting upgraded. First from crappy 2d, to slow 2d, to fast 2d, to 3d now ^_^.

TótóálWár
07-28-2007, 10:54 AM
Hey thanks for the tips. Though you dont have to make mmorpg's with coding language. And im 14 and i have made FPS games and a few MMOs in my time so age has nothing to do with anything.
Thanks again,
Tótóál.

naruto1327
07-30-2007, 01:10 AM
Hey thanks for the tips. Though you dont have to make mmorpg's with coding language. And im 14 and i have made FPS games and a few MMOs in my time so age has nothing to do with anything.
Thanks again,
Tótóál.

You are correct that age has nothing to do with anything (maybe some things relating to business, but eh), but that first part... :-/

Jatter
08-28-2007, 12:33 PM
Heey, I have the book Sams C++ in 21 days 3rd edition and was wondering if I should use the book or the tuts on cprogramming?

AtomSlap
08-28-2007, 02:27 PM
Heey, I have the book Sams C++ in 21 days 3rd edition and was wondering if I should use the book or the tuts on cprogramming?

Use the book, then site tuts, then the book again, then site tuts again.

And Total War, you have no coded several MMOs at the age of 14.
And yes, sometimes age has a role in game deveopment. It's more likely that a 35 year old man has made 3 ORPGs rather than a 14 year old made 3 ORPGs.

Jatter
08-28-2007, 02:40 PM
Use the book, then site tuts, then the book again, then site tuts again.

Ok, Thank you for the awnser:)

Deceth
02-06-2008, 06:52 PM
Great article!

Anyone getting started, you have to realize that programming a game isn't all fun and games until you are done and can then spend all your time playing the game. Don't give up though, even if its complicated or boring at first. The rewards are worth the effort!

Also, start with a small project. Set yourself up to succeed, not fail. Work your way up slowly to bigger and bigger things.

Dabia
04-01-2008, 07:13 PM
Iam following a gaming education and I have the subject Programming ofcourse and i learn Blitz first. I don't know why though maybe because it's easier than C++, anyway my point is if you want to learn some basic coding i can tell you, you can go to www.blitzbasic.com as well and order that program. You can make pretty nice things in it even the MMORPG engine RealmCrafter is written in it. Well to make a long story short if you want to learn to program you have some choices in languages and i can tell you that Blitz is easier than C++. Iam off coding again at my 3D game