Quote: "Render target is "camera to image"?"
Not exactly:
Quote: "MSDN ¬
A render target is a buffer where the video card draws pixels for a scene that is being rendered by an Effect Class.
The default render target is called the back buffer - this is the part of video memory that contains the next frame to be drawn. You can create other render targets with the RenderTarget2D class - in effect, reserving new regions of video memory for drawing. Most games render a lot of content to other render targets besides the back buffer ("offscreen"), then assemble the different graphical elements in stages, combining them to create the final product in the back buffer."
The idea is to render all the text or 2d to a render target texture as if it was like a text sheet/ 2d layer that would sit on top the of the 3d scene. I believe the camera render target is the default back buffer or frame buffer and this is what 'set camera to image' captures.
You'll need Ian M's matirx plugin (only this for my snippet below) and or Imagekit for further manipulation to make and edit render targets. Here's an example of a ton of text i've pre-rendered to a render target and at runtime I only update a bit of text when I need to, in this case it's the fps value on the image. This is done by clearing the text value in it's position then re-writing the new value.
// rect2 = rectangle 2d - stores rectangles positions
type rect2
x, y, w, h
endtype
global _rect2 as rect2
// set up screen
sync on : sync rate 0
set text size 32
// set up our text sheet via a render target
make image 1,screen width(),screen height()
draw to image 1
for n = 0 to 1023
text rnd(screen width()),100+rnd(screen height()-140),"Hello World"
next
// important bit - since "screen fps: " doesn't change put it on our image
text 20, 20, "screen fps: "
draw to bitmap 0
make object cube 1,1
do
r# = wrapvalue(r#+0.25)
rotate object 1,r#,r#,0
// what we are doing here is checking if a variable on the image needs updating.
// if it does, we first work out where it is on the image and then remove it by colouring
// it the same as our alpha channel which is rgb(0,0,0), then we add the new text
// in it's place.
if fps <> lastFps
draw to image 1
// work out where it is and store it in a rect2
start = len("screen fps: ") // - the start position we want to clear from
size = len(str$(lastFps)) // - the end position we want to clear to
getInStringRect( 20, 20, "screen fps: "+str$(lastFps), start, size )
// now we've worked out the postion we can update our text on our image
ink 0x00000000 // - this color is what the render target uses for transparencey
box _rect2.x, _rect2.y, _rect2.x+_rect2.w,_rect2.y+_rect2.h
ink rgb(255,255,255)
text _rect2.x,_rect2.y,str$(screen fps())
draw to bitmap 0
lastFps = fps
endif
// the final result
paste image 1,0,0,1
lastFps = fps
fps = screen fps()
sync
loop
// gets the rectangular position of part our text
function getInStringRect( x, y, str as string, start, size )
local cutString0 as string
local cutString1 as string
cutString0 = mid$(str, 1, start)
cutString1 = mid$(str, start+1, size)
_rect2.x = x + text width(cutString0)
_rect2.y = y
_rect2.w = text width(cutString1)
_rect2.h = text size()
endfunction
"Get in the Van!" - Van B