5 ms·
> This is because OpenGL is at its essence a 2D API. The vertex shader accepts something as input and it produces 2D vertices in device coordinates (-1 to 1) as
by w1nt3rmu4e 8y ago
> This is because OpenGL is at its essence a 2D API. The vertex shader accepts something as input and it produces 2D vertices in device coordinates (-1 to 1) as output.
And the same can be said for every other GPU API. That's what rasterization is. You take a bunch of input and put out a 2D texture. It's necessarily 2D because screens are 2D.
Luckily, first class support for matrices, 4D vectors, mipmaps, lighting (well, at least insofar as lighting is math), etc make it well suited for creating the illusion of 3D.
I get paid to work with OpenGL -- and, somewhat uniquely, 2D OpenGL. I'm confident in saying that while OpenGL might suffice for a 2D game engine and yes, might allow you to skip over a little bit of the math, it is terrible as a 2D UI engine.
GPU APIs are first and foremost for rendering 3D scenes. You can certainly use them for 2D but how well suited they are to that is dramatically dependent on what the use case is.
- earenndil 8y agoDo you think other gpu apis (vulkan, metal, direct3d) are better suited for 2d?
- pjmlp 8y agoDirect3D alone not, but DirectX as a whole yes. Same applies to Metal. OpenGL suffers from "go fish libraries" mentality, where we only get a way to put pixels on the GPU and nothing else. While Metal, DirectX, LibCGNM, NVN, GX, GX2 provide a complete framework around their APIs. You get a way to do math, shader loading, dealing with fonts, textures, materials, scene descriptions, mesh loading, shader management. If I had a penny for every OpenGL tutorial that teaches how to manually load, compile and link shaders, or which libraries I am supposed to hunt down, I would be enjoying some nice vacations.
- pjmlp 8y agoSadly OpenGL as 2D UI is Google's answer for anyone that wants to do 2D rendering from the NDK. Which means everyone ends up writing their own little library on top of OpenGL, or increasing their APK size bringing in SDL, Cocos2D, .... Or if 2D rendering performance isn't a constraint, calling via JNI the Canvas API, which happens to use Skia for its native methods, but isn't exposed as NDK API.