OpenGL and C vs C++

Started by
15 comments, last by ShawMishrak 21 years, 6 months ago
I remember reading a thread a month back or so on this subject, but I cannot find it as the search function is not available. I have been using OpenGL inside C++ classes for a couple years now, but a question has been bothering me recently: Should I use C++ or C to write the graphics engine? I originally thought C++ classes were the way to go to keep everything together and pretty. However, I read an article about Doom3, and in it was an interview with Carmack in which he stated that the game was written in C++, with the exception of the graphics engine, which was written in C. This made me think; is C faster or better than C++ when it comes to OpenGL? If so, which parts should be written in C and which in C++? Should the whole graphics engine be written in C, or just the functions that interface directly with OpenGL? I''m just looking for any advice, since this question has been bothering me lately and I haven''t been able to find anything online beside that thread which I now cannot find.
Advertisement
If John Carmark jumped off a building, would do that, too?

If C++ works for you, stick with C++ - let John C. do it however the hell he wants.

If I had my way, I''d have all of you shot!

codeka.com - Just click it.
Don''t use a coding style because others do it, use it because it allows you to work to your best potential for you and others. I have my oppinion but sinse it doesn''t matter, I''m not going to tell you.

---
My Site-My Tetris Clone w/Source
Come join us on IRC in #directxdev @ irc.afternet.org
I didn''t say I follow everything Carmack does, I''m just wondering if there was any specific reason or advantage to that style. Calm down.
C is slightly faster than C++ because it doesn''t have virtual functions (with virtual functions, the program has to figure out which methods to call at run-time rather than compile-time). That''s probably why he used it. However, most compilers do enough optimization that the difference is negligible. It''s perfectly possible to create a great graphics engine in C++. Doom 3 isn''t the only game in the world with great graphics, you know.
Yeah, I just figured there might be a reason.

Thanks for the replies. I can sleep a little easier now. =)
quote:Original post by DC_Tsunami
C is slightly faster than C++ because it doesn''t have virtual functions...
You only get the overhead of virtual functions if you declare them as virtual!

And getting the same effect in C requires the exact same overhead.

Possibly C just suits the style of engine iD/JC want to write.

Also .. Quake and Q2 were definitely written in C .. possibly Q3 (dunno, haven''t seen the code) .. in which case they may just be building on the (known good) technology they already have.

tbh, what everyone else says above: use what works for you
(I have read that Quake3 was written in C)
as I side note, from what I read about Doom3 the only hold overs from Q3 to start with was stuff like loading code, audio code etc, the graphics engine was apprently gutted and started again from the beginning.

As for C vs C++ in the case of Doom3, its probably a case of JC just likes/knows how to use C more than C++ to get better results, so if you prefer to go with C++ over C then do so, basical at the end of the day its whatever works for you

This topic is closed to new replies.

Advertisement