Page 1 of 4
How much c++
Posted: Tue May 05, 2009 1:26 pm
by jtst1
I've been reading and learning c++ for a little while now, thanks to Sam's c++ in 21 days. I was just wondering what is the minimal amount of information necessary for making a graphical game. Not some MMORPG, just something like pong or space invaders. I was also wondering what to use for the graphics, Sdl, opengl, or can I just do it in c++.
Thank you in advance.
Re: How much c++
Posted: Tue May 05, 2009 2:33 pm
by Falco Girgis
You need to have some sort of graphics API that allows you to do stuff with video (by talking to the graphics cards/hardware of the computer for you).
DirectX, OpenGL, Direct3D, Allegro, and SDL are all have graphics APIs that let you do this.
For a beginner, I would personally recommend using SDL. You probably don't need too much C++ to get started. At least make sure that you understand things like pointers and basic object oriented programming concepts.
Re: How much c++
Posted: Tue May 05, 2009 2:52 pm
by jtst1
Ok, Thanks man.
By the way I love your game, and the series. I've always loved computers, but your series helped me into programming. Can't wait to play Elysian shadows! Keep it up!
Re: How much c++
Posted: Tue May 05, 2009 4:10 pm
by programmerinprogress
Another important think you need to be able to do is to understand how to
Program
I know this may sound a little stupid, but think about it, it's all fine and well being able to memorise what a variable is, or what a pointer is, but you have to know how to apply these principles and how to use in them in your code.
e.g. you might find yourself writing your first SDL application, and you want it to print random colours to draw random-coloured boxes to the screen or something like that.
It would be of great benefit if you understand how to come up with the appropriate algorithms.
Going back to the coloured box example, you should be able to say to yourself "well I need to use a random number generator to generate 3 sets of integers to create the random colour, I might want to handle some input using this control structure etc", as long as you're able to apply what you have learnt, then you are ready ( well you're ready if you have what gyro said as well
)
There's only one thing I can think of to sum up my point and that is
Inquisitive mind thats what you need to program, if you've got that, you can pick the rest up along the way, being able to come up with things is useless if you don't
want to come up with them!
Good luck, and I hope to see what you come up with in the nenear future, i'll be watching
Re: How much c++
Posted: Tue May 05, 2009 4:38 pm
by jtst1
I understand what you mean, all the knowledge means nothing if you don't know how to put it to use.
As I said before i'm reading sam's book, and in here it talks about "prototypes" such as:
void myfunction();
int main()
{
some st00f blaaah
return 0;
}
void myfunction()
{
blaaaahh more stuff
}
Now why would I need to use the prototype there? I don't know if I'm being clear, but I don't understand the use, and the book isn't really explaining.
Re: How much c++
Posted: Tue May 05, 2009 4:50 pm
by herby490
jtst1 wrote:I understand what you mean, all the knowledge means nothing if you don't know how to put it to use.
As I said before i'm reading sam's book, and in here it talks about "prototypes" such as:
void myfunction();
int main()
{
some st00f blaaah
return 0;
}
void myfunction()
{
blaaaahh more stuff
}
Now why would I need to use the prototype there? I don't know if I'm being clear, but I don't understand the use, and the book isn't really explaining.
You need to have a prototype there because it is located after the main function. You could either put the whole function before main or you have to prototype it so the compiler can find it. Try not prototyping and you will get an compiler error.
Re: How much c++
Posted: Tue May 05, 2009 4:53 pm
by jtst1
Ah thank you. It makes sense.
Re: How much c++
Posted: Tue May 05, 2009 5:40 pm
by programmerinprogress
Prototyping is very important, because the compiler doesn't know that a function exists, unless you explcity mention that it does before the main() function.
Everything in C++ has a purpose, it's karma dude
Re: How much c++
Posted: Tue May 05, 2009 5:43 pm
by eatcomics
herby490 wrote:jtst1 wrote:I understand what you mean, all the knowledge means nothing if you don't know how to put it to use.
As I said before i'm reading sam's book, and in here it talks about "prototypes" such as:
void myfunction();
int main()
{
some st00f blaaah
return 0;
}
void myfunction()
{
blaaaahh more stuff
}
Now why would I need to use the prototype there? I don't know if I'm being clear, but I don't understand the use, and the book isn't really explaining.
You need to have a prototype there because it is located after the main function. You could either put the whole function before main or you have to prototype it so the compiler can find it. Try not prototyping and you will get an compiler error.
That through me off for a while when I first started, I was used to blitz basic, and you could put your functions anywhere and it would work, and I always put my functions after my main loop... I had a lot of errors in my first few programs....
Re: How much c++
Posted: Tue May 05, 2009 7:40 pm
by jtst1
Ah ok. Lol at ^^ post above.
Sorry for the long list of questions, but I've been trying to use the knowledge that i've aquired, and I've run into a snag.
Code: Select all
#include <iostream.h>
int firstDub (int);
long firstDub (long);
float firstDub (float);
double firstDub (double);
int main()
{
int firstNumber;
int doubledInt;
long doubledLong;
float doubledFloat;
double doubledDouble;
cout << "Please enter a number between 1-500: ";
cin >> firstNumber;
if (firstNumber > 500)
{
cout << "THATS TOO HAI!\n";
else;
doubledInt = firstDub(firstNumber);
doubledFloat = firstDub(firstNumber);
doubledLong = firstDub(firstNumber);
doubledDouble = firstDub(firstNumber);
cout << "The first number you entered: " << firstNumber << "\n";
cout << "The first number doubled: " << ??? << "\n";
}
}
int firstDub(int x)
{
return 2 * x;
}
long firstDub(long x)
{
return 2 * x;
}
float firstDub(float x)
{
return 2 * x;
}
double firstDub(double x)
{
return 2 * x;
}
I wanted to have a function that was a float,double,int,long, so that when the user entered in a number and it was doubled, even if it was a decimal and - it would still work. Now that I think about it there really is no point for a long or double... considereing the number is between 1-500. So onto the question, I had "firstNumber" entered where the ???? are, but it only output the original number, so I was wondering if I put the wrong thing there. I thought it would be that because the function would replace the old value with the new.
Re: How much c++
Posted: Tue May 05, 2009 7:52 pm
by MarauderIIC
You didn't change the value of firstNumber. You stored the doubled value of firstNumber into like, doubleInt and stuff. That's what you have to output.
Also:
"else;"
is the same as:
"else {}"
It does nothing. You can remove it, if that's what you meant to write.
Re: How much c++
Posted: Tue May 05, 2009 8:01 pm
by herby490
Ok I made a few changes to your code. First use <iostream> instead of <iostream.h> iostream.h is old. You do not need the float, int, or long because is you enter one of those to a double it will automatically convert it. Here is the new code
Code: Select all
#include <iostream>
#include <windows.h>
using namespace std;
int firstDub (int);
long firstDub (long);
float firstDub (float);
double firstDub (double);
int main()
{
int firstNumber;
//int doubledInt;
//long doubledLong;
//float doubledFloat;
double doubledDouble;
cout << "Please enter a number between 1-500: ";
cin >> firstNumber;
if (firstNumber > 500)
{
cout << "THATS TOO HAI!\n";
}
else
{
//doubledInt = firstDub(firstNumber);
//doubledFloat = firstDub(firstNumber);
//doubledLong = firstDub(firstNumber);
doubledDouble = firstDub(firstNumber);
cout << "The first number you entered: " << firstNumber << "\n";
cout << "The first number doubled: " << doubledDouble << "\n";
}
Sleep(2000);
return 0;
}
/*int firstDub(int x)
{
return 2 * x;
}
long firstDub(long x)
{
return 2 * x;
}
float firstDub(float x)
{
return 2 * x;
}*/
double firstDub(double x)
{
return 2 * x;
}
Sorry for the poor explanation.
Re: How much c++
Posted: Tue May 05, 2009 8:03 pm
by MarauderIIC
You forgot to add using namespace std
Re: How much c++
Posted: Tue May 05, 2009 8:05 pm
by herby490
MarauderIIC wrote:You forgot to add using namespace std
Yeah I added it in the code i guess i forgot to tell him to add it.
Re: How much c++
Posted: Tue May 05, 2009 8:08 pm
by jtst1
herby490 wrote:Ok I made a few changes to your code. First use <iostream> instead of <iostream.h> iostream.h is old. You do not need the float, int, or long because is you enter one of those to a double it will automatically convert it. Here is the new code
Code: Select all
#include <iostream>
#include <windows.h>
using namespace std;
int firstDub (int);
long firstDub (long);
float firstDub (float);
double firstDub (double);
int main()
{
int firstNumber;
//int doubledInt;
//long doubledLong;
//float doubledFloat;
double doubledDouble;
cout << "Please enter a number between 1-500: ";
cin >> firstNumber;
if (firstNumber > 500)
{
cout << "THATS TOO HAI!\n";
}
else
{
//doubledInt = firstDub(firstNumber);
//doubledFloat = firstDub(firstNumber);
//doubledLong = firstDub(firstNumber);
doubledDouble = firstDub(firstNumber);
cout << "The first number you entered: " << firstNumber << "\n";
cout << "The first number doubled: " << doubledDouble << "\n";
}
Sleep(2000);
return 0;
}
/*int firstDub(int x)
{
return 2 * x;
}
long firstDub(long x)
{
return 2 * x;
}
float firstDub(float x)
{
return 2 * x;
}*/
double firstDub(double x)
{
return 2 * x;
}
Sorry for the poor explanation.
A few questions. When i try to use <iostream> codeblocks gives me an error. Second is namespace std for cout and cin. Never mind I just had to delete the functions i didnt use. But the usingnamespace std, do you put that instead of the <.h>