Hi all. I found this rendering target stuff pretty neat and thought I would share this. I cant believe I was missing out on the speed! pcRaider indirectly reminded me of the newsletter 69 article about this stuff. So thanks pcRaider!
This example demostrates that you can use multiple rendering targets and update it's target size area dynamically during runtime. This example updates the render targets every frame to just show how it effects the fps. Obviously, we would want to change the target size only when needed to not effect the fps this way. Ofcoarse as in this example as an extreme case, the more rendering targets you change in size at each frame, the slower it gets.
What can it be used for? For me, I needed a fast way to update a target scrolling area such as a word editor or a treeview area in my gui Im making. I could also imagine a use for it for a chat dialog like what MMO's use where you can resize the chat window to see more messages.
This is by far faster then trying to cut/clip images inside a rectangler area and updating images via the Get Image command and/or transfering specified image data through memblocks. Can't wait to use this method in my C coded plug-in.
Hope somebody can find this useful...
Rem Dynamic Rendering Targets Example
sync on
sync rate 0
autocam off
cls rgb(255,128,0) : Rem never should see this color in "this" example
Rem Make a camera for use as fps player view for example...
make camera 1
color backdrop 1,rgb(95,95,95) : Rem background color
Rem animate dynamic render targets
global global_pos as integer
global_pos = 128
global global_bdir as integer
global_bdir = 0
Rem keep track of of sync mask
global global_smask as integer
global_smask = %1111111111111111 : Rem Render Target Camera bits will be set to Zero
Rem Dynamic Render Target Camera #1
RenderTargetCam1 = 3
RenderTargetImage1 = 3
MySprite1 = 3
Rem Dynamic Render Target Camera #2
RenderTargetCam2 = 4
RenderTargetImage2 = 4
MySprite2 = 4
Rem Set Render Target Camera Bits to Zero so they wont render, otherwise the image used will be destroyed
global_smask = global_smask ~~ (2 ^ RenderTargetCam1)
global_smask = global_smask ~~ (2 ^ RenderTargetCam2)
sync mask global_smask : Rem Update Sync Mask
Rem Example Loop
do
UpdateRenderTarget(RenderTargetCam1,RenderTargetImage1,MySprite1,16,100)
UpdateRenderTarget(RenderTargetCam2,RenderTargetImage2,MySprite2,16+128+16,100)
text 10,10,"HELLO WORLD"
Sync
loop
end
Rem Example function to Update the Render Target Dynamically
Function UpdateRenderTarget(param_rtc as integer, param_rti as integer, param_sprite as integer, param_x as integer, param_y as integer)
Rem Hard coded render target's width and height size to 128x128 here as for use as an example...
if global_bdir = 0
inc global_pos
endif
if global_bdir = 1
dec global_pos
endif
if global_pos>128
global_bdir = 1
endif
if global_pos<0
global_bdir = 0
endif
make camera param_rtc : Rem Make Render Target Camera
set camera to image param_rtc,param_rti,global_pos,128 : Rem Set Render Target Image to Camera and set it's size
Rem Upate Current Render Target graphics
set current bitmap -param_rtc
cls rgb(0,0,255)
text 2,2,"-"+str$(param_rtc)
center text 64,64,"FPS: "+str$(SCREEN FPS())
set current bitmap 0
Rem Delete Camera
Delete Camera param_rtc
Rem Update Sprite to show updated render target
sprite param_sprite,param_x,param_y,param_rti
EndFunction