Dare I ask: c or c++ ?

I see that its possible to use C for openGL development rather than C++ but would I be shooting myself in the foot using it?

I’m learning C for OS development and want to work on openGL development too but I need to be able to get tuts and help and if 99% of people use c++ then I should go with that instead

Thanks

Craig

I say C++ …

my bad… got to get back to programming … Stayed away for too long I guess, starting to forget stuff

[This message has been edited by jubei_GL (edited 12-16-2002).]

Whoa wait…C has structures too. I think you mean classes. And yeah, use C++. It allows you to make things more organized into neat little modules. Also operator overloading and function overloading help. Templates are SUPER useful too. Plus who says you can’t design a program like a C Application instead of a C++ application WHILE using C++. You can still use a procedural design.

C++ is the way to go in my opinion!

  • Halcyon

Well, you are right C and C++ handle structs.

But in C you dont put functions in a struct,
whereas in C++ you can. I may be wrong, but last time I checked this was the case.

You may find the link below useful.
http://www.clarkson.edu/~jets/cs444/sp02/references/c++_to_c_guide.html

Originally posted by Halcyon:
[b]Whoa wait…C has structures too. I think you mean classes. And yeah, use C++. It allows you to make things more organized into neat little modules. Also operator overloading and function overloading help. Templates are SUPER useful too. Plus who says you can’t design a program like a C Application instead of a C++ application WHILE using C++. You can still use a procedural design.

C++ is the way to go in my opinion!

  • Halcyon[/b]

If you’re working with MSVS then there is no difference at all, create new workspace, add cpp file to it & write your code. If you’re writing only C code it’ll work just fine with no warnings, if you’ll add some C++ features nothing changes. Think of that - C++ is C update, so the syntax stays the same, you only need new compiler, that can compile new features (it’ll definately support old ones too).

BTW, somwhere in this forum I saw comparison that showed C is in the 1st place and C++ in 4th in speed benchmarks. Although, I doubt because it depends highly on compiler you’re using. Prove me wrong

[This message has been edited by M/\dm/
(edited 12-15-2002).]

Mancha, you are totally right. C++ lets you put procedures inside a structure, but then it turns into a class basically .

Anyways, i really thing that benchmark is in the way that the benchmark app was programmed for c and c++. I mean there are things that are slower in C++ but you can get around em. And i mean come on…In the day and age of 2+ gigahertz computers, i dont’ think you will notice a difference unless you are the equivallent to superman in the programming world.

Plus the advantages of program design in C++ beat the slowing down (if there is any). I mean I find it incredibly intuitive to create modules that handle a seperate task (texture loading module, opengl scene module, etc) than straight coding it in C. But that is my opinion.

Use C++. C++ has two things going for it, first has no technical merit;
a) employers want new C++ programmers, not C programmers. You’ll get interview questions using std::string instead of char * and std::vector instead of arrays and be expected to know them inside out. Whether C++ is better or not is not relevent. C++ is simply trendier.
b) I think C++ is better. There is one simple thing it does that C can’t; operator overloading. In C++ you can write a nice function called operator*(lhs, rhs) and then simply type C = A * B; to multiply vector A and B. This alone makes C++ better for programming 3D. It is just so much clearer to see that, as it would appear in real math, than the old C version of C = Mul( A, B );

Classes vs structs, and all the other C vs C++ arguemnts are up to your preferrence, but I think you’ll agree C++ is better simply for operator overloading. And if you want to be a professional programmer it is handy to know the language people want to hire you to use.

Yes, for 999999999…9999%

Well other than just operator overloading, there are templates. I mean if those aren’t helpful…what are??? With templates you have a class/procedure work on any data type. For example if you want to build a CStack class, then you need to make another structure or something so you can tell the procedures what data type to take. But with templates, you tell the CStack class what it’s taking, and you have a class that can work on anything. It’s REALLY useful.

And yes…operator overloading IS awesome!!!

Although there is lot of hidden stuff under it I mean mem allocation.

