Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ShawMishrak

OpenGL OpenGL and C vs C++

This topic is 5744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!