Target Renderer

From FIFE development wiki
Revision as of 14:42, 21 March 2012 by Helios2000 (Talk | contribs)

Jump to: navigation, search
wiki
Document Data structures Data strucures
Concepts illustrated here are relevant to understand what kind of data FIFE engine is able to process.

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 parameter tells FIFE do 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 imagee every frame, like for instance minimap image - only on change.

Drawing is done in the same way as with GenericRenderer.

Options

TargetRenderer

createRenderTarget(const std::string& name, uint32_t width, uint32_t height)
- returns a RenderTarget(Image) with the given name and size
createRenderTarget(ImagePtr& image)
- returns a RenderTarget(Image) based on the given image, so you can render on already loaded/created images
setRenderTarget(const std::string& targetname, bool discard, int32_t ndraws = 0)
- sets a RenderTarget that is used by the TargetRenderer
render()
- forces the TargetRender to render, should not be used because engine calls it

RenderTarget

addLine(const std::string &group, Point n1, Point n2, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
- adds a line to the target. group mean the group name, points are screen coordinates, r,g,b,(a) are the color values, range 0-255
addPoint(const std::string &group, Point n, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
- adds a point(pixel) to the target. group mean the group name, points are screen coordinates, r,g,b,(a) are the color values, range 0-255
addTriangle(const std::string &group, Point n1, Point n2, Point n3, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
- adds a triange to the target. group mean the group name, n points are screen coordinates, r,g,b,(a) are the color values, range 0-255
addQuad(const std::string &group, Point n1, Point n2, Point n3, Point n4, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
- adds a quad to the target. group mean the group name, n points are screen coordinates, r,g,b,(a) are the color values, range 0-255
addVertex(const std::string &group, Point n, int32_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
- adds a vertex(frame) to the target. group mean the group name, n is the center, size is dimensions, r,g,b,(a) are the color values, range 0-255
addText(const std::string &group, Point n, IFont* font, const std::string& text)
- adds a text to the target. group mean the group name, n is the center, font is the pointer to used font, text is the string
addImage(const std::string &group, Point n, ImagePtr image)
- adds another image to the target. group mean the group name, n is the center, image is the pointer to the used image
addAnimation(const std::string &group, Point n, AnimationPtr animation)
- adds a animation to the target. group mean the group name, n is the center, animation is the pointer to the used animation
resizeImage(const std::string &group, Point n, ImagePtr image, int32_t width, int32_t height)
- adds another image in a different size to the target. group mean the group name, n is the center, image is a pointer to the used image, w,h defines the new size
removeAll(const std::string &group)
- removes all elements with this group string
removeAll()
- removes all
render()
- forces the target to render its stuff, should not be used because engine calls it
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.

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())