Utility Functions

Triangle mapping and perspective warp operations

Summary
Utility FunctionsTriangle mapping and perspective warp operations
Functions
d2_utility_maptriangleThis function uses d2_settexturemapping to map a texture on a triangle.
d2_utility_perspectivewarpCopies an image in perspective manner to a destination rectangle.
d2_utility_fbblitcopyCopy a rectangular part inside the current framebuffer.
d2_rendercircle_no_hilimiterprecisionEnable or disable the high limiter precision feature of the latest D/AVE 2D renderer for drawing blurred circles with higher image quality.

Functions

d2_utility_maptriangle

d2_s32 d2_utility_maptriangle(d2_device *handle,
const d2_f32 *points,
const d2_f32 *uvs)

This function uses d2_settexturemapping to map a texture on a triangle.

parameters

handledevice pointer (see: d2_opendevice)
pointsptr to array of six floats containing the screen positions (x,y pairs)
uvsptr to array of six floats containing the texture coordinates (u,v pairs)

Please remember that this function has to access the current texture details (width, height and pitch) in order to calculate a correct mapping.  So the final texture must be active in the selected context at the time d2_utility_maptriangle is called. d2_utility_maptriangle is internally using d2_settexturemapping and is overwriting the current values.

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

see also

d2_settexturemapping

d2_utility_perspectivewarp

d2_s32 d2_utility_perspectivewarp(d2_device *handle,
d2_u16 srcwidth,
d2_u16 srcheight,
d2_s16 srcx,
d2_s16 srcy,
d2_s16 dstwidth,
d2_s16 dstheight,
d2_s16 dstx,
d2_s16 dsty,
d2_u16 wt)

Copies an image in perspective manner to a destination rectangle.

d2_utility_perspectivewarp is internally using d2_settexturemapping and is overwriting the current values.

parameters

handledevice pointer (see: d2_opendevice)
srcwidthwidth of source rectangle in pixels
srcheightheigth of source rectangle in pixels
srcxx position in source bitmap
srcyy position in source bitmap
dstwidthwidth of destination rectangle in pixels
dstheightheight of destination rectangle in pixels
dstxx position in destination bitmap
dstyy position in destination bitmap
wt1/z (z>1) value in 16 Bit fraction (z=2 -> wt=65536/2)

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

example

Copy a 256x256 source texture into a 640x480 destination rectangle:

...
d2_settexture( handle, texture, 256, 256, 256, d2_mode_rgb565 );
d2_settexturemode( handle, 0 );
d2_setfillmode( handle, d2_fm_texture );
d2_utility_perspectivewarp(  handle, 256, 256, 0, 0, 640, 480, 0, 0, 65536/4 );
...

limitations

This function is not meant for dynamic perspective animations.

see also

d2_settexturemapping

d2_utility_fbblitcopy

d2_s32 d2_utility_fbblitcopy(d2_device *handle,
d2_u16 width,
d2_u16 height,
d2_blitpos srcx,
d2_blitpos srcy,
d2_blitpos dstx,
d2_blitpos dsty,
d2_u32 flags)

Copy a rectangular part inside the current framebuffer.

This is a wrapper function around d2_blitcopy, which copies a rectangular region inside a single buffer.  Source and destination buffer are the current framebuffer, set via d2_framebuffer.  This function handles the different cases of potentially overlapping source and destination areas and makes sure no read-after-write problems arise.  Note that both source and destination rectangles need to lie fully inside the framebuffer for this function to work correctly.

parameters

handledevice pointer (see: d2_opendevice)
width, heightsize of source/destination rectangle in pixels (integer)
srcx, srcytop/left coordinate of source rectangle (integer)
dstx, dstytop/left coordinate of destination rectangle (integer)
flagsany combination of blit flag bits (see below), passed on to d2_blitcopy

flags parameter bits (only one bit allowed)

d2_bf_no_blitctxbackupfor this blit don’t backup context data for better performance; previous texture modes get lost and must be set again

returns

errorcode (D2_OK if successful) see list of Errorcodes for details

d2_rendercircle_no_hilimiterprecision

void d2_rendercircle_no_hilimiterprecision(d2_device *handle,
d2_u32 flag)

Enable or disable the high limiter precision feature of the latest D/AVE 2D renderer for drawing blurred circles with higher image quality.  Note: This function can be used to de-activate the feature for compatibility reasons (clear D2FB_HILIMITERPRECISION bit in HW revision)!

parameters

handledevice pointer (see: d2_opendevice)
flag0 will activate the high limiter precision if possible, 1 will deactivate the feature even on newer version of D/AVE 2D.
d2_s32 d2_utility_maptriangle(d2_device *handle,
const d2_f32 *points,
const d2_f32 *uvs)
This function uses d2_settexturemapping to map a texture on a triangle.
d2_s32 d2_utility_perspectivewarp(d2_device *handle,
d2_u16 srcwidth,
d2_u16 srcheight,
d2_s16 srcx,
d2_s16 srcy,
d2_s16 dstwidth,
d2_s16 dstheight,
d2_s16 dstx,
d2_s16 dsty,
d2_u16 wt)
Copies an image in perspective manner to a destination rectangle.
d2_s32 d2_utility_fbblitcopy(d2_device *handle,
d2_u16 width,
d2_u16 height,
d2_blitpos srcx,
d2_blitpos srcy,
d2_blitpos dstx,
d2_blitpos dsty,
d2_u32 flags)
Copy a rectangular part inside the current framebuffer.
void d2_rendercircle_no_hilimiterprecision(d2_device *handle,
d2_u32 flag)
Enable or disable the high limiter precision feature of the latest D/AVE 2D renderer for drawing blurred circles with higher image quality.
d2_device * d2_opendevice(d2_u32 flags)
Create a new device handle.
List of all dave driver errorcodes.
d2_s32 d2_settexturemapping(d2_device *handle,
d2_point x,
d2_point y,
d2_s32 u0,
d2_s32 v0,
d2_s32 dxu,
d2_s32 dyu,
d2_s32 dxv,
d2_s32 dyv)
Define texture mapping.
d2_s32 d2_blitcopy(d2_device *handle,
d2_s32 srcwidth,
d2_s32 srcheight,
d2_blitpos srcx,
d2_blitpos srcy,
d2_width dstwidth,
d2_width dstheight,
d2_point dstx,
d2_point dsty,
d2_u32 flags)
Copy rectangle part of the source into destination.
d2_s32 d2_framebuffer(d2_device *handle,
void *ptr,
d2_s32 pitch,
d2_u32 width,
d2_u32 height,
d2_s32 format)
Specify the rendering target.
Close