User Guide Vol3

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 181

DownloadUser Guide Vol3
Open PDF In BrowserView PDF
User Guide
Volume III

Copyright © 2003 – Criterion Software Ltd.

User Guide

Contact Us
Criterion Software Ltd.
For general information about RenderWare Graphics e-mail info@csl.com.

Developer Relations
For information regarding Support please email devrels@csl.com.

Sales
For sales information contact: rw-sales@csl.com

Acknowledgements
Contributors

RenderWare Graphics Development and Documentation
Teams

The information in this document is subject to change without notice and does not represent a commitment on the part
of Criterion Software Ltd. The software described in this document is furnished under a license agreement or a nondisclosure agreement. The software may be used or copied only in accordance with the terms of the agreement. It is
against the law to copy the software on any medium except as specifically allowed in the license or non-disclosure
agreement. No part of this manual may be reproduced or transmitted in any form or by any means for any purpose
without the express written permission of Criterion Software Ltd.
Copyright © 1993 - 2003 Criterion Software Ltd. All rights reserved.
Canon and RenderWare are registered trademarks of Canon Inc. Nintendo is a registered trademark and NINTENDO
GAMECUBE a trademark of Nintendo Co., Ltd. Microsoft is a registered trademark and Xbox is a trademark of Microsoft
Corporation. PlayStation is a registered trademark of Sony Computer Entertainment Inc. All other trademark mentioned
herein are the property of their respective companies.
III-2

11 February 2004

Table of Contents
Part F - Utility Libraries ........................................................................................... 7
Chapter 30 - 2D Graphics Toolkits ........................................................................... 9
30.1 Introduction ................................................................................................10
30.1.1

The 2D Toolkit ................................................................................ 10

30.1.2

2D Objects ..................................................................................... 10

30.1.3

The Character Set Toolkit ................................................................. 10

30.2 Using the 2D Toolkit.....................................................................................11
30.2.1

Initialization.................................................................................... 11

30.2.2

Device Abstraction........................................................................... 11

30.2.3

The Current Transformation Matrix .................................................... 12

30.2.4

Paths ............................................................................................. 13

30.2.5

Brushes.......................................................................................... 16

30.2.6

The Current Transformation Matrix .................................................... 17

30.2.7

Fonts ............................................................................................. 19

30.3 2D Objects..................................................................................................23
30.3.1

Introduction.................................................................................... 23

30.3.2

Creating Objects ............................................................................. 23

30.3.3

Adding Objects to a Scene................................................................ 26

30.3.4

Object Serialization.......................................................................... 28

30.3.5

Object Manipulation ......................................................................... 28

30.3.6

Object Rendering ............................................................................ 30

30.3.7

Object Destruction........................................................................... 30

30.3.8

Objects .......................................................................................... 30

30.4 The Character Set Toolkit .............................................................................32
30.4.1

Initialization.................................................................................... 32

30.4.2

The Font Descriptor ......................................................................... 32

30.4.3

Rendering....................................................................................... 33

30.4.4

Destroying the font.......................................................................... 33

30.5 Font File Formats .........................................................................................34
30.5.1

"Metrics 1" (Bitmap) ........................................................................ 34

30.5.2

"Metrics 2" (Bitmap) ........................................................................ 34

30.5.3

"Metrics 3" (Outline) ........................................................................ 35

30.6 Summary....................................................................................................38
30.6.1

2D Toolkit ...................................................................................... 38

30.6.2

Key Points ...................................................................................... 38

30.6.3

Paths & Brushes .............................................................................. 38

30.6.4

The Camera.................................................................................... 38

30.6.5

Current Transformation Matrix .......................................................... 39

30.6.6

Fonts ............................................................................................. 39

30.6.7

Rt2dObjects.................................................................................... 39

30.6.8

Character Set Toolkit ....................................................................... 39

User Guide

Chapter 31 - Maestro ............................................................................................ 41
31.1 Introduction ................................................................................................ 42
31.1.1

Maestro Overview ........................................................................... 42

31.1.2

This document ................................................................................ 44

31.1.3

Other Resources ............................................................................. 44

31.1.4

Using the maestro1 Example ............................................................ 44

31.2 Flash and RenderWare Graphics .................................................................... 46
31.2.1

Supported Features ......................................................................... 46

31.2.2

Unsupported Features...................................................................... 47

31.3 Creating 2D Content for Use Within RenderWare Graphics ................................ 49
31.3.1

Publishing an SWF ........................................................................... 49

31.3.2

Elements of a User Interface............................................................. 50

31.3.3

Virtual Controllers and Console Artwork ............................................. 55

31.4 Importing Flash Files into RenderWare Graphics .............................................. 57
31.4.1

Importing the SWF into RenderWare Graphics .................................... 57

31.4.2

2d Viewer....................................................................................... 58

31.5 Developing With Maestro .............................................................................. 59
31.5.1

Introduction ................................................................................... 59

31.5.2

Playback of an ANM file in RenderWare Graphics ................................. 60

31.5.3

String Labels .................................................................................. 63

31.5.4

Messages ....................................................................................... 65

31.5.5

Hooking a custom message handler................................................... 67

31.5.6

Triggering button transitions by name ............................................... 68

31.5.7

Mouse Interaction on a PC................................................................ 69

31.6 Summary ................................................................................................... 72
31.7 Appendix I – Planning a Menu System............................................................ 73
31.7.1

Planning a Menu.............................................................................. 73

31.7.2

Main Menu Frames .......................................................................... 74

31.8 Appendix II – Naming Conventions ................................................................ 75
Chapter 32 - The User Data Plugin ........................................................................ 77
32.1 Introduction ................................................................................................ 78
32.2 Plugin Features ........................................................................................... 79
32.2.1

User Data Arrays............................................................................. 79

32.3 Storing User Data ........................................................................................ 81
32.3.1

Exporters ....................................................................................... 81

32.3.2

Procedural Generation ..................................................................... 82

32.3.3

Accessing User Data ........................................................................ 83

32.3.4

Deleting User Data .......................................................................... 85

32.4 Summary ................................................................................................... 86
32.4.1

Main Properties ............................................................................... 86

32.4.2

Access functions.............................................................................. 86

32.4.3

Creation ......................................................................................... 87

Part G - PowerPipe................................................................................................ 89
Chapter 33 - PowerPipe Overview......................................................................... 91
III-4

11 February 2004

Table of Contents

33.1 Introduction ................................................................................................92
33.1.1

What is PowerPipe? ......................................................................... 92

33.1.2

Pipelines and Nodes ......................................................................... 92

33.1.3

PowerPipe Usage in the Real World .................................................... 93

33.1.4

Other Documents ............................................................................ 93

33.2 Pipelines .....................................................................................................94
33.2.1

Pipeline Usage ................................................................................ 94

33.2.2

Pipeline Structure ............................................................................ 95

33.2.3

Dataflow in Pipelines........................................................................ 97

33.2.4

Pipeline Construction ....................................................................... 99

33.3 Generic Pipelines ....................................................................................... 104
33.3.1

RwIm3D....................................................................................... 104

33.3.2

RpAtomic ..................................................................................... 108

33.3.3

RpWorldSector .............................................................................. 109

33.3.4

RpMaterial .................................................................................... 110

33.4 Platform Specific Pipelines .......................................................................... 112
33.5 Common Traps and Pitfalls.......................................................................... 113
33.6 Summary.................................................................................................. 114
Chapter 34 - Pipeline Nodes ................................................................................ 115
34.1 Introduction .............................................................................................. 116
34.1.1

The Node Definition ....................................................................... 116

34.1.2

Node Methods ............................................................................... 116

34.1.3

Other Documents .......................................................................... 117

34.2 The Node Definition.................................................................................... 118
34.2.1

Example Code ............................................................................... 118

34.2.2

Structures .................................................................................... 120

34.2.3

Input Requirements and Outputs..................................................... 121

34.2.4

Node Methods ............................................................................... 125

34.3 The Node Body Method............................................................................... 128
34.3.1

Packet Manipulation....................................................................... 129

34.3.2

Cluster Manipulation ...................................................................... 130

34.3.3

Example Code ............................................................................... 134

34.4 Provided Nodes ......................................................................................... 138
34.4.1

The Standard Clusters.................................................................... 138

34.4.2

The Generic Nodes ........................................................................ 145

34.5 Common Traps and Pitfalls.......................................................................... 161
34.5.1

Pipeline Construction Problems ....................................................... 161

34.5.2

Pipeline Performance ..................................................................... 162

34.5.3

RxCluster->numUsed..................................................................... 162

34.6 Summary.................................................................................................. 164
Appendix - Recommended Reading ..................................................................... 165
Index .................................................................................................................. 177

RenderWare Graphics 3.7

III-5

Part F

Utility Libraries

Chapter 30
2D Graphics
Toolkits

Chapter 30- 2D Graphics Toolkits

30.1 Introduction
This chapter covers two 2D graphics toolkits: Rt2d and RtCharset.

30.1.1 The 2D Toolkit
Rt2d, the 2D Toolkit, provides a rich 2D graphics API that makes full use of
the acceleration provided by today's 3D graphics hardware. This provides
support for features including:
•

blending

•

anti-aliasing

•

transparency

•

fast rotation

•

bitmap and outline font support

30.1.2 2D Objects
The 2D objects section in the chapter builds upon the 2D Toolkit section,
explaining how to save objects that contain brushes, paths and fonts so
that you are able to reuse and manipulate them. The 2D objects that can
be created are:
•

shapes

•

scenes

•

pick regions

•

object strings

30.1.3 The Character Set Toolkit
RtCharset, the Character Set Toolkit, provides support for displaying text
using a basic, fast bitmapped font. Its speed makes it useful for displaying
debugging and metrics information.
The Character Set Toolkit is a no-frills toolkit which makes it relatively
inflexible and unsuitable for use in most released products.

III-10

11 February 2004

Using the 2D Toolkit

30.2 Using the 2D Toolkit
The Rt2d API lets the developer create 2D graphics imagery using the full
power of the RenderWare Graphics engine. The 2D Toolkit makes use of
traditional 2D graphics primitives, such as brushes and paths, to make
working with the toolkit easier.

