Redirect drawing ops to TPixmaps/TImages?

BlitzMax Forums/BlitzMax Programming/Redirect drawing ops to TPixmaps/TImages?

Russell(Posted 2010) [#1]
Is there a way to redirect drawing operations, such as DrawText(), DrawRect(), etc to draw to a pixmap or image instead of the backbuffer? I have had lots of instances lately where something like this would have come in very handy!

If not, I submit this as a future feature request! Right now, the only way I know to, for example, write text to a pixmap is to either a) draw it on the backbuffer and then grab it or b) decipher the TImageFont format and write the font pixels directly using WritePixel(). Usually, the first method is sufficient, but there are times when it's not. The second method would be much harder (for me anyway) and probably way slower than desirable. Besides, I don't think the TImageFont format is published anywhere?

Thanks,
Russell


Rozek(Posted 2010) [#2]
Brucey's Cairo module draws into a (dynamic) image or a pixmap


beanage(Posted 2010) [#3]
Well, if you dont want to import a big new module just for this, there's also OpenGL Framebuffer Objects. Here is some code:



Would be nice to have this standard in Max2d tho indeed.


ImaginaryHuman(Posted 2010) [#4]
You could also draw to the backbuffer and grab it into a texture/image/pixmap.


DavidDC(Posted 2010) [#5]
BeAnAge: Don't suppose you could whip up a simple demo of TFBO in action?

I just tried it and crash on

glGenFramebuffersEXT 1, Varptr id

in New()

but maybe I'm doing something daft in my setup. (tested on macmini SnowLeopard).

[edit] Sorry, all good now - found this


Russell(Posted 2010) [#6]
@ImaginaryHuman: That's what I do, but sometimes this is not desirable. Like when you don't want to have to worry about when the flip is executed (Is the stuff I drew going to be seen, if only for a frame). Drawing directly to an image or pixmap would mean there is no possible way for the backbuffer to be corrupted with graphics data.

For now, I am just careful where my Flip() is.

@BeAnAge: Thanks for the code! And it should be cross-platform, too! Nice.

Russell