PDA

View Full Version : new to programming



k3v0
05-08-2003, 08:45 AM
hi, im pretty new to any programming besides web programming. I know very little c++ im about 4 chapters into my book and i was wondering if i would be able to learn opengl without really knowing any c++?

c_olin
05-08-2003, 09:21 AM
no, read the whole c++ book and make a few simple c++ consol programs, then go to nehe.gamedev.net and start at the first tutorial.

Obli
05-09-2003, 09:25 AM
I don't really agree on this.
It is something really subjective. Maybe someone will feel better by learning while "on the road".

To tell the truth, a lot can be done with using basic C/C++, basic GL and a bunch of time to spend.

Of curse, having C skill helps, but usually not so much.

My personal opinion is that you need just a basic C knowledge to start using GL.

One you got data types, ifs, pointers (a bit, some people finds 'em difficult), cicles, something about I/O and you __practiced__ it a bit you may start GL and learn while using it, if you are good at thinking... else read teh book, prac, prac, prac, read the tuts.

PS: Always leave your book at hand however...

EDIT: forgot you have to know a bit of dynamic memory allocation and arrays.

[This message has been edited by Obli (edited 05-09-2003).]

05-09-2003, 09:45 AM
I too, am new to coding, and have grasped the first few chapters of my C++ book (I can code a math quiz) and wish to know when I should try and learn openGL or directX.

starman
05-09-2003, 09:58 AM
No, do NOT learn all of C++ before starting OpenGL. I've been writing production C++ code for five years and there are parts of that gigantic language I haven't used yet.

Learn the basics - classes, virtual functions, constructors, destructors. Pick up the /C++ FAQs/ book if you can...just about any question you might have about the language is in there.

Good advice on the NeHe tutorials, though.

starman
05-09-2003, 10:00 AM
Oh yeah...learn the C++ standard library, at the very least the std::string and std::vector classes. You will find that you can use these to replace char * strings and dynamically allocated/reallocated arrays. I'd still stick with arrays for things that have static bounds, though (like vectors, matrices, etc.).

A good book for learning C++ is /Accelerated C++/ by Koenig and Moo.

Tea
05-11-2003, 12:27 AM
im also C++ noob, and i realy dont know how to use pointers. But i feel good without them. Im creating opengl fps game, with some model imports, console and other ****.

starman
05-12-2003, 07:40 AM
Pointers can be used a lot less frequently in C++ than they were in C. If you want to pass something to a function by reference, use a const reference instead of a pointer:

void draw(const GameObject & obj);

If you want to store text strings, use the std::string class instead of allocating (and worrying about) character pointers:

#include <string>

std::string WindowTitle = "My OpenGL Program";

If you are calling functions that use take character pointers, just call the c_str() member function:

someFunc(WindowTitle.c_str());

If your class has to use pointers, make sure you allocate your pointer in the constructor and delete it in the destructor so you avoid memory leaks:

MyClass::MyClass()
{
gameObject_ = new GameObject();
}

MyClass::~MyClass()
{
delete gameObject_;
}

Finally, you can use the Boost library's smart pointers if you don't want to worry about managing the memory yourself. Download them at boost.org.

#include <boost/shared_ptr.hpp>

boost::shared_ptr<GameObject> gameObjectPtr(new GameObject());

Now you can pass gameObjectPtr around like you would a raw pointer to a Game Object, but you don't have to worry about who owns the pointer and who is responsible for deleting it - shared_ptr does the work for you.

Red15
05-12-2003, 09:21 AM
Yeah, a question about that std::string
class, why can't it convert itself?

I would reckon that using global operator
overloading it would be possible to do
something like :

std::string number = "20.34";

float value = atof(number);

Or is there another way to convert strings to numbers and am I just being inefficient?

-Red15-

starman
05-12-2003, 10:17 AM
'std::string number = "20.34";

float value = atof(number);
'

Actually, you would call "atof(number.c_str());" since atof() takes a char *, not a string.