30.2.1 Initialization
The Rt2dOpen() function initializes the 2D Toolkit. However, the 2D Toolkit
needs to be told which camera to use before any rendering can be
performed. The Rt2dOpen() function therefore takes an RwCamera pointer
as its only parameter.
This function must be called before any 2D functions in the toolkit can be
used.
After Rt2dOpen()has been called, it is possible to replace the current
camera with another using the Rt2dDeviceSetCamera() function.
All rendering is performed on the chosen camera. Rendering to a camera
that has a raster attached to it for later use as a texture
(rwRASTERTYPECAMERATEXTURE) is also supported.

✎

Cameras
RenderWare Graphics' virtual camera object is covered in full detail in the chapter
entitled: The Camera.

Closing the 2D Toolkit
This must be done before terminating RenderWare Graphics itself and is
achieved using Rt2dClose().

30.2.2 Device Abstraction
With a camera now set up as a target for rendering, the next step is to
interrogate it and determine its dimensions and other useful properties. For
this purpose, the 2D Toolkit API includes a set of Rt2dDevice…()
functions.

Coordinate Mapping
A camera uses an RwRaster for the rendered graphics. As this raster object
can be of arbitrary size, the Rt2dDeviceGetMetric() function can be used
to obtain the current origin and width/height mappings:
success = Rt2dDeviceGetMetric ( &x, &y, &width, &height );

The variables x, y, width and height are RwReal values that will receive
the output device's origin (x and y) and its width and height.
RenderWare Graphics 3.7

III-11

Chapter 30- 2D Graphics Toolkits

It is also possible to use the Rt2dDeviceSetMetric() function to change
these values, so that the application can work at a lower or higher
resolution internally.
The 2D Toolkit can render 2D graphics at any scale. It may also render
graphics to a plane set at an arbitrary distance from the camera (see
Layering, below), so another device function, Rt2dDeviceGetStep(), is
provided to determine how big a pixel is at the current depth and scale.
The Rt2dDeviceGetStep() function fills two 2D-vectors representing a
one-pixel step in the x and y axes, and fills a third vector with the offset to
the origin.

Layering
The 2D Toolkit renders to a plane parallel to the camera view-plane. The
plane's depth—its distance from the camera—can be changed using
Rt2dDeviceSetLayerDepth().
By default, the plane is at a depth of 1.0 units. Any new value should be
greater than zero.

Pipeline Flags
Rt2dSetPipelineFlags() takes a combination of flags defining how
rendering is to be performed. The flags are defined by the
RwIm3DTransformFlags enumerations, although only the rwIM3D_NOCLIP
and rwIM3D_ALLOPAQUE flags produce useful results.
Values are logically ORed with the current immediate mode flag settings.

30.2.3 The Current Transformation Matrix
The 2D Toolkit relies on the underlying 3D graphics engine. This means 2D
coordinates must be transformed into 3D space before any rendering can
be performed.
The Current Transformation Matrix (CTM) is used to convert 2D data into 3D
space. Multiple CTMs are supported using a stack-based mechanism.
•

Rt2dCTMPush() pushes a new CTM onto the stack, making it the active
CTM.

•

Rt2dCTMPop() removes the top CTM from the stack and destroys it,
making the next CTM on the stack active.

The CTM can be rotated, scaled and translated. These transformations
affect the rendered imagery accordingly, allowing layering, rotating and
scrolling of 2D graphics.

III-12

11 February 2004

Using the 2D Toolkit

30.2.4 Paths
An Rt2dPath object defines a path in 2D space. The path can contain one
or more lines or curves and can be either open-ended or closed.
Rendering a path involves specifying a brush (covered in 30.2.5 Brushes)
that is used to paint the path.
A brush defines the color and texture used when drawing (known as
stroking) or filling a path.

Creating Paths
The Rt2dPathCreate() function returns a pointer to an empty path object
(Rt2dPath). When the path is created it is locked.
Once created, the path information is added to the object using one or more
of the functions listed in the following table.
USE

TO

Rt2dPathMoveto()
Rt2dPathLineto()

Move to a specific coordinate
Draw a line from the current location to
another
Draw a line from the current location to
another (uses relative coordinates)
Draw a curve from the current location to
another
Draw a curve from the current location to
another (control points given in relative
coordinates)
Add a rectangle to the path
Add a rounded rectangle to the path
Add an oval to the path

Rt2dPathRLineto()
Rt2dPathCurveto()
Rt2dPathRCurveto()

Rt2dPathRect()
Rt2dPathRoundRect()
Rt2dPathOval()

Locking and Unlocking Paths
Paths can be locked using Rt2dPathLock() and unlocked using
Rt2dPathUnlock().

Open and Closed Paths
An open path has two distinct ends at separate locations.
A closed path describes a closed polygon and starts and ends at the same
location.
An open path can be closed by calling Rt2dPathClose(). This function will
add an extra line connecting the two ends of the path.

RenderWare Graphics 3.7

III-13

Chapter 30- 2D Graphics Toolkits

Deleting Paths
When your application has finished with a path object, it needs to be
destroyed. This is performed by a call to Rt2dPathDestroy().

Rendering Paths
A path can be rendered either by stroking it, or by filling it.
Stroking a path—whereby the path is drawn as a line—involves specifying a
brush which defines the color and/or texture to be used during rendering.
The texture will be tiled or stretched along the path according to the UV
mapping set with Rt2dBrushSetUV(). The width of the stroke is set by a
call to Rt2dBrushSetWidth().
To paint a path, call Rt2dPathStroke(), which takes a pointer to both the
path and the brush.

Filled Paths
Filling treats the path as a window through which a brush will be visible.
The brush is rendered as a texture of the same size as the path's bounding
box. The path itself is used as a mask so that the parts of the texture that
are outside the path are not rendered.
Rt2dPathFill() is used to fill the specified path using the colors and
texture coordinates of the given brush. The path must be closed for this
function to work properly. The fill color for each point within the path is
determined by bilinear interpolation of the colors of the brush assuming
they represent the colors of the four corners of the path's bounding box.
Hence, the fill color depends on the relative distance of each interior point
from the corner points of the path's bounding box. If the brush also
specifies texture coordinates and a texture image, the path is filled with the
image assuming that the bounding box corners have the texture
coordinates of the brush.

✎

Due to the algorithm used, Rt2dPathFill() will produce undefined results if the path
specified is concave or crosses over itself.

The Inset Value
The 2D Toolkit supports an inset value for each path. This value specifies
an offset from the center of the path's stroke. This offset is used when
rendering, so that a path can be re-rendered inset or outset from a previous
rendering of the same path.
For example, a path describing a simple rectangle could be rendered once,
then re-rendered with its inset value modified so that a second box appears
inside the original.

III-14

11 February 2004

Using the 2D Toolkit

Flattening Curves
It is necessary to replace curves with short line segments—a process known
as flattening—so that the curve can be rendered. In such cases, the
Rt2dPathFlatten() function can be used to convert the curves in a path
into straight line segments. A tolerance value which governs the number of
resulting straight lines produced can be modified using
Rt2dPathSetFlat(). This value is set to 0.5 by default.
Ideally, flattening should be performed only once per curve as repeated
calls to Rt2dPathFlatten() may impact heavily on performance.

Bounding Boxes
Paths have a bounding box, which is a 2D box with boundaries that
completely contains the path. This box is important when rendering the
shape described by a path as the brush used to fill the shape will be scaled
to match the dimensions of the path's bounding box.
The Rt2dPathGetBBox() function is used to obtain the bounding box for a
specified path. This bounding box uses an Rt2dBBox structure, which
defines a two-dimensional box.
{
RwReal
RwReal
RwReal
RwReal

x;
y;
w;
h;

/*
/*
/*
/*

x coordinate of lower-left corner */
y coordinate of lower-left corner */
width */
height */

}

Clipping Paths
RenderWare Graphics will avoid performing clipping operations if the
underlying platform allows it to do so. (This is the case on the PlayStation®2
platform, for instance.) However, your application may need to perform
clipping itself for its own purposes. For this reason, a clipping path
representing the area within which all rendering takes place, can be
obtained using Rt2dDeviceGetClippath(). 2D graphics rendering with
the 2D Toolkit will not be visible outside this path, which can therefore be
used for clipping calculations.
The clipping path is an ordinary Rt2dPath object and will usually be a
rectangle.

Emptying & Copying Paths
An existing path can be emptied with a call to Rt2dPathEmpty(). This
function will delete all existing path data from the structure.

RenderWare Graphics 3.7

III-15

Chapter 30- 2D Graphics Toolkits

Copying paths can be performed by a call to Rt2dPathCopy(). This
function will call Rt2dPathEmpty() on the destination path; concatenation
is not performed. The destination path must have been created using
Rt2dPathCreate().

30.2.5 Brushes
The brush object (Rt2dBrush) represents color and texture information
used when stroking or filling a path. In addition, a brush can be given a
width which defines the width of a stroked path.

Creating Brushes
Brushes are created using Rt2dBrushCreate(), which returns a pointer to
a valid brush object. This object then needs to be initialized with useful
data.

Properties
A brush object contains a number of properties that can be set by the
application. The properties, with the functions used to set them, are listed
in the following table. These properties must be set by the application prior
to using the brush for rendering.

III-16

PROPERTY

API FUNCTIONS

RGBA. Four color vectors are used. These
define the color at each of the four corners
of the brush. The colors are bi-linearly
interpolated when rendering.
Texture. this defines a bitmap which will be
used when rendering the brush. The
texture will be stretched and/or tiled
according to the brush's UV values (see
next entry).
Texture coordinates. Four UV pairs are
stored in a brush. For painting, they define
the texture coordinates at the corners of
the resulting primitive. When filling a path,
they define the texture coordinates at the
corners of the path's bounding box. In both
cases, corner texture coordinates are
ordered anti-clockwise and interior
coordinates are determined by bilinear
interpolation.
Width. This defines the width of a stroked
path.

Rt2dBrushSetRGBA()

