0
$\begingroup$

Digital painting and raster graphics software like Krita and Photoshop have a canvas where you can paint with brushes. From a programming perspective, how is this canvas rendered? Can it be included on a graphics pipeline like OpenGL?

One proposed solution is to represent the canvas as a texture. If you know more possible solutions let me know. Thanks.

$\endgroup$
1
  • 1
    $\begingroup$ It is a 2D array containing the color values: an image. You can present it on screen through various methods, a special case being drawing it as an OpenGL texture. $\endgroup$
    – lightxbulb
    Jun 9, 2020 at 5:41

1 Answer 1

0
$\begingroup$

Digital painting and raster graphics software like Krita and Photoshop have a canvas where you can paint with brushes. From a programming perspective, how is this canvas rendered?

I don't have access to the code of the programs you mentioned, so I can't tell how exactly they did this since there are usually multiple ways to solve a programming problem. However, I guess everybody with some graphics programming experience will immediately think of the solution @lightxbulb already mentioned in his comment because it is the simplest one.

Textures are just an array of color values and a graphics API like OpenGL expects you to upload them as such. So a possible solution would be to represent your modifiable canvas in memory in this form too. Every time a modification is made, you find the affected pixels in your array, adjust their color values, and upload the updated canvas as texture (or update the already existing one). Then you just draw a fullscreen (or any other size you like) quad and attach the texture to it. Simple as that.

Can it be included on a graphics pipeline like OpenGL?

As you might already guess: Yes, you can do that. If you use the texture approach, you can do anything you can do with an ordinary texture in the graphics pipeline. If your intention is to include a canvas in a 3d game, then keep in mind that finding the pixel that should be modified gets a little bit more complicated due to the perspective projection. However, the rendering process stays the same.

$\endgroup$
2
  • $\begingroup$ I have little experience in graphics programming but seems a little hacky. It also seems easy so i guess its worth a try. I wonder what performance will it have. One critical component must be only updating the changed pixels instead of the whole canvas for each frame. $\endgroup$
    – Burst
    Jun 9, 2020 at 12:34
  • $\begingroup$ The main performance problem in OpenGL is the texture update on the GPU side. But there exist some fast routes (search for "OpenGL buffer streaming" or "OpenGL Approaching zero driver overhead"). However, if you are just doing a regular paint program, this is not worth optimizing since you have "plenty" of time. Also, I wouldn't call it hacky since it is a perfectly valid usage of the render pipeline. - Updating single pixels is also not that much of a problem because there are special OpenGL functions for that. $\endgroup$
    – wychmaster
    Jun 9, 2020 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.