Firstly you need to clear your render targets otherwise they might be filled with random memory data. Secondly render targets must currently be a power of 2 in size. They don't have to match the screen size as they can be scaled to any size when used on a sprite.
However, on mobile GPUs render targets should be cleared after a significant amount of drawing as they work differently to desktop GPUs. Mobile GPUs queue up draw calls until their buffers are flushed by a clear command, so every time you draw a new sprite it adds it to an ever increasing list of polygons that it draws every time the image is updated. It doesn't keep reading the frame buffer and writing it back for every sprite like a desktop GPU would. I've never tested the limits of this but to be safe you should use a method of double buffering your image rendering to help the GPU run smoothly. Try the following code
Global w,h,rw,rh,screenTop as integer
w = 800
h = 1280
Global sw#, sh# as float
sw# = w/rw
sh# = h/rh
screenTop=0 // Change this to position drawing screen height
SetWindowTitle( "Paint" )
SetScreenResolution( w, h)
SetSyncRate( 60, 0 )
SetVirtualResolution( w, h )
SetScissor( 0, 0, 0, 0 )
SetClearColor(0,0,0)
SetPrintSize(20)
// create two render targets and swap between them
global buffer as integer[1]
buffer[0] = CreateRenderImage( 512, 1024, 0, 0 ) // currently render targets must be a power of 2
buffer[1] = CreateRenderImage( 512, 1024, 0, 0 ) // luckily they don't have to match the current screen size to work
global currBuffer as integer = 0
// clear them both
SetRenderToImage( buffer[currBuffer], 0 )
ClearScreen()
SetRenderToImage( buffer[1-currBuffer], 0 )
ClearScreen()
SetRenderToScreen()
// create the screen sprite, this will be used to display the final image and draw the
// background of the next render image
global screen as integer
screen = CreateSprite(buffer[currBuffer])
SetSpriteDepth(screen,1000)
SetSpriteTransparency(screen,0)
// these positions only matter if you have black borders, the render image will also have
// them so the sprite displaying it must be in the true top left corner of the screen
// if you can guarantee no black borders then you can use 0,0 and w,h
SetSpritePosition(screen,GetScreenBoundsLeft(),GetScreenBoundsTop())
SetSpriteSize(screen, GetScreenBoundsRight()-GetScreenBoundsLeft(),GetScreenBoundsBottom()-GetScreenBoundsTop())
iBrush = LoadImage( "/media/brush2.png" )
Global Brush as integer
Brush = CreateSprite(iBrush)
SetSpriteSize(brush,128,128)
SetSpriteOffset(brush, GetSpriteWidth(brush)/2,GetSpriteHeight(brush)/2)
SetSpriteColorAlpha(brush, 60)
SetSpritePosition(brush,-200,0)
SetSpriteVisible(Brush,0)
Do
Print("FPS:"+str(ScreenFPS(),0))
if getpointerpressed()
SetSpriteColor(brush, Random(0,255), Random(0,255), Random(0,255), 255)
endif
if GetPointerState()=1
x = GetPointerX()
y = GetPointerY()
Paint(x,y)
endif
sync()
Loop
function Paint(x,y)
// Draw the current screen with the old render image onto the new render image
// Draw the new brush onto the new render image
// Set the new render image as the screen image and swap the buffers ready to do it again
// make sure the background image is in the right place just in case
SetSpriteImage( screen, buffer[1-currBuffer] )
SetSpritePosition(screen,GetScreenBoundsLeft(),GetScreenBoundsTop())
SetSpriteSize(screen, GetScreenBoundsRight()-GetScreenBoundsLeft(),GetScreenBoundsBottom()-GetScreenBoundsTop())
// clear the image and draw the background (the current scene)
SetRenderToImage( buffer[currBuffer], 0 )
ClearScreen()
DrawSprite(screen)
// draw the new brush
SetSpritePositionByOffset(Brush,x,y)
SetSpriteAngle(Brush, random(0,360))
SetSpriteVisible(Brush,1)
DrawSprite(Brush)
SetSpriteVisible(Brush,0)
SetRenderToScreen()
// set the new render image as the current scene and swap the buffers for next time
SetSpriteImage( screen, buffer[currBuffer] )
currBuffer = 1-currBuffer
endfunction