Rt2dBrushSetTexture()

Rt2dBrushSetUV()

Rt2dBrushSetWidth()
Rt2dBrushGetWidth()

11 February 2004

Using the 2D Toolkit

Rendering
It is important to note that brushes can only be rendered with paths. For
example, a billboard (also known as a sprite by some 2D games
programmers) would be created as follows:
1. Define a brush with a texture
2. Set UV values according to requirements
3. Define a path in the shape of a simple rectangle
4. Render the path using the brush and Rt2dPathFill()
Rendering is performed using the RenderWare Graphics' 3D engine, so
texture data can contain alpha information, enabling translucency and
transparency effects.

30.2.6 The Current Transformation Matrix
A transformation matrix is used to transform vertices from one space—such
as local or object space—to another—usually the device space. The 2D
Toolkit makes use of transformation matrices during rendering, passing all
the vertices it processes through a transformation matrix when rendering.
The 2D Toolkit maintains a stack of transformation matrices and the top
matrix on the stack is the current transformation matrix (CTM). The CTM is
the matrix used during rendering, but other matrices can be added or
removed from the stack arbitrarily.
For example, a speedometer in a racing car could be rendered directly onto
a 3D-rendered dashboard at the correct angle, scale and distance from the
camera using the 2D Toolkit alone. It would achieve this by setting up the
necessary transformation within the CTM.

The Rendering Process
Rendering with the 2D Toolkit is concerned mainly with paths being
stroked or filled by brushes. When rendering a path, the 2D Toolkit
converts the path into triangle strips which can then be rendered.

Object Spaces
Paths are defined in a local object space. This means that the first vertex in
a path is always the origin for that path; subsequent vertices within the
same path are defined relative to this local origin.
In order to render a path, its vertices must therefore be transformed into
device space. This involves processing the path through the CTM. The
processed vertices are then converted into 3D Immediate Mode triangle
strips and rendered according to the brush's settings.

RenderWare Graphics 3.7

III-17

Chapter 30- 2D Graphics Toolkits

The CTM therefore defines the transformation needed to move the path's
object space vertices to screen space.

The CTM Stack
When the Rt2dOpen() function is called, a CTM stack is initialized,
containing one CTM.

Initializing a CTM
The default transformation matrix is the identity matrix. You can reset the
current transformation matrix.
As all paths are defined in object space, it is likely that a number of
transformation matrices will be needed by your application—often one for
each path. For this reason, the 2D Toolkit exposes a CTM stack API to help
manage transformation matrices.
The transformation matrices are stored as full RwMatrix objects. The CTM
can therefore be copied into an RwMatrix object with a call to
Rt2dCTMRead().
The use of RwMatrix objects means that transformations can use all three
axes: x, y and z. The transformation and rendering of 2D graphics using
the 2D Toolkit is performed in hardware wherever possible, so a number of
techniques are made available to the 2D graphics programmer that would
previously have required CPU-intensive processing, such as rotation and
layering.

Using the CTM Stack
Earlier, we saw that the CTM is the top-most matrix on the stack. When a
new transformation matrix is needed, the current transformation matrix
can be pushed down the stack and a new CTM placed at the top of the
stack. This is achieved by a call to Rt2dCTMPush(). The new CTM is a copy
of the pushed transformation matrix.
To revert to a previous transformation matrix, the current matrix can be
popped off the stack—deleting it in the process—so that the next matrix in
the stack becomes the current transformation matrix. This is performed by
a call to Rt2dCTMPop().
The 2D Toolkit always renders using the current transformation matrix—
i.e. the top-most transformation matrix on the CTM stack.

Setting Transformations
When a valid CTM is on the stack, the 2D Toolkit can be used to set the
transformations required by the application. In most cases, the application
will only need to transform vertices in a 2D plane. Dedicated 2D
transformation functions are therefore provided, as shown in the following
table:
III-18

11 February 2004

Using the 2D Toolkit

TO

USE

Rt2dCTMTranslate()
Apply a translation to the current
transformation matrix (CTM) using the
specified x- and y-components
Rt2dCTMScale()
Apply a scale transformation to the
current transformation matrix using the
specified x- and y-scale factors
Rt2dCTMRotate()
Apply a rotation to the current
transformation matrix using the specified
angle of rotation
All transformations are pre-concatenated with the CTM.

Rendering & Cameras
Rt2d rendering functions need to be called within
RwCameraBeginUpdate() and RwCameraEndUpdate() using the last
camera set for Rt2d operations via the Rt2dOpen() or
Rt2dDeviceSetCamera().

30.2.7 Fonts
The 2D Toolkit supports three specific types of font:
1. Metrics 1 – A bitmap font format which requires a bitmap image (an
optional mask can also be specified). An associated .met file—a text
file—is used to define the positions of each character within the bitmap.
2. Metrics 2 – A variant of Metrics 1. This format uses marker pixels within
the bitmap to determine the location of each character, removing the
need to specify them explicitly in the .met text file.
A major advantage of this format is support for multiple bitmap files and
a larger number of characters. This makes it better suited to
applications where non-Roman characters must be used (e.g. Chinese,
Greek, Japanese or Korean character sets).
3. Metrics 3 – An outline font. This format is based loosely on the Adobe®
Type 1 font format in that each character is defined explicitly as paths
using text instructions within the .met file.
The file formats are described fully in section 30.5 Font File Formats, at the
end of this chapter.

✎

Rendering outline fonts
It is important to note that outline fonts are always stroked. It is not possible to render
filled characters.

RenderWare Graphics 3.7

III-19

Chapter 30- 2D Graphics Toolkits

Using Fonts
Before a font can be used, it must first be read. This is performed by a call
to Rt2dFontRead(). This function takes the name of a .met file. A search
path for the font metrics file should be set prior to this call using
Rt2dFontSetPath(). The result is a pointer to an Rt2dFont object.
Alternatively, a binary font can be loaded from a RwStream using
Rt2dFontStreamRead(). This loads just the font data and returns an
Rt2dFont object. Both outline and bitmap fonts are loaded with the same
method. If the font is a bitmap, any associated textures will be loaded into a
texture dictionary, if not already present. The font data chunk is identified
by the chunk header rwID_2DFONT.
A Rt2dFont object is written out to a RwStream using
Rt2dFontStreamWrite(). Rt2dFontStreamGetSize() can be used to
query the size, in bytes, of the Rt2dFont data chunk in an RwStream.
When working with outline fonts, the height parameter in most Rt2dFont
functions determines the scaling factor at which the font is to be rendered,
as well as the upper bound of its bounding box. For bitmap fonts, the
height defines only the upper bound of a bounding box. Scaling of bitmap
fonts should be performed by setting a scale transform in the CTM.
There are two functions provided for rendering text using the chosen font:
1. Rt2dFontShow() renders a string displayed using the specified font and
rendered using the specified brush. A 2D vector specifying the lower-left
coordinate of the text's bounding box—and therefore, its position on the
screen—must also be specified, as well as a height for the rendered text.
The 2D vector is updated to point to the end of the string’s position on
screen. This is so that any following strings will be rendered in the
correct position after the current string.
Only one line is displayed, clipped and transformed using the current
transformation matrix.
2. Rt2dFontFlow() is similar to Rt2dFontShow(), except that it renders
the string into a box (Rt2dBBox), flowing the text according to the
justification specified. The 2D Toolkit will flow the text into the box until
it either runs out of text, or it runs out of space. In the latter case, the
text will be truncated.
The supported justification flags for Rt2dFontFlow() are listed in the
following table:
FLAG

RESULT

rt2dJUSTIFYLEFT

Lines are aligned with the left edge of the
bounding box
Lines are centered within the bounding box
Lines are aligned with the right edge of the
bounding box

rt2dJUSTIFYCENTER
rt2dJUSTIFYRIGHT

III-20

11 February 2004

Using the 2D Toolkit

Destroying a Font
When your application has finished using a particular font, the Rt2dFont
object needs to be destroyed with a call to Rt2dFontDestroy().

Font Texture Dictionary
All the textures for bitmap fonts are stored in a texture dictionary,
RwTextDictionary. This dictionary can be the main dictionary or a local
dictionary just for the font textures.
Rt2dFontTextDictionarySet() is used to set the active dictionary for
storing the font textures. Rt2dFontTextDictionaryGet() is used to query
the current active dictionary.

Unicode Font
Unicode allows 1 million unique characters to be represented and are
supported in a Rt2dFont object. Rt2dFont only supports the first 64,000
characters which can be encoded using two bytes per character. This is still
sufficient to encode most of the major language’s characters.
There are no explicit functions to enable Unicode support. A Rt2dFont is
classed as a Unicode font automatically when reading the font’s metric file.
If the metric file contains characters that are outside the ASCII character
set, the font will be classed as a Unicode font, otherwise it is classed as an
ASCII font.
The classification of the font is important since this affects the processing
of the string. Strings using a Unicode font needs to be in double byte
format, so Unicode characters can be encoded. This also include the ASCII
characters in string. Strings using a ASCII font are assumed to be in single
byte.
Rendering a Unicode string is done using the standard string rendering
functions, Rt2dFontFlow() and Rt2dFontShow().

Utility Functions
The 2D Toolkit's font API includes some additional functions to help
determine where and how to render a string:
• Rt2dFontGetHeight() will return the real height of a bitmap font as it
would appear when rendered, taking into account the font's CTM and
the view settings. Using the bitmap font height when rendering text
ensures there is a one-to-one mapping to the display; hence the text's
rendered size remains independent of current transformations. (For
outline fonts, the Rt2dFontGetHeight() function will always return a
value of 1.0.)
RenderWare Graphics 3.7

III-21

Chapter 30- 2D Graphics Toolkits

• Rt2dFontGetStringWidth() is a utility function that returns the width
of a given string if it were rendered with the specified font and height.
• Rt2dFontSetIntergapSpacing() sets the spacing between the
individual characters when rendering the font. This allows characters to
be set further apart or closer together than normal.
• Rt2dFontIsUnicode() is a utility function to query if a font is classed as
a Unicode font, containing Unicode characters. Strings using a Unicode
font must be in double byte format. Strings using a pure ASCII font
must be in single byte format.

