7 ms·
Not exact related, but is there a modern, widely used object oriented c++ wrapper for OpenGL? Why does OpenGL persist with a C style API instead of a more expre
by billfruit 5y ago
Not exact related, but is there a modern, widely used object oriented c++ wrapper for OpenGL? Why does OpenGL persist with a C style API instead of a more expressive one?
- Jasper_ 5y agoThere's no wrapper because a modern high level rendering engine doesn't expose raw graphics APIs to the user, and instead keeps it behind higher level structures like draw calls and render graphs. At that layer, you don't need the C++ API, in fact you want something to efficiently let you manage the OpenGL context state as directly as possible. And a C API is fine for that. Basically, the amount of code interfacing with OpenGL should be fairly minimal.
- Jare 5y agoC can interop with anything. There are higher level graphics libraries on top of OpenGL, Vulkan, Metal, WebGL & DirectX, for example bgfx or sokol, but IIRC they still go C style for the same reason. Then there are language-specific libraries that will be idiomatic, like wgpu for Rust. Finally, you reach entire very opinionated game engines at various levels (Unity, UE, Godot, etc).
- pjmlp 5y agoMetal and DirectX are based on C++, thankfully.
- my123 5y agoThe exposed API for Metal is Obj-C, and the one for DirectX is using COM. (for shaders, MSL is a C++ dialect, but HLSL isn't)
- pjmlp 5y agoThanks for being pedantic, none of them is C.
- vvanders 5y agoPedantically, none of them are C++ either.
- pjmlp 5y agoIn which language are DirectX examples and SDK written on?
- joe91 5y agoWhile not being based on C DirectX actually has a C API, even for D3D12. For example to call device->CreateRootSignature(...) from C you call ID3D12Device_CreateRootSignature(device, ...).
- pjmlp 5y agoBecause COM can be called from C, yet no sane people do it, unless they are trying to make a point no matter what.
- codeflo 5y agoThere’s no shame in simply admitting one was mistaken.
- pjmlp 5y agoI am not mistaken. DirectX is a COM API, and although some masochits can make use of it from C, 99% of the world does not, including the official SDK. Metal is a mix of Objective-C and C++, with Swift bindings thanks Objective-C interop. None of them are C based like Khronos darlings.
- tedajax 5y agoI promise you the Vulkan C API is significantly cleaner.
- pjmlp 5y agoBefore or after dealing with the dynamic loading of all required extensions, validation layers, memory allocator (which AMD had to create a more user friendly wrapper) and initialization boilerplater?
- Const-me 5y agoIf you have relatively new GL, this one is good: https://diligentgraphics.com/diligent-engine/ https://diligentgraphics.com/diligent-engine/
- nih0 5y agotheres magnum.graphics but going with an opengl loader is always better imo
- Game_Ender 5y agohttps://magnum.graphics https://magnum.graphics Supports WASM and WebGL too!
- forrestthewoods 5y ago> instead of a more expressive one? I would not consider a C++ API particularly more expressive than a C API. RAII handles are nice. But that’s about all the expressiveness you get from C++ at the API level. Languages that provide expressiveness generally do so at the implementation level, in my experience.
- bloodycxx 5y agoLet's just say C++ code is sexy to eye compared to C. It's like Javascript :)
- dkersten 5y ago> RAII handles are nice. If that's all you want, its not hard to write your own RAII wrapper for things anyway.
- forrestthewoods 5y agoAgreed 100%. I quite like C APIs. They’re simple, elegant, and can wrapped with RAII or your preferred style. A C++ API imposes its style on you. Usually badly. Never mind the ABI issues. Most interfaces could be improved by re-writing them in C. I can’t say the same for the inverse. That said, OpenGL is a terrible API that is nearly impossible to use correctly. But neither C nor C++ have much impact on its horrifically stateful architecture.
- SubjectToChange 5y agoC++ APIs are made far better by templates (and soon concepts), smart pointers, objects, better type checking, etc, not just RAII. C-style APIs really can't compete, IMO. > Never mind ABI issues. A C ABI is far more brittle than a C++ one.
- neutronicus 5y agoLet's play "who's supposed to call 'free' on this pointer"!!!
- deleted 5y ago[deleted]
- spacechild1 5y agoThere's https://openframeworks.cc/ https://openframeworks.cc/. It's basically the C++ equivalent to https://processing.org/ https://processing.org/. Unfortunately, it's not really a library but rather a complete app framework, but it shows how a C++ wrapper API could look like. It definitely makes OpenGL programming easier and more fun.
- Procedural 5y ago> Unfortunately, it's not really a library I made it a library with a single header: https://github.com/redgpu/framework https://github.com/redgpu/framework
- spacechild1 5y agoInteresting. Where is the source code?
- wffurr 5y agohttps://github.com/google/ion https://github.com/google/ion as used by Google Earth.
- EamonnMR 5y agoYou may enjoy the OGRE. https://www.ogre3d.org/ https://www.ogre3d.org/
- mikepurvis 5y agoOgre is the renderer for a number of robotics projects, like rviz (robot visualization) and Gazebo (robot simulation). I don't know that either of those necessarily showcase it in the best possible light, but more just to say that it has a rich history serving in a variety of cross-platform use cases.
- integricho 5y agopure opengl wrapper: https://github.com/cginternals/globjects https://github.com/cginternals/globjects
- pjmlp 5y agoBecause Khronos just cannot move their mindset away from C. It took NVidia beating them to the ground for OpenCL to ever consider anything other than C and create SPIR. Then the existing C++ bindings for Vulkan were originally created by NVidia (again). Now ANARI is yet again a C API, they just cannot move beyond C.
- kolbusa 5y agoC++ is a mess from the backwards compatibility and portability point of view. Just try shipping a binary C++ library on Linux.
- bloodycxx 5y agoWat? Wat? C++ always has been much easy to use in Linux compared to Windows. Modern C also lack portability due to UBOs and compiler optimizations, but still good enough so is C++.
- pjmlp 5y agoAs if C was imune from such ABI mess called glibc.
- agent327 5y agoFunnily enough, the things that everyone complains about are all inherited from C...
- junon 5y agohttps://github.com/bkaradzic/bgfx https://github.com/bkaradzic/bgfx
- frozenport 5y agoI use Qt's built in bindings for the engineering CAD style programs I wrote
- fsloth 5y agoAll platform APIs are in C and not C++. The main reason IMO is the lack of standardization of C++ ABI. This is not such an obvious problem if you always only use single compiler, but the main difference between C and C++ after all the language sugar has been removed is that C++ binaries on a single platform, compiled on two different compilers beyond their C like aspects are only accidentally compatible. On some platforms you can make even single compiler builds in C++ incompatible if you use stl - e.g. a stl::vector may be quite different in debug and release build which leads naturally to faulty memory acceess.