Drawing into ofTexture

Hey everyone

I just started learning OF, coming from Flash and Processing and I’m very excited.

I’ve created an interface for a drawing program and now I want the user to be able to draw on an area of the screen. In Processing I would create a PGraphics object draw into this and then image(); the graphic object on screen every draw loop.

I’m a bit confused how to do it in OF. I know I need to have a pixels array, update pixel index on mousepress and loadDraw it into the ofTexture, but I really can’t make it happen.

Does anyone have any sample code or projects you can link to?

I’d like to draw a circle with 10px radius every draw loop when the mouse is pressed. I need to do it in a texture because I have the interface that needs to update the background continuously.



Funny, this is almost the same problem as this one ( http://forum.openframeworks.cc/t/offline-rendering-with-off/3253/0 ), so I’ll post the same answer:

I’m not sure, but maybe this will help you? ofxFBO http://forum.openframeworks.cc/t/ofxfbotexture/3143/0

cheers ph

FBO is definitely the way to go with this. You could use a texture but you’ll have to do a lot of manual pixel manipulation and it’ll most likely be pretty slow. FBOs are awesome, I had trouble getting my head around them when I first saw them but now I realize that they’re pretty simple and awesome. Basically an FBO is an alternative canvas that you can draw to using all of the OF/openGL commands and then just draw it to your main window anywhere anytime. I imagine if you’re doing a painting program you won’t want to erase the canvas every time unless someone hits clear, so you can set this up in ofxFBO as well.

The basic premise with an FBO is that you create an object, then when you want to draw into it you tell OF to switch from drawing in the main window to drawing in the FBO. You then do whatever drawing is necessary using normal OF stuff (ofCircle, ofRect, etc etc) and then tell the FBO you are finished. You can then draw this FBO anywhere on the screen like a texture. Its a bit more complicated than that as far as getting used to the syntax but not by much, its really pretty simple/easy/awesome and you’ll get the hang of it pretty quickly.

Use the link above and search the forum for FBO if you’re having any issues getting it going