III-22

11 February 2004

2D Objects

30.3 2D Objects
30.3.1 Introduction
The previous section of this chapter dealt with the creation and usage of
brushes, paths and fonts. This section shows you how you can save objects
that contain brushes, paths and fonts so that you are able to reuse and
manipulate them. Groups of objects can be added to scenes where they can
be manipulated together.
There are four objects that can be used to store brush, path and text data.
These objects can be manipulated and rendered.
The four objects are:
1. Shapes: shapes are a collection of brushes and paths that are added
together using nodes. Shapes can be saved and added to scenes. This
chapter has already covered how to create paths and brushes.
2. Object Strings: an object string is an object that contains text. This
chapter has already covered how to create brushes and use fonts.
3. Pick Regions: a pick region is an area on a screen. They are invisible
and can be used, for example, for buttons and clickable areas. Pick
regions are not rendered, and need another object, for example a shape,
to represent them in a scene.
4. Scenes: a scene is a container of Rt2d objects that can be manipulated
and rendered. A scene is also an Rt2d object.

30.3.2 Creating Objects
How to create each object type is described below.

Creating a Shape
The following steps describe the procedure needed to create a shape.
1. Rt2dShapeCreate() creates a shape.
2. Rt2dBrushCreate() creates a brush using the functions described
earlier in this chapter. Brushes must be created for filling and stroking.
3. Rt2dPathCreate() creates a path.
a. Rt2dPathLock() locks the path. When the path is created it is
locked.
b. Build the path for the required shape.
c. Rt2dPathUnlock() unlocks the path.

RenderWare Graphics 3.7

III-23

Chapter 30- 2D Graphics Toolkits

4. Rt2dShapeAddNode() adds the shape, path, brush fill and brush
strokes together. Rt2dShapeGetNodeCount() can be used to find out
the number of nodes.

Code Example
/*
* Rectangle
*/
{
Rt2dObject *shape;
Rt2dPath *path;
Rt2dBrush *strokeBrush;
Rt2dCTMPush();
Rt2dCTMTranslate(WinBBox.w * 0.2f, WinBBox.h * 0.7f);
shape = Rt2dShapeCreate();
path = Rt2dPathCreate();
Rt2dPathLock(path);
Rt2dPathRect(path, -0.1f, -0.1f, 0.2f, 0.2f);
Rt2dPathUnlock(path);
strokeBrush = Rt2dBrushCreate();
Rt2dBrushSetRGBA(strokeBrush, &col[6], &col[6}, &col[2],
&col[2]);
Rt2dBrushSetWidth(strokeBrush, 0.03f);
Rt2dShapeAddNode(shape, rt2dSHAPENODEFLAGNONE, path,
strokeBrush);
Rt2dObjectApplyCTM(shape);
Rt2dObjectSetVisible(shape, TRUE);
Rt2dCTMPop();
}

Creating a String
The following steps describe the procedure needed to create an object
string.
1. Rt2dObjectStringCreate() creates an object string.
2. Rt2dObjectStringGetBrush() gets a brush used for rendering a
string. The brush affects the color/fill of the text and width of the
drawing.

III-24

11 February 2004

2D Objects

Code Example
{
Rt2dObject *string;
Rt2dBrush *strokeBrush;
Rt2dCTMPush();
Rt2dCTMTranslate(WinBBox.w * 0.2f, WinBBox.h * 0.2f);
/* set font */
string = Rt2dObjectStringCreate("Hello World",
RWSTRING("helv"));
strokeBrush = Rt2dObjectStringGetBrush(string);
Rt2dBrushSetRGBA(strokeBrush, &col[6], &col[6], &col[2],
&col[2]);
Rt2dBrushSetWidth(strokeBrush, 0.01f);
Rt2dObjectStringSetHeight(string, 0.2f);
Rt2dObjectApplyCTM(string);
Rt2dObjectSetVisible(string, TRUE);
Rt2dCTMPop();
}

Creating a Pick Region
The following steps describe the procedure needed to create a pick region.
1. Rt2dPickRegionCreate() creates a pick region.
2. Rt2dPickRegionGetPath() returns a path.
a. Rt2dPathLock() locks the path. When the path is created, it is
locked.
b. Build the path for the required pick region.
c. Rt2dPathUnlock() unlocks the path.

Code Example
{
Rt2dObject *pickregion;
Rt2dPath *path;
Rt2dCTMPush();
Rt2dCTMTranslate(WinBBox.w * 0.45f, WinBBox.h * 0.45f);

RenderWare Graphics 3.7

III-25

Chapter 30- 2D Graphics Toolkits

pickregion = Rt2dPickRegionCreate();
path = Rt2dPickRegionGetPath(pickregion);
Rt2dPathLock(path);
Rt2dPathRect(path, 0.4f,0.4f,0.4f, 0.4f);
Rt2dPathUnlock(path);
Rt2dObjectApplyCTM(pickregion);
Rt2dCTMPop();
}

Creating a Scene
Rt2dSceneCreate() creates a scene. By default the scene is locked.
MainScene = Rt2dSceneCreate();

Working with scenes is described in more detail in the next section.

30.3.3 Adding Objects to a Scene
Objects can be added to a scene using one of two methods:

Method 1
1. Rt2dSceneLock() locks the scene. Immediately after a scene has been
created, the scene is locked by default.
2. Create objects using Rt2dShapeCreate(), Rt2dPickRegionCreate(),
Rt2dObjectStringCreate() or Rt2dSceneCreate().
3. Rt2dSceneAddChild() adds Rt2dObjects to a scene. After a child
object has been added to a scene, the scene takes ownership of the
object.
4. Rt2dSceneGetChildCount() is used to obtain the child count.
5. Call Rt2dSceneUnlock() to unlock the scene.

Code Example
Rt2dSceneLock(MainScene);
Rt2dSceneAddChild(MainScene, shape);
Rt2dSceneUnlock(MainScene);
III-26

11 February 2004

2D Objects

/* shape may have moved during unlock */
shape = Rt2dSceneGetChildByIndex(MainScene, 0);
Rt2dObjectMTMSetIdentity(MainScene);

Method 2
1. Rt2dSceneLock() locks the scene. Immediately after the
scene has been created, the scene is locked.
2. Create objects using Rt2dSceneGetNewChildShape(),
Rt2dSceneGetNewChildPickRegion(),
Rt2dSceneGetNewChildObjectString() or
Rt2dSceneGetNewChildScene().
3. Rt2dSceneUnlock() to unlock the scene.

Code Example
{
Rt2dObject *zigzag;
Rt2dPath *path;
Rt2dBrush *strokeBrush;
Rt2dCTMPush();
Rt2dCTMTranslate(WinBBox.w * 0.3f, WinBBox.h * 0.3f);
Rt2dSceneLock(MainScene);
zigzag = Rt2dSceneGetNewChildShape(MainScene);
/* set path */
path = Rt2dPathCreate();
/* set brush */
strokeBrush = Rt2dBrushCreate();
Rt2dShapeAddNode(zigzag, path, NULL, strokeBrush);
Rt2dObjectApplyCTM(zigzag);
Rt2dObjectSetVisible(zigzag, TRUE);
Rt2dSceneUnlock(MainScene);
/* shape may have moved during unlock */
zigzag = Rt2dSceneGetChildByIndex(MainScene, 1);
Rt2dCTMPop();
RenderWare Graphics 3.7

III-27

Chapter 30- 2D Graphics Toolkits

}

30.3.4 Object Serialization
All objects can be streamed. Refer to Explicit Streaming Functions in the
Serialization chapter. All objects should be unlocked before streaming.
For shapes use:
•

Rt2dShapeStreamRead()

•

Rt2dShapeStreamWrite()

•

Rt2dShapeStreamGetSize()

For object strings use:
•

Rt2dObjectStringStreamRead()

•

Rt2dObjectStringStreamWrite()

•

Rt2dObjectStringStreamGetSize()

For pick regions use:
•

Rt2dPickRegionStreamRead()

•

Rt2dPickRegionStreamWrite()

•

Rt2dPickRegionStreamGetSize()

For scenes use:
•

Rt2dSceneStreamRead()

•

Rt2dSceneStreamWrite()

•

Rt2dSceneStreamGetSize()

30.3.5 Object Manipulation
Manipulating an Object in a Scene
To manipulate an object within a scene the following steps need to be
taken:

III-28

11 February 2004

2D Objects

1. Rt2dSceneUnlock() unlocks the scene. This is not necessary
but it is recommended.
2. Rt2dSceneGetChildByIndex() obtains a pointer to a particular object
or Rt2dSceneForAllChildren() obtains pointers to all objects.
3. Manipulate an object using these functions: Rt2dObjectMTMRotate(),
Rt2dObjectMTMScale(), Rt2dObjectMTMTranslate(),
Rt2dObjectSetColorMultiplier(), Rt2dObjectSetColorOffset(),
Rt2dObjectSetDepth(), Rt2dObjectSetVisible().
Object strings can be manipulated using
Rt2dObjectStringSetBrush(), Rt2dObjectStringSetFont(),
Rt2dObjectStringSetHeight() and Rt2dObjectStringSetText().
4. Rt2dObjectApplyCTM() copies the current transformation matrix
(CTM) to the object modeling transformation matrix (MTM). This is
necessary to apply camera changes i.e. changing the viewpoint.
5. Rt2dSceneUpdateLTM() updates the LTM because the scene MTM has
changed and may need to be recalculated for rendering. If the LTM does
not need updating, for example for collision detection, you can wait
until after rendering because the rendering functions update the LTM.
6. Rt2dSceneSetDepthDirty() tells the scene that the next time it
renders, that object depths may have changed. This function is required
if Rt2dObjectSetDepth() has been used to manipulate an object.

Code Example
Rt2dSceneUnlock(MainScene);
Rt2dSceneGetChildByIndex(MainScene , 2);
Rt2dObjectMTMScale(zigzag, 0.6f, 0.6f);
color.red =0.5f;
color.green = 1.0f;
color.blue= 0.5f;
color.alpha = 1.0f;
Rt2dObjectSetColorMultiplier(zigzag, &color);

