Difference between revisions of "API"
Line 88: | Line 88: | ||
: abi_CMD_G2D_END() and [[API#abi_CMD_G2D_BEGIN_BITMAP|abi_CMD_G2D_BEGIN_BITMAP]]/[[API#abi_CMD_G2D_BEGIN_DISPLAY|abi_CMD_G2D_BEGIN_DISPLAY]] delimits the group of layers to be blended. After abi_CMD_G2D_END call final blending will be initiated and results will be stored according to the begin comand. | : abi_CMD_G2D_END() and [[API#abi_CMD_G2D_BEGIN_BITMAP|abi_CMD_G2D_BEGIN_BITMAP]]/[[API#abi_CMD_G2D_BEGIN_DISPLAY|abi_CMD_G2D_BEGIN_DISPLAY]] delimits the group of layers to be blended. After abi_CMD_G2D_END call final blending will be initiated and results will be stored according to the begin comand. | ||
+ | =====Examples===== | ||
+ | 1. Render into inner G2D resource buffer #face and display it on the display #face. Please, note that last argument of abi_CMD_BITMAP is a `true` flag, which means G2D resource should be used: | ||
+ | ... | ||
+ | abi_CMD_G2D_BEGIN_BITMAP(face, 240, 240, true); | ||
+ | abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize0, 120 - animationSquareSize0, animationSquareSize0 * 2, animationSquareSize0 * 2, 0xdfff0000); | ||
+ | abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize1, 120 - animationSquareSize1, animationSquareSize1 * 2, animationSquareSize1 * 2, 0xdfffff00); | ||
+ | abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize2, 120 - animationSquareSize2, animationSquareSize2 * 2, animationSquareSize2 * 2, 0xdfff00ff); | ||
+ | abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize3, 120 - animationSquareSize3, animationSquareSize3 * 2, animationSquareSize3 * 2, 0xdf00ffff); | ||
+ | abi_CMD_G2D_ADD_SPRITE(resID, false, 120, 120, animationAlpha, 0x00000000, animationAngle, MIRROR_BLANK); | ||
+ | abi_CMD_G2D_END(); | ||
+ | ... | ||
+ | abi_CMD_BITMAP(face, 120, 120, 0, MIRROR_BLANK, true); | ||
+ | ... | ||
+ | abi_CMD_REDRAW(face); | ||
+ | ... | ||
+ | 2. Render directly into display framebuffer #face. This will produce same result on display as example #1, but the generated image is not saved: | ||
+ | ... | ||
+ | abi_CMD_G2D_BEGIN_DISPLAY(face, true); | ||
+ | abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize0, 120 - animationSquareSize0, animationSquareSize0 * 2, animationSquareSize0 * 2, 0xdfff0000); | ||
+ | abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize1, 120 - animationSquareSize1, animationSquareSize1 * 2, animationSquareSize1 * 2, 0xdfffff00); | ||
+ | abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize2, 120 - animationSquareSize2, animationSquareSize2 * 2, animationSquareSize2 * 2, 0xdfff00ff); | ||
+ | abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize3, 120 - animationSquareSize3, animationSquareSize3 * 2, animationSquareSize3 * 2, 0xdf00ffff); | ||
+ | abi_CMD_G2D_ADD_SPRITE(resID, false, 120, 120, animationAlpha, 0x00000000, animationAngle, MIRROR_BLANK); | ||
+ | abi_CMD_G2D_END(); | ||
+ | ... | ||
====Font drawing functions==== | ====Font drawing functions==== |
Revision as of 00:13, 10 September 2020
Introduction
The main functions of the API are listed here, the features of the work of the environment are described
WOWCube Paradigms
WOWCube executes 8 copies of the byte-code of the script at the same time, providing functions for the interaction of scripts with each other, drawing functions, functions for accessing resources, and other specific functions. Each copy of the script has access to 3 displays. Resource scripts are packed into a package.
Pawn API
Graphic functions
Graphics 2D acceleration (G2D)
WOWCube provides the 2D acceleration interfaces to enhance gaming experience . Basically G2D engine allows to blend up to the 4 image layers at once with a HW acceleration. However there is no limit of layers, they are blended in a cascade. For example, if Pawn script requested 7 layers to be blended then 2 HW blending will occur:
Result of the blending can be saved as an internal G2D resource or flushed immediately on the specified display. Internal G2D resources can be used as an usual bitmap primitive (abi_CMD_BITMAP) or reused as an input for the next G2D action. Basic coordinate principle:
Coordinates are limited from -2048 to 2047. Maximum layers size is 240x240.
abi_CMD_G2D_BEGIN_BITMAP
Syntax:
abi_CMD_G2D_BEGIN_BITMAP(const resID, const width, const height, const bool:replace)
Description:
- abi_CMD_G2D_BEGIN_BITMAP and abi_CMD_G2D_END delimits the group of layers to be blended into internal G2D resource. This API is not intended for frequent usage. It is better suited for complex background generation on game initialization or dynamic resource modification triggered by rare game events.
Arguments:
- resID
- ID of the resource that will be generated from blending layers presented between abi_CMD_G2D_BEGIN_BITMAP and the subsequent abi_CMD_G2D_END. G2D engine can keep up to 3 different resources with IDs: 0, 1 and 2.
- width
- Width of the resulting resource. G2D engine can keep resource of 240px width maximum.
- height
- Height of the resulting resource. G2D engine can keep resource of 240px height maximum.
- replace
- If true, then an existing image will be replaced completely, otherwise it will be overwritten by reusing itself as a background layer.
abi_CMD_G2D_BEGIN_DISPLAY
Syntax:
abi_CMD_G2D_BEGIN_DISPLAY(const display, const bool:replace)
Description:
- abi_CMD_G2D_BEGIN_DISPLAY and abi_CMD_G2D_END delimits the group of layers to be blended directly into display framebuffer. Obviously this API is designed for rendering scene on game tick. This API is not limited by layers count as well as abi_CMD_G2D_BEGIN_BITMAP. However it is strictly recommended to blend no more than 4 layers. Otherwise cascade blending will be initiated resulting in some FPS drop.
Arguments:
- display
- ID of the display which framebuffer will be used for blending. Each module have 3 displays with ID starting from 0.
- replace
- If true then an existing image will be replaced completely, otherwise it will be overwritten by reusing itself as a background layer.
abi_CMD_G2D_ADD_SPRITE
Syntax:
abi_CMD_G2D_ADD_SPRITE(const resID, const bool:g2d, const x, const y, const alpha, const color, const rotation, const mirror)
Description:
- Specifies game resource which will be used as a layer for blending.
Arguments:
- resID
- ID of the resource to be uses as a layer.
- g2d
- Indicates if an internal G2D resource is specified or not.
- x, y
- Coordinates of the bitmap center to place on the layer.
- alpha
- Layer transparency in range between 0x00 and 0xFF, where 0x00 is a fully transparent layer.
- color
- Layer's source key - a color in ARGB8888 format to be avoided.
- rotation
- Clockwise rotation angle in degrees. It is possible to specify free angle, but only right angles have HW acceleration. Currently rotation only applicable for external resources.
- mirror
- Mirroring variant. Possible values are self-explained: MIRROR_BLANK, MIRROR_X, MIRROR_Y, MIRROR_XY.
abi_CMD_G2D_ADD_RECTANGLE
Syntax:
abi_CMD_G2D_ADD_RECTANGLE(const x, const y, const width, const height, const color)
Description:
- Specifies rectangle area which will be used as layer of blending. This API is not intended for frequent usage, i.e. particles generation. It is better suited for changing image background or applying color mask.
Arguments:
- x, y
- Coordinates of top left rectangle corner.
- width
- Rectangle width.
- height
- Rectangle height.
- color
- Rectangle color in ARGB8888 format.
abi_CMD_G2D_END
Syntax:
abi_CMD_G2D_END()
Description:
- abi_CMD_G2D_END() and abi_CMD_G2D_BEGIN_BITMAP/abi_CMD_G2D_BEGIN_DISPLAY delimits the group of layers to be blended. After abi_CMD_G2D_END call final blending will be initiated and results will be stored according to the begin comand.
Examples
1. Render into inner G2D resource buffer #face and display it on the display #face. Please, note that last argument of abi_CMD_BITMAP is a `true` flag, which means G2D resource should be used:
... abi_CMD_G2D_BEGIN_BITMAP(face, 240, 240, true); abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize0, 120 - animationSquareSize0, animationSquareSize0 * 2, animationSquareSize0 * 2, 0xdfff0000); abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize1, 120 - animationSquareSize1, animationSquareSize1 * 2, animationSquareSize1 * 2, 0xdfffff00); abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize2, 120 - animationSquareSize2, animationSquareSize2 * 2, animationSquareSize2 * 2, 0xdfff00ff); abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize3, 120 - animationSquareSize3, animationSquareSize3 * 2, animationSquareSize3 * 2, 0xdf00ffff); abi_CMD_G2D_ADD_SPRITE(resID, false, 120, 120, animationAlpha, 0x00000000, animationAngle, MIRROR_BLANK); abi_CMD_G2D_END(); ... abi_CMD_BITMAP(face, 120, 120, 0, MIRROR_BLANK, true); ... abi_CMD_REDRAW(face); ...
2. Render directly into display framebuffer #face. This will produce same result on display as example #1, but the generated image is not saved:
... abi_CMD_G2D_BEGIN_DISPLAY(face, true); abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize0, 120 - animationSquareSize0, animationSquareSize0 * 2, animationSquareSize0 * 2, 0xdfff0000); abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize1, 120 - animationSquareSize1, animationSquareSize1 * 2, animationSquareSize1 * 2, 0xdfffff00); abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize2, 120 - animationSquareSize2, animationSquareSize2 * 2, animationSquareSize2 * 2, 0xdfff00ff); abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize3, 120 - animationSquareSize3, animationSquareSize3 * 2, animationSquareSize3 * 2, 0xdf00ffff); abi_CMD_G2D_ADD_SPRITE(resID, false, 120, 120, animationAlpha, 0x00000000, animationAngle, MIRROR_BLANK); abi_CMD_G2D_END(); ...
Font drawing functions
abi_CMD_TEXT
API:
abi_CMD_TEXT(const text[], const fontResID, const x, const y, const scale, const angle, const r, const g, const b)
Description:
- Intended to render a system font or a custom font from resources with specified coordinates, scale and rotation at an arbitrary angle.
Arguments:
- text
- Array of chars.
- fontResID
- Custom font resource identifier.
- x, y
- Coordinates of top left rectangle corner.
- scale, angle
- Percentage scale and clockwise rotation angle in degrees. Max size of font is 200x200 px. (scale = 100%)
- r, g, b
- Font color in RGB format.
Example:
new text[4] = ['A', 'p', 'p', '\0']; abi_CMD_TEXT(text, RES_ID_FONT, 90, 160, 16, current_angles[face], 255, 0, 0);