Should we use OpenGL for 2D graphics?

If we want to make an application, for example, MS Paint, should OpenGL be used to render graphics? I want to mention performance if using traditional GDI and OpenGL. And if there are some better libraries for this purpose, please look at me.

+7
source share
2 answers

GDI, X11, OpenGL ... are rendering APIs, i.e. you usually do not use them to manipulate images (you can do this, but this requires some precautions).

In a drawing application such as MS Paint, if it is pixel-based, you will usually manipulate some image buffer using regular code or a special image manipulation library, and then send the full buffer to the rendering API.

If your data model consists of strokes and individual figures, that is, vector graphics, then OpenGL does a good backend. However, it might be worth taking a look at some other vector graphics API such as OpenVG (which in its current implementations is on top of OpenGL, but a built-in implementation that works directly on the GPU may appear).

In your use case, you will not encounter any performance issues on current computers, so do not select your API from these criteria. OpenGL is definitely faster than GDI when it comes to texturing, alpha blending, etc. However, depending on the system and GPU, pure GDI may be superior to OpenGL for such simple things as drawing an arc or filling in a complex, self-intersecting polygon with complex winding rules.

+8
source

There is no reason not to use OpenGL for this. Also, maybe if you have many years of experience with GDI, but I don't know anything about OpenGL.

OpenGL, on the other hand, can be excellent in many cases. Composition of layers or adjusting hue / saturation / brightness / contrast in the GLSL shader will be several orders of magnitude faster (in fact, to a large extent "instantly") if the computer has a fairly new map. The gradual passage of the path of liberation using the "fuzzy" handle (ie, Mixing the sprite with alpha transparency again and again) will be an order of magnitude faster. On images with somewhat reasonable sizes, most filter cores should work near real-time. Scaling with bilinear filtering is done in hardware.

Such things will not matter on a 512x512 image, since almost everything is instantaneous at such resolutions, but on a typical 4096x3072 image (or larger) from your digital camera this can be very noticeable, especially if you have 4-6 layers.

+4
source

All Articles