Manipulating Objects not in a Scene
Objects that are not in a scene can be manipulated as above and using
Rt2dObjectCopy().

RenderWare Graphics 3.7

III-29

Chapter 30- 2D Graphics Toolkits

30.3.6 Object Rendering
All objects that have Rt2dObjectSetVisible(TRUE) can be rendered
individually or within a scene.
The rendering functions are as follows:
• Rt2dShapeRender()
• Rt2dObjectStringRender()
• Rt2dSceneRender()

30.3.7 Object Destruction
Objects can be destroyed in one of two ways depending on whether or not
they are part of a scene.
If the object is not part of a scene use the following functions to destroy the
object:
• Rt2dObjectStringDestroy()
• Rt2dPickRegionDestroy()
• Rt2dShapeDestroy()
If the object has been added to a scene the scene is the owner of the object.
In this instance use Rt2dSceneDestroy() to destroy the entire scene and
all child objects.

30.3.8 Objects
Object Type
The following functions can be used to determine what type an object is:
• Rt2dObjectGetObjectType()
• Rt2dObjectIsObjectString()
• Rt2dObjectIsPickRegion()
• Rt2dObjectIsScene()
• Rt2dObjectIsShape()

Matrix Functions
Matrices can be manipulated using the following functions:
III-30

11 February 2004

2D Objects

•

Rt2dObjectGetLTM() – return the world matrix

•

Rt2dObjectGetMTM() – return object matrix

•

Rt2dObjectMTMChanged() – updates the object when the MTM has
changed

•

Rt2dObjectSetMTM() – sets the MTM from an RwMatrix

Using Pick Regions
RtPickRegionIsPointIn() is used to test a 2d point against the pick
region. It returns TRUE if the point is inside the pick region or FALSE if not.
The 2d point should be passed using normalized screen coordinates.
For example:
2D point coordinate
0Æ1
È
1

RenderWare Graphics 3.7

Screen Coordinate
0Æ640
È
480

III-31

Chapter 30- 2D Graphics Toolkits

30.4 The Character Set Toolkit
The Character Set Toolkit (RtCharset) contains a simplified text output
API. The font is a mono-spaced font design which is embedded in the toolkit
library file and cannot be changed without access to the source code. The
Character Set Toolkit's primary purpose is for displaying run-time
debugging, testing and diagnostics messages.
The toolkit supports ASCII text strings exclusively. Unicode and other
multi-byte formats cannot be used.

30.4.1 Initialization
Before rendering any text strings, the Character Set Toolkit needs to be
initialized. This is performed through a call to RtCharsetCreate(), which
returns a pointer to an RtCharset object.
The parameters to RtCharsetCreate() allow the application to choose
foreground and background colors for the font, which is a single-color
bitmapped font. To redefine these colors later in your application, use
RtCharsetSetColors().

30.4.2 The Font Descriptor
The Character Set Toolkit can be rebuilt with different fonts, so source-code
licensees of RenderWare Graphics should not assume that the same font
will always be embedded in the toolkit binaries.
The API provides a method which can be used to determine the embedded
font's properties: RtCharsetGetDesc(). This function returns a pointer to
an RtCharsetDesc object, which contains the following elements,
describing the embedded font:
•

count – the number of characters in the set

•

height – the height, in pixels, of each character

•

tileheight – the height of the raster in characters

•

tilewidth – the width of the raster in characters

•

width – the width, in pixels, of each character

All are of type RwInt32.
As the font is always mono-spaced, this information can be used to
determine the screen area required for a rendered string.

III-32

11 February 2004

The Character Set Toolkit

30.4.3 Rendering
Two string-rendering functions are provided: RtCharsetPrint() and
RtCharsetPrintBuffered().
Both functions take the same parameters: a pointer to a valid RtCharset
object; a pointer to the text string itself, and the x and y coordinates of the
top-left corner of the string to be displayed on screen.
The buffered print function, RtCharsetPrintBuffered(), will not render
the string immediately. Instead, the output is buffered. This buffer should
be flushed by a call to RtCharsetBufferFlush() once the printing is
completed.
As the font rendering process uses immediate mode triangles, RtCharset
rendering functions must be placed between calls to
RwCameraBeginUpdate() and RwCameraEndUpdate().

30.4.4 Destroying the font
When the font, contained in the RtCharset object, is no longer required, it
must be destroyed with a call to RtCharsetDestroy().

RenderWare Graphics 3.7

III-33

Chapter 30- 2D Graphics Toolkits

30.5 Font File Formats
This section describes the three font formats supported by the 2D Toolkit's
.met ("metrics") files.
The metrics files must be in UTF-8 format. Unicode characters are encoded
using the UTF-8 format in the character code section.

30.5.1 "Metrics 1" (Bitmap)
A "Metrics 1" font is a bitmap font and requires a bitmap image. An optional
mask can be specified after the image file. The image and mask filenames
must not contain any spaces. The .met file is used to define the characters
available and their dimensions. The position values are the pixel
coordinates in the image.
The format of a "Metrics 1" file is as follows:
METRICS1
 []

    
    
...

A fragment of a Metrics 1 file is shown below. This fragment is taken from
the "cn12.met" file, which defines a 12-point "Courier New"-style font with
both a font bitmap ("cn12.bmp") and a mask ("mcn12.bmp").
METRICS1
cn12.bmp mcn12.bmp
5
32
0
0 10 18
33 11
0 21 18
34 22
0 32 18
35 33
0 43 18
…

#
#
#
#

' '
'!'
'"'
'#'

30.5.2 "Metrics 2" (Bitmap)
"Metrics 2" is also a bitmap font format requiring a bitmap image. An
optional mask can be specified after the image file. The image and mask
filenames must not contain any spaces.
The "Metrics 2" .met file only lists the characters available in the bitmap.
Each character's dimensions are encoded in the image font.

III-34

11 February 2004

Font File Formats

Each character in the image is surrounded by a boundary. This marks the
dimension of the character's bitmap. The start of a character's bitmap is
denoted by a marker pixel at the top left of each boundary. It is therefore
important that the color values of the marker pixel and the boundary are
not used elsewhere, otherwise the character will use an incorrect area of
the bitmap for the character.
The same marker pixel must also be present at the bottom left corner for
the first character's bitmap. This is used to determine the height of the font
set. Otherwise the font will not be loaded correctly.
The area used for the character’s bitmap is inset by 2 pixels from the four
boundaries. This is to prevent the boundary pixels from appearing when
displaying the character.
"Metrics 2" also supports multiple bitmaps for the font so a font can be
spread over more than one bitmap. This can be used to break up a large
image into smaller sections, or it can be used to support fonts that have a
large number of characters, such as Greek, Chinese or Japanese Kanji.
Up to four image bitmaps can be specified.
The format of a "Metrics 2" file is as follows:
METRICS2
 []


[] []
[]
[]

A fragment of a "Metrics 2" file is shown below. This fragment is taken from
the "illum.met" file, which defines a font which uses two bitmap/mask
pairs.
METRICS2
illum0.bmp illum0m.bmp
10
ABCDEFGHIJKLMNOPQRSTUVWXYZ
gold1.bmp gold1m.bmp
10
abcdefghijklmnopqrstuvwxy;z,.!:?- 0123456789

30.5.3 "Metrics 3" (Outline)
"Metrics 3" is an outline font format. Each character uses a series of 2D
vector commands to describe the geometric shape of the character.

RenderWare Graphics 3.7

III-35

Chapter 30- 2D Graphics Toolkits

Each font character begins with the character string. The geometric
description begins with the begin keyword and ends with end keyword.
There is no limit to number of 2D commands for the font. A final moveto
command is used to set the width of the character—the resulting location
being the position where the next character should begin.
The format of a "Metrics 3" file is:
METRICS3

''
begin
moveto  
lineto  
curveto      
closepath
moveto  
end

A fragment of one of the "Metrics 3" files is shown below. This fragment is
taken from the "ch.met" file, which defines an outline font.
Characters that are part of the ASCII standard, but which are not defined
in the font itself, should be defined with a single moveto instruction (as for
the '!' character in the example shown), rather than omitted entirely.
METRICS3
ch
' '
begin
moveto 0.999 0.0
end
'!'
begin
moveto 0.28 0.0
end
'"'
begin
moveto 0.09 0.215
lineto 0.115 0.175
lineto 0.14 0.125
lineto 0.16 0.075
lineto 0.185 0.015
lineto 0.205 -0.035
lineto 0.24 -0.085
lineto 0.275 -0.09
lineto 0.305 -0.075
lineto 0.32 -0.025
lineto 0.33 0.025
lineto 0.325 0.08
lineto 0.285 0.125
lineto 0.24 0.155
III-36

11 February 2004

Font File Formats

lineto 0.185 0.185
lineto 0.12 0.22
closepath
moveto 0.998 0.0
end

RenderWare Graphics 3.7

III-37

Chapter 30- 2D Graphics Toolkits

30.6 Summary
This chapter has covered both the 2D Toolkit and the Character Set Toolkit.

30.6.1 2D Toolkit
Uses the Rt2d object.

30.6.2 Key Points
•

Hardware-accelerated 2D graphics on supported platforms

•

Brushes define textures and colors

•

Paths are primitives which can be any combination of lines and Bezier
curves

•

Primitives are always rendered to a camera

•

A transformation matrix is required to render paths to device space

•

Bitmap and outline fonts are supported for both ASCII and multi-byte
character sets (including Unicode)

30.6.3 Paths & Brushes
•

Curves in brushes must be flattened before rendering

•

A brush is required to render a path

•

Paths can be stroked or filled

•

Stroking a path uses a brush to draw along the path, so a line is
produced

•

Filling a path creates a window in the shape of the path through which
the brush is seen

•

A brush can contain colors and/or a texture

•

Rendering a brush defined using multiple colors results in a gradient fill
effect

