Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C or C++ for OpenGL graphics

there is any drawback in choose C++ and an object oriented model (classes) to implement a simulation in OpenGL (or DirectX)? It's preferred to use C and a procedural programming paradigm ?

like image 855
Lucas Avatar asked Feb 10 '10 23:02

Lucas


2 Answers

The most common drawback of object oriented programming in the context of high performance graphics (games etc.) is the memory bottleneck. OOP often (but not necessarily) leads to writing functions that operate on single elements and leveraging the standard library to generalize these to arrays. It might be preferable to operate on arrays in the first place, for example cull against all six frustum planes instead of calling the single plane culling routine six times.

Check out the following resources for more details:

  • Pitfalls of OOP
  • The Latency Elephant
  • Data-Oriented Design (Or Why You Might Be Shooting Yourself in The Foot With OOP)
  • Memory Optimization
  • C++ Programming is Bullshit

Note that using C++ does not imply strict object oriented programming, you can use it for many paradigms. So if you code your engine in C++, you can still leverage all existing OOP style libraries such as Qt, while using any paradigm you like for the core. Although all of this is also possible in C, C++ might be a bit more comfortable.

like image 132
Malte Clasen Avatar answered Oct 12 '22 22:10

Malte Clasen


Not really, unless you have an unreasonably stupid design or are on a seriously limited platform there is no performance advantage of c over c++.

like image 34
Martin Beckett Avatar answered Oct 12 '22 23:10

Martin Beckett