PDA

View Full Version : Learning OpenGL with C (API) or C++(libraries)?



schultz
04-25-2005, 10:52 PM
I would like to ask you to share your experience about using core OpenGL API with C/C++ (and making own wrapper classes) vs using available C++ OpenGL libraries.

What are pros and cons of using C/C++ (please without performance wars). I am newbie in OpenGL area, and have some experience in C and much more in C++.

There is much more resources about C (GL) then C++(GL) available online... So can someone recommend me C++ library worth of learning if this is way to go.

Thank you,

T101
04-25-2005, 11:23 PM
I'd have to say: when you start wrapping, go for C++.

Once you go beyond simple experiments, you're better off with C++ because you can make your code a lot cleaner. (vector classes, different behaviour for different types of objects etc).

And you can still use the C functions from C++ anyway, so you might as well start with C functions in C++, and "grow" the code into classes.

RigidBody
04-25-2005, 11:26 PM
why i like c++ ...

1. the syntax is very free. in c++ you can define variables almost anywhere you want:


int main(argc, char *argv[]) {

for(int i = 0; i < 100; i++)
printf("\t%3i\n", i);

float x = M_PI, y;

y = sin(x);

}2. classes. you can define a vertex class, for example, with many different constructors, which allow you to simplify declaration of local objects in your code like


Vertex v1(1., 0., 0.), v2(0., 1., 0.); // define vertices with coordinates
Vertex v3(v1, v2, false); // v3 = diff vector from v1 to v2
Vertex v4(v1, v2, true); // v4 = normalized diff vector from v1 to v2
Vertex v5(v1, v2, 5.0); // v5 = diff vector from v1 to v2, length = 5. unitshope that gives you a small impression of c++.

schultz
04-25-2005, 11:56 PM
Thank you for your response.

So basically it means, learn C GL api, and use C++ to make code cleaner, easy to read and OO. :)

There are no C++ libraries which are on same maturity/functionality level as C api?

Greetings,

RigidBody
04-26-2005, 12:05 AM
what exactly do you mean with C api?

if you program in c++, you still use C libs and include files like stdio.h, stdlib.h, string.h, math.h ... PLUS additional c++ libs.

schultz
04-26-2005, 12:36 AM
Originally posted by RigidBody:
what exactly do you mean with C api?

if you program in c++, you still use C libs and include files like stdio.h, stdlib.h, string.h, math.h ... PLUS additional c++ libs.Probably my bad english.

OpenGL api is C api. Correct?

I can use it:
-as it is, pure C
-as it is, (plus own made classes C++)
-as(in) some higher level OpenGL C++ library ???

You already answered my first question, in your first reply. Second one was about existing C++ libs for ogl programming.

I hope you get the point.

Thank you.