30.6.4 The Camera
The 2D Graphics Toolkit works by rendering to a camera (RwCamera) object.
The rendering functions must be placed between calls to
RwCameraBeginUpdate() and RwCameraEndUpdate()using the last camera
set for Rt2d operations via the Rt2dOpen() or Rt2dDeviceSetCamera().
III-38

11 February 2004

Summary

30.6.5 Current Transformation Matrix
•

The 2D Toolkit uses a transformation matrix stack to convert its 2D
vertices from local (object) space to device space.

•

The top-most matrix on this stack is called the current transformation
matrix (CTM).

•

The CTM is used for all 2D Toolkit rendering

30.6.6 Fonts
•

Two bitmap font formats are supported: "Metrics 1" & "Metrics 2"

•

One outline font format is supported: "Metrics 3"

•

Text strings are rendered inside bounding boxes

•

Text can be rendered justified left, right or centered

30.6.7 Rt2dObjects
This section explained what objects are and how they can be created and
used.
There are four objects:
1. Shapes
2. Object Strings
3. Pick Regions
4. Scenes
These objects can be manipulated, rendered and destroyed individually or
as part of a scene.

30.6.8 Character Set Toolkit
Key Points
•

The Character Set Toolkit (RtCharset) is primarily intended for
debugging and diagnostics use.

•

It is fast, but inflexible and only supports ASCII text.

•

The font used by RtCharset is embedded within the library and cannot
be changed.

RenderWare Graphics 3.7

III-39

Chapter 31
Maestro

Chapter 31- Maestro

31.1 Introduction
31.1.1 Maestro Overview
Maestro is a collection of components that can be used for the design and
playback of 2D user interfaces in games. The user interface is typically
designed using Macromedia Flash. Published swf files can be processed
into a form suitable for run-time playback in RenderWare Graphics.
Examples of Maestro's usage include menu systems and screens for
navigation, system setup and character selection.
Maestro is not a Flash or swf player. Flash is used as an authoring route
for 2D user interfaces. This is similar to the 3ds max and Maya exporters,
which do not support all features of 3ds max and Maya.
Maestro-related components include the following, which are shown
diagrammatically on the next page.
•

2dconvrt
a command-line tool that is used to convert swf animations into a
format that can be read by RenderWare Graphics

•

Rt2d
a toolkit that implements low-level 2d functions

•

Rt2dAnim
a toolkit that extends the functions of the Rt2d toolkit to include
animations. It contains an object called Rt2dMaestro. This object
coordinates playback of the 2d animations, and could be considered the
nerve center of the Maestro components.

•

2dviewer
a viewer, to play Maestro animations. Can be used for testing exported
.anm files. Code is provided, and demonstrates how to play back .anm
files.

✎

By convention, assets used by the Maestro player have an .anm file extension

•

maestro1
an example demonstrating the use of Maestro to playback a user
interface authored in Flash.

The Flash features that Maestro supports are those that are implemented
in the Rt2d and Rt2dAnim toolkits. The 2dconvrt tool strips out all features
of the swf file that cannot be supported at run-time.
III-42

11 February 2004

Introduction

As a simple example, the 2d toolkits do not support sound. Any sound
effects that are stored in the swf file are not reproduced by the run-time
components of Maestro. Sound effects can still be triggered; they just aren't
imported using the Maestro file format.

Flash
Publish
Maestro Components
2dconvert
swf
file
anm
file

Rt2dMaestro

Rt2dAnim
Rt2d

RenderWare Core and World

When an animation is created and saved in Flash an fla file is produced.
To be able to use the fla file in RenderWare Graphics the following steps
need to be followed:
1. Publish the fla file. This creates a swf file.
2. Convert the swf file to an anm file.
3. Read in and playback the anm file in RenderWare Graphics.
Regarding multiple platform development, ideally the same .fla and .swf files should be
used.

✎

Sequencing of user interfaces for console games is much more restrictive than for PCs due
to the lack of a mouse. It is advisable to author the Flash animation as if it were intended
for a console. This dictates the control flow and layout of the animation.
After a console-compatible interface has been completed, a PC overlay can be constructed
for each screen.
The PC-based Flash content will not, in general, resemble an ordinary PC Flash
production. This is due to the need to remain platform independent at the sequencing
level.

RenderWare Graphics 3.7

III-43

Chapter 31- Maestro

31.1.2 This document
This document consists of six sections.
It is aimed at both artists and programmers. Artists should read sections
31.1, 31.2 and 31.3. Programmers should read the entire document.
The first section is this; the introduction.
The second section lists those features of Flash that are supported in
RenderWare Graphics and those that are not.
The third describes the content generation and publishing process. User
interface design for Maestro is detailed.
The fourth shows how to import content and view it using RenderWare
Graphics.
The fifth five describes the playback mechanism, specifically what hooks
exist for the developer. Topics include how to get information to and from
the player while it is playing.
The last section summarizes the major topics.

31.1.3 Other Resources
API Reference
−

Rt2d toolkit

−

Rt2dAnim toolkit

•

2d Graphics Toolkit Chapter in the User Guide

•

2dconvrt tool documentation, in docs\tools\2dconverter.pdf.

•

2dviewer viewer

•

maestro1 example, a brief description of which is in section

31.1.4 Using the maestro1 Example
The maestro1 example is accessed from the Windows Start Menu, under
ProgramsÆRenderWareÆGraphics ÆSDKÆExamples.
Double-click on the maestro1 folder, then run either the
maestro1_d3d8.exe, maestro1_d3d9.exe or the maestro1_opengl.exe
executable.
The following dialogue should show:

III-44

11 February 2004

Introduction

Click OK, and the example will start with the following:

At this point, the example will respond to keypresses such as ENTER,
BACKSPACE and the arrow keys. ENTER corresponds to SELECT and
backspace to CANCEL on a console.
Pressing ENTER on this screen will take you into the main part of the
example.

RenderWare Graphics 3.7

III-45

Chapter 31- Maestro

31.2 Flash and RenderWare Graphics
The Flash-to-.ANM converter has been designed to support Flash 3. This
limits the actions that can be performed from a later version of Flash.
We chose the Flash 3 version because it closely matches the features that
Maestro supports. If you use a more recent version of the Flash authoring
application, then you must export the swf using the Flash 3 file format.
The range of supported and unsupported features is primarily due to the
feature set of the Rt2d and Rt2dAnim toolkits. The conversion process from
swf to the RenderWare Graphics format ignores those effects that the
toolkits cannot support.

31.2.1 Supported Features
The supported features in the Flash importer are:
•

Bitmap fills in .png format.
Power-of-2 height and width bitmaps should be used for bitmap fills, for example 256*256
or 128*512. Most modern hardware requires this. Within Maestro non-power-of-2 sized
bitmaps are resampled. It's better for the artist to resize their textures rather than let it
happen automatically.

✎
•

Static 2D vector-based content
−

Line styles

−

Solid fill styles

−

Curved paths

−

Alpha transparency

−

Basic text strings

The best results are obtained through converting vector-based artwork to small
bitmapped artwork.

✎

III-46

Vector-based artwork is supported in order to make it easy to import initial artwork
roughs. Artwork of this form will load and run less efficiently than bitmap-based artwork.
Since vector-based art can consume large amounts of memory, it's recommended that you
measure this early in the UI creation process and make sure you have the memory budget
for it.

•

Mapping of RenderWare Graphics fonts to Flash fonts.

•

Animations on static content

•

Utilization of 3D hardware to accelerate rendering

•

Z-ordering / layering

•

User interactivity including buttons

11 February 2004

Flash and RenderWare Graphics

•

✎

A subset of Flash 3 actions including ActionGoToLabel,
ActionSetTarget (non-relative), ActionGotoFrame, ActionGetURL,
ActionNextFrame, ActionPreviousFrame, ActionPlay, ActionStop.
Inside Maestro there are corresponding messages that may be intercepted by developer
code. See section 31.5.4.

•

Actions may be triggered as frame actions or on button transitions

•

Button export linkage is utilized. This allows console controller button
pushes to trigger the actions associated with a Flash button. See
section 31.5.6 for details.

•

Comprehensive import tool, allowing extraction of data ranging from
simple static objects to complex interactive content

31.2.2 Unsupported Features
The unsupported features in the Flash importer are listed below. Where
possible, workarounds are detailed.
•

Flash 4.0 and Flash 5.0 specific features.

•

ActionScript introduced in Flash 4.0. Replace this with code written in
C. This may be triggered from Flash the "GetURL" trigger mechanism.
See section 31.5.4.

•

Gradient and radial fills. Bitmap fills can be used to approximate a
gradient. Bitmaps may be stretched, so small bitmaps will work.

•

Clipping layers.

•

Movies within buttons. A separate movie clip can be triggered by a
transparent (yet active) button. This applies to the MouseOver state, so
movies cannot be played in the button when a mouse hovers over the
button.

•

Relative targets in buttons. The only relative target supported is the
direct parent of a sprite.

•

Bitmap fills in .jpg or .jpeg format. Store in lossless format once in
Flash. To do this:

•

-

From the menu bar, select WindowÆLibrary.

-

Right click the image's name to access the context menu

-

Choose properties from the menu

-

For "Compression", choose "Lossless"

Sounds. "GetURL" triggers can be used to synchronize sound events.

RenderWare Graphics 3.7

III-47

Chapter 31- Maestro

•

Flash native and TrueType fonts. Use the fontalias.txt file to setup
RenderWare Graphics font aliases.

•

Slanting transforms on text is not supported in RenderWare Graphics.

•

Morph shapes. Break up the morph into individual positioning
keyframes. Consider using the Rt2dAnim interpolation feature (see
Rt2dAnim API reference) to make animations play exceptionally
smoothly.

•

Objects with non-edge-touching holes. A common practice in Flash is to
create a "frame" with a cutout in the center. Because 2D shapes are
plotted as large, continuous areas in RenderWare Graphics, these
regions are opaque. Break the object into two separate objects in
different layers, and it will plot correctly.
Background

•

III-48

Background

Complex concave curved regions. Usually these will render correctly,
but in a few cases there will be minor overfill errors. Splitting up the
curves that form the edges of the concave regions should help alleviate
this.

11 February 2004

