Using line to clear is already efficient I think (no benchmarks done).
Note that 0 to w-1/h-1 is sufficient.
Example using pixel data pointer added.
Code: Select all
#include "fbgfx.bi"
sub clear_graph_full(pImg as FB.IMAGE ptr, _color as ulong )
dim as integer w, h
imageinfo(pImg, w, h)
line pImg, (0, 0)-(w - 1, h - 1), _color, bf 'note -1
end sub
sub clear_graph_pixels(pImg as FB.IMAGE ptr, _color as ulong )
dim as integer w, h, bypp, pitch
dim as ulong ptr pPixdata 'for 32-bit color mode!
imageinfo(pImg, w, h, bypp, pitch, pPixdata)
for y as integer = 0 to h - 1
for x as integer = 0 to w - 1
pPixdata[x] = _color
next
pPixdata += (pitch \ 4) 'pitch in bytes, but ulong pointer, so \ 4
next
end sub
screenres 800, 600, 32
'create image (with default transparent color)
dim as FB.IMAGE ptr pImg = imagecreate(100, 100)
put(10,10), pImg, pset
sleep 500
clear_graph_full(pImg, &hffff00) 'yellow
put(10,10), pImg, pset
sleep 500
clear_graph_pixels(pImg, &h00ff00) 'green
put(10,10), pImg, pset
sleep 500
getkey()
You can also do:
Code: Select all
pPixdata[x + y * (pitch \ 4)] = _color
but that will probably be slower, unless the compiler optimizes it again.