Target Renderer

From FIFE development wiki
Jump to: navigation, search


Introduction

In previous version of FIFE you were allowed to draw on image just as on back buffer but it was far from optimal. Since 0.3.3 this is not possible anymore. Instead, we introduced Target Renderer to do it from now on. When using OpenGL render backend, it uses internally FBO or fallbacks to drawing on backbuffer and copying it to a destination when FBO isn't supported. With SDL, it just replace blitting destination for given image surface.

Usage

In order to make use of it you need to create render target and link it with an image:

image = imagemanager.load(image_file_path)
rendertarget = targetrenderer.createRenderTarget(image)

When you require to use it as a render target you simply call:

targetrenderer.setRenderTarget(image_file_path, discard=False, ndraws=0)
discard
tells FIFE that you care about previous contents of the image. If you want to just add something to already non trivial image you should set it to False. Otherwise, when you need to redraw whole image, you should set it to True.
ndraws
tells FIFE how frequently it should draw with ndraws=0 meaning just for the next frame, ndraws=1 means every frame, ndraws=2 means every other frame and so on. This option can be useful if you don't need to recreate/redraw an image every frame, like for instance the minimap image - only on change.

Drawing is done in the same way as with GenericRenderer.

Options

TargetRenderer

createRenderTarget(group, width, height)

returns a RenderTarget (image) with the given name and size

group
string; the group name
width
integer; width
height
integer; height

createRenderTarget((image)

returns a RenderTarget (image) based on the given image pointer, so you can render on already loaded / created images

image
fife.ImagePtr; image pointer

setRenderTarget(targetname, discard, ndraws)

sets a RenderTarget that is used by the TargetRenderer

targetname
string; target name
discard
bool; discard the content of the image or not
ndraws
integer; frequency of draws (0: only next frame, 1: every frame, 2: every other frame...)

render()

forces the target to render, should not be used as the engine calls this

RenderTarget

addLine(group, n1, n2, r, g, b, a = 255)

adds a line to the target

group
string; the group name
n1, n2
fife.Point objects; screen coordinates
r,g,b,(a)
integer; color values, range 0-255


addPoint(group, n, r, g, b, a = 255)

adds a point (pixel) to the target

group
string; the group name
n
fife.Point objects; screen coordinates
r,g,b,(a)
integer; color values, range 0-255


addTriangle(group, n1, n2, n3, r, g, b, a = 255)

adds a triangle to the target

group
string; the group name
n1, n2, n3
fife.Point objects; screen coordinates
r,g,b,(a)
integer; color values, range 0-255


addQuad(group, n1, n2, n3, n4, r, g, b, a = 255)

adds a quad to the target

group
string; the group name
n1, n2, n3, n4
fife.Point objects; screen coordinates
r,g,b,(a)
integer; color values, range 0-255


addVertex(group, n, size, r, g, b, a = 255)

adds a vertex (frame) to the target

group
string; the group name
n
fife.Point object; center coordinate
size
integer; dimensions
r,g,b,(a)
integer; color values, range 0-255


addText(group, n, font, text)

adds a text to the target

group
string; the group name
n
fife.Point object; center coordinate
font
fife.IFont; pointer to font object
text
string; a text


addImage(group, n, image)

adds another image to the target

group
string; the group name
n
fife.Point object; center coordinate
image
fife.ImagePtr; pointer to the image


addAnimation(group, n, animation)

adds an animation to the target

group
string; the group name
n
fife.Point object; center coordinate
animation
fife.AnimationPtr; pointer to the animation


resizeImage(group, n, image, width, height)

adds another image in a different size to the target

group
string; the group name
n
fife.Point object; center coordinate
image
fife.ImagePtr; pointer to the image
width
integer; new width
height
integer; new height


removeAll(group)

removes all elements of the given group

group
string; the group name


removeAll()

removes everything


render()

forces the target to render, should not be used as the engine calls this


getTarget()

returns the target image

Example

Here we create a new RenderTarget with width=200, height=200. Then we add a red quad on it and let the GenericRenderer draws it on screen.

 # self.hero.instance is an instance of fife.Instance()
 # self.camera is an instance of fife.Camera()
 
 #get renderer
 target_renderer = self.engine.getTargetRenderer()
 generic_renderer = fife.GenericRenderer.getInstance(self.camera)
 
 #create and set target
 target = target_renderer.createRenderTarget("testimage.png", 200, 200)
 target_renderer.setRenderTarget("testimage.png", True, 0)
 
 #add quad
 target.addQuad("quads", fife.Point(0,100), fife.Point(100,100), fife.Point(100,0), fife.Point(0,0), 255, 0, 0)
 
 #create node
 node = fife.RendererNode(self.hero.instance)
 
 #add target to generic
 generic_renderer.addImage("quad_test", node, target.getTarget())