Creating 2D Content for Use Within RenderWare Graphics

31.3 Creating 2D Content for Use Within
RenderWare Graphics
This section describes:
•

publishing a Flash fla file to a Flash swf file

•

elements of a user interface

•

creating and using a virtual controller in order to test the user interface
as it would be navigated on the console

•

use of naming conventions to simplify development

Additionally, the maestro1 example demonstrates a user interface in
action. Appendix I shows some of the sequencing planning that was carried
out for maestro1.

31.3.1 Publishing an SWF
Flash fla files need to be published as swfs to be imported into
RenderWare Graphics. To convert an fla to a swf file the fla file needs to
be published in the Flash 3 format.
RenderWare Graphics supports a subset of Flash 3. In Flash 5, Publish
Settings can be changed and set to Flash 3 and any options that are not
supported in Flash 3 are highlighted.
To ensure that when you are creating something in Flash you are only
using Flash 3 functionality, in Flash setup the following:
File Æ Publish Settings Æ Flash tab
Ensure that Version is set to Flash 3.

RenderWare Graphics 3.7

III-49

Chapter 31- Maestro

Every time the movie is run only the object window will appear stating if
any non-Flash 3 actions have been used.

Publishing
The swf can be published in two ways:
1. File Æ Publish Settings Æ Flash tab click on Publish
2. File Æ Publish

31.3.2 Elements of a User Interface
The following Flash elements may be useful in creating a user interface:

III-50

•

symbols

•

buttons

•

movie clips

•

labeling

•

actions

•

graphics

•

text

•

naming conventions

11 February 2004

Creating 2D Content for Use Within RenderWare Graphics

Symbols
It's convenient to set up most items in Flash Movies as symbols. This
makes editing easier, especially when a symbol is repeatedly used.
If an identical piece of text is used in multiple scenes, a symbol containing
that text could be defined. Updating that symbol would update the text in
all the places where that symbol is used.

✎

Symbol names aren't saved in .swf files, and consequently are inaccessible from code.

Buttons
IMPORTANT: Most consoles have no mouse. The design of most Maestrobased user interfaces must take this into account. They cannot be authored
in exactly the same way as web-based user interfaces, since there is no
concept of a mouse position and active button.
Buttons are used to put together a 'virtual controller' that may be used to
simulate a console controller. The buttons' purpose is to serve as
placeholders for Flash actions that will be assigned to them during content
creation. This is described in section 31.3.3.
It is common in Maestro to author buttons with just a hit state, so that
they do not appear. Images of different button states should be dependant
on the current movie frame, rather than on a mouse-dependant button
state.
Unless you are developing for a platform with a mouse, the only button
events that are useful to assign actions to are 'press' and 'release'.
Buttons created must also have linkage properties set. The linkage
properties are used when the buttons are exported from Flash and then
imported into RenderWare Graphics.

✎

Programs using Maestro animations will need to refer to buttons by names. See section
31.5.6 to see why. The linkage properties can be used to make the button names get
exported.

To assign an identifier string to a button:
Select the button symbol in the Library.
Right click the symbol name and choose Linkage
Select Export this symbol and enter an identifier string.

RenderWare Graphics 3.7

III-51

Chapter 31- Maestro

Movie Clips
Movie clips are animations that play inside other animations. They can be
played within the main animation or other movie clips. They may contain
any of the Flash elements detailed in this section.
Movie clips can be used to put together simple animation sequences. These
may then be placed as a single objects within larger animations. This
simplifies the design of the larger animation by breaking it up into parts.
Although movie clips are usually animated, they can be 'stopped' so that
they stay on a particular frame.
This makes them useful to implement user interface aspects such as slider
positions or displayed control states.
For the programmer, movie clips correspond loosely to Rt2dAnims with additional features
like actions, frame labels and buttons.
Movie clip instance names are exported, which means that specific movies can be looked
up in code. See the section on string labels (31.5.3) for information on how to do this.
Since movie clip names are exported and symbol names are not, movie clips are actually
the only way of naming graphics so they can be found in code.

✎

Possible uses of movie clips:
•

looking up the current frame of the movie. You could use this method to get a slider
position. The maestro1 example uses this method on the player name edit screen.

•

locating an object so that you can change its displayed position in code

•

locating an object so that you can look up and change a texture

•

locating a text string so that you can modify it in code. You can also do this by
traversing the main scene tree, as is done in the maestro1 example to find some
marker text.

Labeling
Movie clips need to be meticulously labeled. The instance labels are used
when actions are created for the select buttons to run movie clips. Labeling
movie clips allows them to be controlled with Flash actions from other
movie clips.

✎
III-52

Labels are accessible from within RenderWare Graphics. See section 31.5.3.

11 February 2004

Creating 2D Content for Use Within RenderWare Graphics

Individual frames may be labeled within movie clips. Actions may be used
to make playback jump to a new frame.

Actions
With the publish settings set to Flash 3 (see Publishing an SWF), Flash
displays illegal actions in yellow. Available actions remain unshaded. All
the "Basic Actions" are available, and a limited number of "Actions".
Actions can be triggered by a particular frame of an animation being
played, or by a button transition such as 'on (press)' or 'on (release)'.
Actions that are useful are 'Go To', 'Play', 'Stop', 'Get URL', 'Tell Target', 'On
Mouse Event' and 'GetURL'. The other actions are not exported, and so are
ignored.

✎

GetURL is particularly important, as it provides a way of triggering actions in the calling
program. See the maestro1 example and section 31.5.4.

RenderWare Graphics 3.7

III-53

Chapter 31- Maestro

unavailable

Graphics
Bitmap fills are very effective in space and speed.
If the .swf will be used on multiple platforms, it may not be possible to get
a one to one relationship between the bitmap and screen. Using a higher
resolution than is strictly required may help.
When objects will be resized through animation, vector artwork will be
better. Artwork in this form is size independent.
The downside of vector artwork is that it can become inefficient without
appearing that way in Flash.
A common practice in Flash is to convert a bitmap to vector art. This is
definitely something to avoid for Maestro, as such an object will be much
less efficient to store and render.

Text
Text may be added with Flash's text tool. Some care must be taken in
choosing fonts, as these will have to be imported into RenderWare Graphics
in order to display correctly.

✎
III-54

For programmers, the 2dconvrt utility has the ability to map fonts within Flash to fonts
within RenderWare Graphics. Consult the 2dconvrt documentation for more information.

11 February 2004

Creating 2D Content for Use Within RenderWare Graphics

Naming Conventions
For convenience and clarity, it is useful to adopt a naming standard for
Flash objects. It may not be apparent from the name what kind of object is
being referred to.
Prefixing a name with an indication of the object type makes it easier to
work with Flash files through the whole content creation and import
process.
Appendix II contains suggested naming conventions.

✎

Programmers are invited to consider this analogous to file extensions, but not Hungarian
notation

31.3.3 Virtual Controllers and Console Artwork
IMPORTANT: Most consoles have no mouse. The design of most Maestrobased user interfaces must take this into account.
Due to the lack of a mouse pointer, buttons that react to mouse clicks
cannot be used on consoles. Images or animations displaying button
pictures may be used, but usually they won't be Flash buttons.
To provide a place-holder for user input, a virtual controller must be used
during content creation (see figure below). This virtual controller serves as a
mock-up of the console's control pad. It has duplicate versions of the
controller direction buttons (up, down, left right) and also the select and
cancel buttons.

virtual controller
(only appears in .swf,
not in exported
interface)
Buttons

Having the virtual controller present during development allows actions to be
assigned to button pushes. For example "select" pressed on Frame1 with
'options' highlighted could have actions to take the player to Frame10 with
'Options Menu' displaying.
RenderWare Graphics 3.7

III-55

Chapter 31- Maestro

Content created for Maestro will have 'controls' displayed as 'active' on
separate frames in preference to controls that react to mouse-overs and
mouse button pushes.
The virtual controller graphics will not be exported for the production
version of your artwork, but its button actions will be. The button actions
may be directly forced from within code, as described in section 1.4.
The other button images present in this figure ("new game", "load game",
"options") are not Flash buttons; they are ordinary graphics and
animations.

III-56

11 February 2004

Importing Flash Files into RenderWare Graphics

31.4 Importing Flash Files into
RenderWare Graphics
Once a Flash file has been published to a .swf file, this .swf must be
converted into a form ready for use inside RenderWare Graphics.
The conversion is performed by a command-line tool, 2dconvrt. The result
of conversion is a RenderWare Graphics .anm file, which may be played
back inside a program or by using the 2dviewer program.
This section is aimed at programmers, and describes
•

converting a Flash swf file to a RenderWare Graphics anm file

• viewing a RenderWare Graphics anm file with the 2dviewer program

31.4.1 Importing the SWF into RenderWare
Graphics
Flash swfs are converted to anms using the 2dconvrt tool.
The 2dconvrt tool is described in detail in the 2dconvrt tool documentation.

Using the 2dconvrt Tool
The 2dconvrt tool converts swfs to anms. anms can be played back and
manipulated within RenderWare Graphics.
The 2dconvrt tool is a command line tool; it has no graphical user
interface.
By default, 2dconvrt exports bitmaps and an anm file containing all scenes,
animations and user interactivity information needed to play the Flash
animation.

Converting an SWF
Using the commands described in the 2dconvrt documentation, .swfs
may be converted as follows at the command line:
• Type 2dconvrt .swf
This creates an anm file, .anm

RenderWare Graphics 3.7

III-57

Chapter 31- Maestro

31.4.2 2d Viewer
As with the 3D parts of RenderWare Graphics, we supply a simple viewer to
allow the converted anm file to be easily viewed. Both a platform specific and
Win32 version of the viewer are provided in the SDK. The source code to
this application is also included.
To display the anm file in RenderWare Graphics:
1. Run the 2dviewer tool.
2. Click and drag the anm file onto the 2dviewer.

2dviewer with default animation, swirly.anm

III-58

11 February 2004

Developing With Maestro

