Requirements :
- I need to draw 2D lines, circles, boxes. Fast. That's it.
- I don't want to learn objC, Swift, Xcode.
- I'm using C++ and Jetbrains' CLion.
- OpenGL is deprecated (or soon to be) on Mac
- I don't even care about Apple (as you probably guessed), but the M1 processor is just too good. (and fanless <3)
- I'll be happy as long as it runs on my MacBook Air
- Text would be a useful feature but totally optional
- I won't even use sprites, or any kind of assets, sound, keyboard, mouse, IO, GUI. I need pure non-interactive visualisation of science-ish stuff.
- fast FPS, refreshing the visualization as fast as possible.
- Even if it's a pure framebuffer (an array of pixels), I'll manage.
- If it's a full fledged 3D accelerated graphic library (eg : openGL, Vulkan, Metal), it also works for me.
- "as long as it works"
What kind of options are available to me with the aforementioned requirements ?
- use openGL anyway and cry when it will no longer works ? (meh)
- hack my way to Metal in C++ ?
- I'm fine if a suggested library isn't Object Oriented (eg : openGL)
- Vulkan ?
- I still need to open a graphic window context somehow
- SDL2 appears to have a some kind of Metal backend/port/whatever but all the exemples I find are in ObjC.
- honestly, my post feel like I'm crying for a documented c++ metal wrapper of some kind I suppose ?
EDIT :
- I read mixed message and confusion on the Future of OpenGL on Mac. Mostly about "no longer supported" vs "Deprecated". Will OpenGL be removed and no longer works. Or it will works but won't be updated anymore ? (considering my requirements, an outdated version of OpenGL is perfectly fine to me)
Thank you <3
Hi ker2x!
Glad you are enjoying the Apple M1 processor!
To answer your questions:
-
To render 2D primitives, you can give Quartz a try. It has a C API, so it meets your requirement of not having to use Swift/Objective-C. You can use CGBitmapContextCreate to create a context for rendering to an offscreen buffer.
-
This leaves you with the problem of displaying this offscreen buffer on screen. This can be accomplished by using any 3rd party app framework.
-
Generally speaking to do high performance rendering using the GPU, your best option is to use Metal. Unfortunately as of today no C++ interface/wrapper for Metal exists. This means that if you want to take this route, there is no way of completely avoiding objective C. By using the objective C++ language (.mm files), you can effectively mix C++ with objective C code. This means you can limit the amount of objective C++ code to just the (metal) API calls, while the rest of you application can be written completely in C++. I hope that would take away some of the burden of having to completely learn a new programming language. An example of using Metal this way can be found here.
Good luck!