Why isn't openGL object-orientied? Everybody teaches Object Orientated Programming + Design Patterns, but OpenGL has many global functions. Isn't this bad style?
The whole point of a low-level API is to make it as minimal and portable as possible. Giving it an object-oriented architecture would not allow this:
Finally, you should really question what you've been taught about OOP. Despite what your college or university may tell you, OOP is not a panacea of program design. There are very good reasons why there is absolutely no object-orientation in the C++ STL (and most of Boost for that matter).
Object-orientation is useful in some cases, but you should learn when it is useful, and when it is not, and under no circumstances should you believe that anything that is not OOP is "bad style".
OpenGL
In general -- OpenGL is designed to allow us to have all the freedom, and don't make any choices for us. And by freedom I mean freedom to choose a platform, a language, a programming paradigm, a engine design, a methodology, and a level of efficiency vs. readability.
And for that I praise OpenGL, and for that I hate Direct X.
Amen.
Sidenote: Everybody teaches Object Orientated programming because it's the easiest to grasp. It's not the one and only true paradigm. There's functional programming, logical programming, contract programming, and even a object oriented way to write in C. There's no one truth in computer science. As for Design Patterns, I could name more than a few that are used in OpenGL's architecture. Bad Style? I've seen beautiful C programs that had aaaaallll global functions...
In general, OpenGL is object oriented. It is just implemented in a language that doesn't directly support OOP. But the API is object-oriented: It consists of a number of different object types, and a set of operations defined on each. And the internals of each object type are hidden from the user. It fulfills all the requirements for OOP. It just so happens to be implemented in C, which doesn't have a convenient class or member method syntax.
Apart from this, there is absolutely nothing wrong with global functions. In C++, a common recommendation is to prefer them over member methods whenever possible. In functional programmming, global functions are the default.
OpenGL was created for and in C, and none of that stuff existed then. Even now, they still want to keep a C interface, because C is still a widely used language.
Should they maintain both C interfaces and C++ wrappers, ditch C and just use C++, or keep a C interface? I'd argue the latter is the best solution: easy on them, not too hard for us.
That said, the OpenGL interface is admittedly gross. Lot's of stuff was "suppose" to be deprecated, but alas that got moved to a later date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With