7

If we want to make an application like MS Paint, should we use OpenGL for render graphics? I want to mention about performance if using traditional GDI vs. OpenGL. And if there are exist some better libs for this purpose, please see me one.

vietean
  • 2,975
  • 9
  • 40
  • 65

2 Answers2

9

GDI, X11, OpenGL... are rendering APIs, i.e. you usually don't use them for image manipulation (you can do this, but it requires some precautions).

In a drawing application like MS Paint, if it's pixel based, you'll normally manipulate some picture buffer with customary code, or a special image manipulation library, then send the full buffer to the rendering API.

If your data model consists of strokes and individual shapes, i.e. vector graphics, then OpenGL makes a quite good backend. However it may be worth looking into some other API for vector graphics, like OpenVG (which in its current implementations sits on top of OpenGL, but native implementations operating directly on the GPU may come).

In your usage scenario you'll not run into any performance problems on current computers, so don't choose your API from that criteria. OpenGL is definitely faster than GDI when it comes to texturing, alpha blending, etc. However depending on system and GPU pure GDI may outperform OpenGL for so simple things like drawing an arc or filling a complex self intersecting polygon with complex winding rules.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • "which in its current implementations sits on top of OpenGL, but native implementations operating directly on the GPU may come" -> what do you mean by that ? – Calvin1602 Mar 17 '11 at 17:33
  • @Calvin1602: So far the existing OpenCV implementations use OpenGL as backend. However GPU vendors may decide to implement optimized OpenCV drivers that directly access the GPUs without an intermediary OpenGL layer. Some aspects of vector graphics are difficult to express in terms of OpenGL, so a more direct approach should be aspired. – datenwolf Mar 17 '11 at 20:08
  • Aren't you mixing openCV, openVG, and maybe openCL in your answer ? I quite don't follow you. – Calvin1602 Mar 17 '11 at 20:13
  • Oh, I'm so sorry, if course I meant OpenVG. I'm just preparing lecture slides about OpenCV; freudian typo :P – I mean OpenVG. – datenwolf Mar 17 '11 at 21:07
  • & @Calvin1602: I could understand what you meant. – vietean Mar 19 '11 at 04:53
4

There is no good reason not to use OpenGL for this. Except maybe if you have years of experience with GDI but don't know a single thing about OpenGL.

On the other hand, OpenGL may very well be superior in many cases. Compositing layers or adjusting hue/saturation/brightness/contrast in a GLSL shader will be several orders of magnitude faster (in fact, pretty much "instantly") if there is a reasonably new card in the computer. Stroking a freedraw path with a "fuzzy" pen (i.e. blending a sprite with alpha transparency over and over again) will be orders of magnitude faster. On images with somewhat reasonable dimensions, most filter kernels should run close to realtime. Rescaling with bilinear filtering runs in hardware.

Such things won't matter on a 512x512 image, as pretty much everything is instantaneous at such resolutions, but on a typical 4096x3072 (or larger) image from your digital camera, it may be very noticeable, especially if you have 4-6 layers.

Damon
  • 67,688
  • 20
  • 135
  • 185