Drawing program

BlitzPlus Forums/BlitzPlus Programming/Drawing program

Chaduke(Posted 2006) [#1]
I've been curious about drawing programs like Photoshop and how they're used to apply changes to an onscreen bitmap. I've been doing a few experiments using drawing directly to the front buffer as well as trying it with page flipping.
It appears that by using page flipping updates don't happen often enough to get a smooth drawing feel.
I was wondering if anyone here has tried to create a drawing program and discovered a technique that works well.
With writing everything to the front buffer I get great speed, but when drawing the brush you have to constantly capture and redraw areas of the onscreen bitmap where the brush last was. This just seems a little awkward to me and I was wondering if there is an easier technique that I'm just not seeing.
Using page flipping its pretty easy, when I'm ready to draw I just set an image buffer and draw on that, then set the buffer back to the back buffer and draw the image, then draw the brush shape and flip. It just doesn't update fast enough and seems very redundant.
If you need me to explain better or provide code examples let me know.


Rck(Posted 2006) [#2]
Drawing on to an imagebuffer can be slow in BlitzPlus. Try getting more advanced (but hopefully faster) by locking the imagebuffer and using the PixelFast commands (ReadPixelFast, WritePixelFast). You will have to consider being more careful not to write out of bounds on the image, etc. Also, you will need a pixel creation function if you want to draw an arbitrary color to certain pixels. Also having a custom color extract function for each Red, Green, and Blue will be helpful. Each of these four functions don't need to be more than one line of code.

As for drawing, I have always found best performance with double-buffering. Drawing to the back buffer then flipping can reduce artifacts and tearing. Probably, the actual image manipulation is what is slowing down your program instead of a buffer choice.


Chaduke(Posted 2006) [#3]
I'm actually using Blitz3D but not using a 3D graphics mode or related functions so I posted here instead.
I wouldn't think it handled 2D differently than BlitzPlus but you never know.
Check out a test program I wrote called "Sand Painter". The painting effects I'm doing seemed impossible with page flipping so it's all done by writing to the front buffer directly.

Here's the link:
http://www.doresoftware.com/misc/sandpainter.zip

There are several source files in the folder, but just open and run sandpainter.bb
I think I did a decent job of commenting the code.

Once you run it you can quickly get a feel for the different effects by tapping the space bar to select a random brush and then trying it out.