31.5 Developing With Maestro
This section details how to develop with Maestro.
Streaming and playback of a Maestro animation is described.
Also described are methods of getting information into and out of Maestro
while it's playing an animation. This can be handy for linking up
controllers, or reacting to events within the animation.
Maestro provides efficient and convenient means of getting handles to
internal data by name.
Finally, use of mouse inputs is described. This is useful in the event that
you're authoring interfaces for the PC.

31.5.1 Introduction
The Maestro API consists of streaming, time update and rendering
functions.
Also exposed is a callback-based message-passing mechanism, by which
events internal to the Flash animation can be passed back to the calling
code. A custom message handler may be chained before the default
message handler. This allows user code to be notified of events internal to
the animation.
The user may also post external events into the animation via the message
passing interface. Rt2dMessage structures can be passed to Maestro to
make Maestro do actions that weren't specified in the Flash file.
Rt2dMessages can also be intercepted by hooking a custom message
handler. In this manner messages can be examined as they flow through
the message processing handler.
Once Flash content has been created and loaded for playback inside
Maestro, the problem arises as to how to link up code to elements that were
authored in the Flash environment. For example, if an animation called
"/imcSubAnim1/Slider1/" exists in the Flash file, how can the current
frame of that animation be determined?
In order to address this issue and others, it's possible to access many Flash
elements by name in the exported .anm file. This is implemented through
the use of a string label table, which allows the lookup of names that were
exported from Flash. The various Rt2dStringLabel functions allow access
to this data.
This section describes how to use those parts of the Rt2dAnim library that
pertain to Rt2dMaestro.

RenderWare Graphics 3.7

III-59

Chapter 31- Maestro

All of the 2D animation APIs build on the hierarchical scene functionality
provided in the Rt2d toolkit. See the 2D Graphics Toolkit user guide
chapter, and Rt2d and Rt2dAnim sections in the API reference for more
information.
Because Maestro has no memory, virtual keyboards, toggles and sliders
require some code support. In most cases this is in order to get information
out of the animation, for example the fact that a slider has moved. At other
times, it may be desirable to externally set the position of a slider on entry
to the screen displaying that slider.
As a rule, it's easier to author the navigation from inside Flash, rather than
try to write C/C++ code that mimics the navigation of a menu system.

31.5.2 Playback of an ANM file in RenderWare
Graphics
The Rt2dAnim toolkit contains Rt2dMaestro functions to playback an anm
file in RenderWare Graphics.
Before any Rt2dMaestro functions may be called, the Rt2dAnim toolkit
must be opened with the Rt2dAnimOpen function. On shutdown, after all
Maestro objects have been destroyed, Rt2dAnimClose must be called.
Rt2dMaestro controls the sequencing of 2D animation with user
interaction. Rt2dMaestro contains a scene. A scene holds 2D objects that
can be manipulated.
The following Rt2dMaestro functionality is discussed::
1. Serialization of the maestro and the maestro scene
2. Positioning the maestro scene on the display
3. Applying time updates
4. Message handling
5. Rendering
6. Destroying the maestro

Serialization
It is assumed that a Maestro animation will be provided from an external
source such as the 2d conversion tool 2dconvrt. Once a Maestro animation
is available in a .anm file, it may be streamed in as per standard
RenderWare Graphics practice.

III-60

11 February 2004

Developing With Maestro

Care should be taken to ensure that the font and texture paths have been
set correctly prior to streaming in the Rt2dMaestro. Note that particular
font or textures may be required by the animation, but may not be in the
same directory as the animation itself.
The following code streams in an animation, assuming that the font and
texture paths have been set beforehand:
RwStream *stream = NULL;
Rt2dMaestro *maestro = NULL;
stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD,
);
if( !stream )
{
return (Rt2dMaestro *)NULL;
}
if (!RwStreamFindChunk(stream, rwID_2DMAESTRO,
(RwUInt32 *)NULL, (RwUInt32 *)NULL)
{
return (Rt2dMaestro *)NULL;
}
maestro = Rt2dMaestroStreamRead(NULL,stream);
return maestro;

Positioning Maestro Rendering on the Display
The maestro scene needs to be positioned on the display. In the example
below the scale and translations needed to position the Maestro have been
chosen in advance. You will need to determine values that work with your
user interface.
Rt2dObject *MaestroScene = Rt2dMaestroGetScene(Maestro);
Rt2dObjectMTMScale(MaestroScene, 0.002f, 0.002f);
Rt2dObjectMTMTranslate(MaestroScene, 100.0f, 100.0f);

✎

The maestro1 example demonstrates another way this could be done.

Maestro builds on top of the Rt2d library. The standard
Rt2dCTM library functions can also be used to position
Maestro's displayed output.

RenderWare Graphics 3.7

III-61

Chapter 31- Maestro

Applying Time Updates
During playback, it is necessary to inform Maestro that time is passing.
Fast paging through animations can be carried out without having to
update the scene.
The next step is to instruct Maestro to update the scene that will be
rendered.
If the state of a scene is required before rendering (e.g. for collision
detection), it can be examined after this scene update step.
/* Inform the Maestro how much time has passed */
Rt2dMaestroAddDeltaTime(, );
/* Cause the Maestro to apply any updates to the scene it
* controls. This does not update the LTM of the scene
* controlled by the Maestro. If collision detection was to
* be performed prior to rendering, Rt2dSceneUpdateLTM would
* have to be called first on the scene obtained from
* Rt2dMaestroGetScene
*/
Rt2dMaestroUpdateAnimations();

Message Handling
Maestro's way of communicating with calling code is through a messaging
interface. Messages may be passed to and from Maestro.
Maestro may generate messages during the time-update phase in the
course of doing an Rt2dMaestroAddDeltaTime.
Maestro can be provided with a custom message handler
Rt2dMaestroSetMessageHandler in order to intercept these messages.
Message may also be sent to Maestro with the Rt2dMaestroPostMessage
API. They won't be processed until Rt2dMaestroProcessMessage is called.
Section 31.5.4 describes this process in detail, as does the Rt2dAnim toolkit
API reference.

Rendering
Once the positions of the displayed objects have been updated in Maestro's
scene, that scene may now be rendered.
/* If changes to the viewpoint are made externally, the base
* level of the scene must be updated. This is common in
* most of the examples, which may be rotated, zoomed in etc
*/
if(  )
{
III-62

11 February 2004

Developing With Maestro

Rt2dObject *MaestroScene =
Rt2dMaestroGetScene();
Rt2dObjectMTMChanged(MaestroScene);
 = FALSE;
}
/* Draw the scene controlled by the maestro */
Rt2dMaestroRender();

Destruction
The maestro is destroyed by:
Rt2dMaestroDestroy(Maestro);

The maestro scene is also destroyed as the maestro owns the scene.

31.5.3 String Labels
Rt2dStringLabel is a string reference structure that is used by
Rt2dMaestro to allow linking of internal and external data by name
without a performance hit.
Rt2dMaestro stores a table of string labels. When an Rt2dMaestro is
created or streamed in, the string label table is populated. The calling
function can then look up names of interest within the table. The index that
indicates where the name was found can be used as a handle to identify
that name.

✎

The strings appear in the .anm file. You can check that the names have exported using
any hex editor or VisualStudio.

Additionally, an identifier is stored within the table to note what kind of
data is being referenced by the name. The user may store additional data in
the table against each name. This provides a convenient location to place
callbacks or flag locations. This would then be used by a custom message
handler hooked to the Rt2dMaestro.

Rt2dStringLabel entity types
A string label may label one of several different entity types within the
Rt2dMaestro. When searching for a particular string label, an entity type
can be provided by the programmer. Allowed entity types are

RenderWare Graphics 3.7

rt2dANIMLABELTYPEANIM

Animation label

rt2dANIMLABELTYPEFRAME

Frame label

rt2dANIMLABELTYPEBUTTON

Button label

rt2dANIMLABELTYPEURL

URL label; used for extensions
III-63

Chapter 31- Maestro

rt2dANIMLABELTYPEURL is the type used for a Rt2dStringLabel exported
for a "GetURL" action in the Flash generated content. It is handy in the
representation of user-defined named triggers.
Usually the text contained within a string label is the same as that listed in
the Flash editor.
Animation instance names, denoted by rt2dANIMLABELTYPEANIM, are a
special case. Flash movie clips can be contained within other movie clips,
giving rise to a 'tree' of named animations.
Animation instance names may be set via the 'Instance' panel within Flash.
They are similar in operation to directory names.
The names get exported in their fully qualified form. The "/" character is
used as a separator. Leading and trailing separators are added
automatically. Examples are shown in the table below.
ANIMATION LABEL

DESCRIPTION

/
/imcSubMovie1/
/imcSubMovie1/imcSlider1/
/imcSubMovie1/imcOnOff1/
/imcSubMovie2/
/imcSubMovie2/imcSlider1/

main animation
sub animation of main animation
animation within the first sub animation
animation within the first sub animation
sub animation of main animation
animation within the second sub
animation

Using Rt2dStringLabel access functions
The Rt2dMaestroFindStringLabel function may be used to locate a string
label stored in the string label table inside an Rt2dMaestro.
Rt2dStringLabel *label;
RwInt32 index;
label = Rt2dMaestroFindStringLabel(
, rt2dANIMLABELTYPEURL, "startGameTrigger",
&index");

The index that's returned is the index of the string label within Maestro's
internal string label table. This index is stored as one of the integer
parameters for several Maestro messages (see the Rt2dAnim API reference
for details).
A custom message handler that watches messages passing through the
system can look at the parameters of these messages. Some messages use
a string label index as a parameter, for example rt2dMESSAGETYPEPLAY
Once the string label has been located, its properties can be modified
directly through the pointer returned,
/* Store some user data */
Rt2dStringLabelSetUserData(

Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.3
Linearized                      : Yes
Producer                        : Acrobat Distiller 4.05 for Windows
Creator                         : Microsoft Word 9.0
Modify Date                     : 2004:02:11 08:43:48Z
Author                          : Catherine Hislam
Title                           : .
Create Date                     : 2004:02:11 08:43:32
Page Count                      : 181
Page Mode                       : UseOutlines
EXIF Metadata provided by EXIF.tools

Navigation menu