Yeah…but if you don’t like it, no one said you couldn’t use memalloc(…) inside a class . It’s not c++ compliant or anything i guess… but who cares. It makes ure program work. Mix C and C++ if you want. A lot of people i know still use fopen(…) fseek(…) etc. as apposed to the file I\O class in C++.

  • Halcyon

thanks guys - the fact you can mix the two makes it easier

I like the idea of procedure programming … been working with c# and classes for the last 3 years (since beta) and I’m tired of them hehe I want chaos! :wink:

Craig

memalloc is good, but I would use the new operator instead. Reason? memalloc is not thread safe and the new operator is.

Templates??? Hummm, they are simply great. However, they are a bit slow, so you dont want them all over your 3D engine.

std::vector… I mean the stds overall are great. But they suffer from speed as well, and they are too dependent on the compiler.
I had my 3ds reader using vector everywhere; it looked like my linear algreba book.
On VC++ 6 it worked just like a brand spanking new porsche. With VC++ 7 (.NET), it ran like a friging volkswagen from the second world war. So I ended up changing my entire code to pointers. Man that was a Max Pain.

C++, however, will allow you to use all of those nice features, such stds that C does not have.

well, i know only C so i write my program with it and i have no problem at all.

some time ago i have also found nehe tutorials writed C only style.

if u need it i can send it there are all the lessons tutorial in one zip file.

the tutoials are written in C only + SDL, so for example to menage the controls u can use sdl instead of glut.

It would be great if you could send me those C tuts. thanks.

You can email them to me at news@ip80.com

Craig

done !

Tre progs may be slow on VC7 because you are compiling them in .NET, you can turn that off & they’ll run like McLaren F1, at least that’s what I’ve heard About mem, I was talking about templates. In one C++ book I found that template actually creates all function posibilities at program start, so it’ll create int f(int), float f(float) and so on, even if you’re not using the first one. About malloc I use new despite the fact that malloc looks beter (understandable), & streams ar just great.

I would simply make my OGL in pascal. Forget C and C++.

Er ja maad, mbe jmp bak t dzumperzz, thatz cll

Hmmmm… For a program, I use C++. If I write a library or some other API, I use C. I have tried to use C++ libs that are given by other programmers, and usually it ends up being an ugly mess. Before you endeavor in C++, understand that C++ IS NOT A NEATO FORM OF C!!! It is a completely different way of thinking, and the programming should reflect that. One thing that pisses me off when I read a code written by somebody is this…

class SomeClass
{
int x, y;
SomeClass() { x = y = 0; };
Initialize(int xval, int yval)
{
x = xval;
y = yval;
};
}

The constructor should initialize the function! In this case, there should either be two constructors, one to initialize to zero and one to initialize to the values given. The constructor is there to keep programmers from using uninitialized classes. If we need the class initialized to specific values, then only the specific constructor should be used ( SomeClass(int xval, int yval) ) thus making a declaration such as:
SomeClass sc; // a compile time error

So, if you want to learn C++ from C, then I suggest you read the book “Thinking In C++” and avoid “C textbook adapted for C++” like the plague!

And also, there are those stinking STL classes. I hate them. They are written to handle every possible case, and not all that efficiently. I suggest you write your own template classes so that you know what is in your own code. Also, watch out for operator overloading. For example, in the previous example, we have vectors A, B and C.
C = A * B; // is this a cross product or dot product? We don’t really know, unless we create something else for dot products or cross products. So, lets overload the ‘.’ operator for a dot product.

C = A . B; // Now we are talking about confusing! What happens when we want the x coordinate of A? A.x… or is that the dot product of A and x? Does the variable x exist? Be careful if you want to overload operators, you may very quickly get in over your head. About 99% of the reason why I don’t like to use C++ libs is because operators are overloaded in ways that I cannot foresee. Maybe Im just paranoid, but keep all this insanity in mind.

just my two cents

[This message has been edited by 147-2 (edited 12-16-2002).]