PDA

View Full Version : Simple 2D Paint



brucemak
09-14-2017, 03:58 PM
I'm trying to generate a texture from a fragment shader to be used as a brush in a simple 2D paint program. I'm having a little trouble wrapping my head around creating a texture and applying it to a quad for later use. Has anyone tried anything similar? I'm using freeglut. If anyone can point me in the right direction that would be awesome.

Thanks!
Bruce

Silence
09-15-2017, 02:55 AM
I never did that. But if you need to generate a texture dynamically, I would draw it into an FBO with a 2D texture attached to it. If the brush needs not to be generated dynamically (ie if only color, intensity or size would change in the paint program), then I would simply use a program like Gimp to create the image of the brush.

Then I will use the texture generated from the FBO (or from the external tool) to draw it on screen. With the fragment shader, it will be easy to change the colors, or its intensity. From the main program, you'll be able to change the size.

To draw in a texture with FBO, you can follow a tutorial like this one (http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/) for example.