openTRI 0.1
Macros | Functions | Variables
2D graphics core

Macros

#define TRI_DLIST_SIZE_KB(x)   triU32 triDlistSizeUser = ((x)*1024);
 
#define SCREEN_WIDTH   480
 
#define SCREEN_HEIGHT   272
 
#define FRAME_BUFFER_WIDTH   512
 
#define FRAME_BUFFER_SIZE   (FRAME_BUFFER_WIDTH*SCREEN_HEIGHT)
 
#define TRI_ALPHA_TEST   0
 
#define TRI_DEPTH_TEST   1
 
#define TRI_SCISSOR_TEST   2
 
#define TRI_STENCIL_TEST   3
 
#define TRI_BLEND   4
 
#define TRI_CULL_FACE   5
 
#define TRI_DITHER   6
 
#define TRI_FOG   7
 
#define TRI_CLIP_PLANES   8
 
#define TRI_TEXTURE_2D   9
 
#define TRI_LIGHTING   10
 
#define TRI_LIGHT0   11
 
#define TRI_LIGHT1   12
 
#define TRI_LIGHT2   13
 
#define TRI_LIGHT3   14
 
#define TRI_AALINE   15
 
#define TRI_COLORKEY   17
 
#define TRI_LOGICAL_OP   18
 
#define TRI_NORMAL_REVERSE   19
 
#define TRI_VBLANK   32
 
#define TRI_PSEUDO_FSAA   33
 
#define TRI_SMOOTH_DITHER   34
 
#define TRI_DEPTH_MASK   35
 
#define TRI_DEPTH_WRITE   35
 

Functions

void triInit (triS32 psm, triBool doublebuffer)
 Initialize graphics. More...
 
void triClose ()
 Close graphics and free all resources.
 
void triBegin ()
 Begin an immediate render command block This is needed when you depend on the render result (e.g. More...
 
void triEnd ()
 End an immediate render command block.
 
void triSync ()
 Sync CPU to GU for the current immediate block.
 
void triSwapbuffers ()
 Wait for rendering to finish and swap front- and backbuffer.
 
void triVblank ()
 Wait for Vblank. More...
 
triFloat triCPULoad ()
 Return the current CPU load in percent. More...
 
triFloat triGPULoad ()
 Return the current GPU load in percent. More...
 
triFloat triFps ()
 Return the current FPS. More...
 
triFloat triFpsMax ()
 Return the maximal FPS. More...
 
triFloat triFpsMin ()
 Return the minimal FPS. More...
 
void triPerspective (triFloat fov)
 
void triOrtho ()
 
void triEnable (triU32 state)
 
void triDisable (triU32 state)
 
void triClear (triU32 color)
 
void triSetClip (triS32 x, triS32 y, triS32 width, triS32 height)
 
void triResetClip ()
 
void triRendertoscreen ()
 
void triRendertotexture (triS32 psm, void *tbp, triS32 tw, triS32 th, triS32 tbw)
 
void triRendertoimage (triImage *img)
 
void triCopyToScreen (triS32 x, triS32 y, triS32 w, triS32 h, triS32 sx, triS32 sy, triS32 sbw, void *src)
 
void triCopyFromScreen (triS32 x, triS32 y, triS32 w, triS32 h, triS32 dx, triS32 dy, triS32 dbw, void *dst)
 
void triDrawLine (triFloat x0, triFloat y0, triFloat x1, triFloat y1, triU32 color)
 Draw a line from (x0,y0) to (x1,y1) in color 'color'. More...
 
void triDrawLines (triVec2 *p, triS32 num, triU32 color)
 Draw a line strip consisting of num points in color 'color'. More...
 
void triDrawRect (triFloat x, triFloat y, triFloat width, triFloat height, triU32 color)
 Draw filled rectangle from (x,y) to (x+width,y+height) in color 'color'. More...
 
void triDrawRectOutline (triFloat x, triFloat y, triFloat width, triFloat height, triU32 color)
 Draw rectangle from (x,y) to (x+width,y+height) in color 'color' with outline only. More...
 
void triDrawRectRotate (triFloat x, triFloat y, triFloat width, triFloat height, triU32 color, triFloat angle)
 Draw Rectangle from (x,y) to (x+width,y+height) in color 'color' rotated by angle degree around it's center. More...
 
void triDrawRectGrad (triFloat x, triFloat y, triFloat width, triFloat height, triU32 color1, triU32 color2, triU32 color3, triU32 color4)
 Draw Rectangle from (x,y) to (x+width,y+height) with gradient. More...
 
void triDrawCircle (triFloat x, triFloat y, triFloat radius, triU32 color)
 Draw Circle. More...
 
void triDrawCircleOutline (triFloat x, triFloat y, triFloat radius, triU32 color)
 Draw Circle (outline only) More...
 
void triDrawCircleGrad (triFloat x, triFloat y, triFloat radius, triU32 color1, triU32 color2)
 Draw Circle with gradient. More...
 
void triDrawTri (triFloat x0, triFloat y0, triFloat x1, triFloat y1, triFloat x2, triFloat y2, triU32 color)
 Draw arbitrary triangle. More...
 
void triDrawTriOutline (triFloat x0, triFloat y0, triFloat x1, triFloat y1, triFloat x2, triFloat y2, triU32 color)
 Draw arbitrary triangle with outline only. More...
 
void triDrawTriGrad (triFloat x0, triFloat y0, triFloat x1, triFloat y1, triFloat x2, triFloat y2, triU32 color1, triU32 color2, triU32 color3)
 Draw arbitrary triangle with outline only. More...
 
void triDrawRegPoly (triFloat x, triFloat y, triFloat radius, triU32 color, triU32 numSteps, triFloat angle)
 Draw regular Polygon (Pentagon,Hexagon,Octagon,etc) More...
 
void triDrawRegPolyOutline (triFloat x, triFloat y, triFloat radius, triU32 color, triU32 numSteps, triFloat angle)
 Draw regular Polygon (Pentagon,Hexagon,Octagon,etc) with outline only. More...
 
void triDrawRegPolyGrad (triFloat x, triFloat y, triFloat radius, triU32 color1, triU32 color2, triU32 numSteps, triFloat angle)
 Draw regular Polygon (Pentagon,Hexagon,Octagon,etc) with gradient. More...
 
void triDrawStar (triFloat x, triFloat y, triFloat radiusInner, triFloat radiusOuter, triU32 color, triU32 numSteps, triFloat angle)
 Draw Star. More...
 
void triDrawStarOutline (triFloat x, triFloat y, triFloat radiusInner, triFloat radiusOuter, triU32 color, triU32 numSteps, triFloat angle)
 Draw Star with outline only. More...
 
void triDrawStarGrad (triFloat x, triFloat y, triFloat radiusInner, triFloat radiusOuter, triU32 color1, triU32 color2, triU32 numSteps, triFloat angle)
 Draw Star with gradient. More...
 
void triColorOp (triS32 op)
 
void trinoColorOp ()
 
void triImageTint (triS32 mode, triS32 comp, triU32 vcolor, triU32 ccolor)
 
void triImageNoTint ()
 
void triImageConstAlpha (triU32 alpha)
 
void triImageBlend (triS32 op, triS32 srcOp, triS32 dstOp, triU32 src_fix, triU32 dst_fix)
 
void triImageNoBlend ()
 
void triImageColorkey (triU32 color)
 
void triImageNoColorkey ()
 
void triSpriteMode (triFloat width, triFloat height, triFloat angle)
 Set sprite mode. More...
 
void triDrawSprite (triFloat x, triFloat y, triFloat u, triFloat v, triImage *img)
 Render a sprite. More...
 
void triBltSprite (triFloat x, triFloat y, triFloat u, triFloat v, triImage *img)
 Render a sprite without effects (no blending, transparency, etc.) More...
 
void triDrawImageCenterScaled (triFloat x, triFloat y, triFloat scale, triImage *img)
 Render an image centered at position x,y scaled by a factor. More...
 
void triDrawImageScaled (triFloat x, triFloat y, triFloat width, triFloat height, triImage *img)
 Render an image scaled by a factor. More...
 
void triDrawImage2 (triFloat x, triFloat y, triImage *img)
 Render an image at full size. More...
 
void triDrawImage (triFloat x, triFloat y, triFloat width, triFloat height, triFloat u0, triFloat v0, triFloat u1, triFloat v1, triImage *img)
 Render an image. More...
 
void triDrawImageRotate2 (triFloat x, triFloat y, triFloat angle, triImage *img)
 Render an image with rotation. More...
 
void triDrawImageRotate (triFloat x, triFloat y, triFloat width, triFloat height, triFloat u0, triFloat v0, triFloat u1, triFloat v1, triFloat angle, triImage *img)
 Render an image with rotation. More...
 
void triDrawImageAnimation (triFloat x, triFloat y, triImageAnimation *ani)
 Render an image animation. More...
 
void triDrawImageAnimationRotate (triFloat x, triFloat y, triFloat angle, triImageAnimation *ani)
 Render an image animation with rotation. More...
 

Variables

void * triFramebuffer
 
void * triFramebuffer2
 
void * triDepthbuffer
 
triS32 triPsm
 
triS32 triBpp
 

Detailed Description

Function Documentation

◆ triInit()

void triInit ( triS32  psm,
triBool  doublebuffer 
)

Initialize graphics.

Parameters
psmPixelformat to set output to (one of GU_PSM_4444,GU_PSM_5551,GU_PSM_5650 or GU_PSM_8888)
doublebufferWhether to use doublebuffering or not.
Note
Doublebuffering will allocate two framebuffers in VRAM and switch those. Else only one framebuffer is allocated in VRAM and two others in System RAM for display ('kind of' triple buffered). As VRAM is small, this might be a valuable trade-off.

mode pixelformat Free VRAM (bytes) double 16bit (no depth) 1,540,096 double 32bit (no depth) 983,040 double 16bit (depth) 1,261,568 double 32bit (depth) 704,512 triple 16bit (no depth) 1,818,624 triple 32bit (no depth) 1,540,096 triple 16bit (depth) 1,540,096 triple 32bit (depth) 1,261,568

◆ triBegin()

void triBegin ( )

Begin an immediate render command block This is needed when you depend on the render result (e.g.

for renderbuffer effects)

◆ triVblank()

void triVblank ( )

Wait for Vblank.

Will do nothing if TRI_VBLANK is already enabled.

◆ triCPULoad()

triFloat triCPULoad ( )

Return the current CPU load in percent.

Returns
The current CPU load in percent

◆ triGPULoad()

triFloat triGPULoad ( )

Return the current GPU load in percent.

Returns
The current GPU load in percent

◆ triFps()

triFloat triFps ( )

Return the current FPS.

Returns
The current FPS

◆ triFpsMax()

triFloat triFpsMax ( )

Return the maximal FPS.

Returns
The maximal FPS

◆ triFpsMin()

triFloat triFpsMin ( )

Return the minimal FPS.

Returns
The minimal FPS

◆ triDrawLine()

void triDrawLine ( triFloat  x0,
triFloat  y0,
triFloat  x1,
triFloat  y1,
triU32  color 
)

Draw a line from (x0,y0) to (x1,y1) in color 'color'.

Parameters
x0X position of first point
y0Y position of first point
x1X position of second point
y1Y position of second point
colorColor of line

◆ triDrawLines()

void triDrawLines ( triVec2 p,
triS32  num,
triU32  color 
)

Draw a line strip consisting of num points in color 'color'.

Parameters
pArray of triVec2's
numNumber of vertices in line strip
colorColor of the line strip

◆ triDrawRect()

void triDrawRect ( triFloat  x,
triFloat  y,
triFloat  width,
triFloat  height,
triU32  color 
)

Draw filled rectangle from (x,y) to (x+width,y+height) in color 'color'.

Parameters
xX position of rectangles top-left point
yY position of rectangles top-left point
widthWidth of the rectangle
heightHeight of the rectangle
colorColor of rectangle

◆ triDrawRectOutline()

void triDrawRectOutline ( triFloat  x,
triFloat  y,
triFloat  width,
triFloat  height,
triU32  color 
)

Draw rectangle from (x,y) to (x+width,y+height) in color 'color' with outline only.

Parameters
xX position of rectangles top-left point
yY position of rectangles top-left point
widthWidth of the rectangle
heightHeight of the rectangle
colorColor of rectangle

◆ triDrawRectRotate()

void triDrawRectRotate ( triFloat  x,
triFloat  y,
triFloat  width,
triFloat  height,
triU32  color,
triFloat  angle 
)

Draw Rectangle from (x,y) to (x+width,y+height) in color 'color' rotated by angle degree around it's center.

Parameters
xX position of rectangles top-left point
yY position of rectangles top-left point
widthWidth of the rectangle
heightHeight of the rectangle
colorColor of rectangle
angleNumber of degree to rotate the rectangle

◆ triDrawRectGrad()

void triDrawRectGrad ( triFloat  x,
triFloat  y,
triFloat  width,
triFloat  height,
triU32  color1,
triU32  color2,
triU32  color3,
triU32  color4 
)

Draw Rectangle from (x,y) to (x+width,y+height) with gradient.

Parameters
xX position of rectangles top-left point
yY position of rectangles top-left point
widthWidth of the rectangle
heightHeight of the rectangle
color1Color of top-left point
color2Color of top-right point
color3Color of bottom-right point
color4Color of bottom-left point

◆ triDrawCircle()

void triDrawCircle ( triFloat  x,
triFloat  y,
triFloat  radius,
triU32  color 
)

Draw Circle.

Parameters
xX position of circle center
yY position of circle center
radiusRadius of circle
colorColor of circle

◆ triDrawCircleOutline()

void triDrawCircleOutline ( triFloat  x,
triFloat  y,
triFloat  radius,
triU32  color 
)

Draw Circle (outline only)

Parameters
xX position of circle center
yY position of circle center
radiusRadius of circle
colorColor of circle

◆ triDrawCircleGrad()

void triDrawCircleGrad ( triFloat  x,
triFloat  y,
triFloat  radius,
triU32  color1,
triU32  color2 
)

Draw Circle with gradient.

Parameters
xX position of circle center
yY position of circle center
radiusRadius of circle
color1Inner color of circle
color2Outer color of circle

◆ triDrawTri()

void triDrawTri ( triFloat  x0,
triFloat  y0,
triFloat  x1,
triFloat  y1,
triFloat  x2,
triFloat  y2,
triU32  color 
)

Draw arbitrary triangle.

Parameters
x0X position of first point
y0Y position of first point
x1X position of second point
y1Y position of second point
x2X position of third point
y2Y position of third point
colorColor of triangle

◆ triDrawTriOutline()

void triDrawTriOutline ( triFloat  x0,
triFloat  y0,
triFloat  x1,
triFloat  y1,
triFloat  x2,
triFloat  y2,
triU32  color 
)

Draw arbitrary triangle with outline only.

Parameters
x0X position of first point
y0Y position of first point
x1X position of second point
y1Y position of second point
x2X position of third point
y2Y position of third point
colorColor of triangle

◆ triDrawTriGrad()

void triDrawTriGrad ( triFloat  x0,
triFloat  y0,
triFloat  x1,
triFloat  y1,
triFloat  x2,
triFloat  y2,
triU32  color1,
triU32  color2,
triU32  color3 
)

Draw arbitrary triangle with outline only.

Parameters
x0X position of first point
y0Y position of first point
x1X position of second point
y1Y position of second point
x2X position of third point
y2Y position of third point
color1Color of first point
color2Color of second point
color3Color of third point

◆ triDrawRegPoly()

void triDrawRegPoly ( triFloat  x,
triFloat  y,
triFloat  radius,
triU32  color,
triU32  numSteps,
triFloat  angle 
)

Draw regular Polygon (Pentagon,Hexagon,Octagon,etc)

Parameters
xX position of polygon center
yY position of polygon center
radiusRadius of polygon points
colorColor of polygon
numStepsNumber of points of polygon (>2)
angleNumber of degree to rotate the polygon by

◆ triDrawRegPolyOutline()

void triDrawRegPolyOutline ( triFloat  x,
triFloat  y,
triFloat  radius,
triU32  color,
triU32  numSteps,
triFloat  angle 
)

Draw regular Polygon (Pentagon,Hexagon,Octagon,etc) with outline only.

Parameters
xX position of polygon center
yY position of polygon center
radiusRadius of polygon points
colorColor of polygon
numStepsNumber of points of polygon (>2)
angleNumber of degree to rotate the polygon by

◆ triDrawRegPolyGrad()

void triDrawRegPolyGrad ( triFloat  x,
triFloat  y,
triFloat  radius,
triU32  color1,
triU32  color2,
triU32  numSteps,
triFloat  angle 
)

Draw regular Polygon (Pentagon,Hexagon,Octagon,etc) with gradient.

Parameters
xX position of polygon center
yY position of polygon center
radiusRadius of polygon points
color1Color of polygon center
color2Color of polygon outer points
numStepsNumber of points of polygon (>2)
angleNumber of degree to rotate the polygon by

◆ triDrawStar()

void triDrawStar ( triFloat  x,
triFloat  y,
triFloat  radiusInner,
triFloat  radiusOuter,
triU32  color,
triU32  numSteps,
triFloat  angle 
)

Draw Star.

Parameters
xX position of star center
yY position of star center
radiusInnerRadius of inner star points
radiusOuterRadius of outer star points
colorColor of star
numStepsNumber of points of star (>2)
angleNumber of degree to rotate the star by

◆ triDrawStarOutline()

void triDrawStarOutline ( triFloat  x,
triFloat  y,
triFloat  radiusInner,
triFloat  radiusOuter,
triU32  color,
triU32  numSteps,
triFloat  angle 
)

Draw Star with outline only.

Parameters
xX position of star center
yY position of star center
radiusInnerRadius of inner star points
radiusOuterRadius of outer star points
colorColor of star
numStepsNumber of points of star (>2)
angleNumber of degree to rotate the star by

◆ triDrawStarGrad()

void triDrawStarGrad ( triFloat  x,
triFloat  y,
triFloat  radiusInner,
triFloat  radiusOuter,
triU32  color1,
triU32  color2,
triU32  numSteps,
triFloat  angle 
)

Draw Star with gradient.

Parameters
xX position of star center
yY position of star center
radiusInnerRadius of inner star points
radiusOuterRadius of outer star points
color1Color of star center
color2Color of star outer points
numStepsNumber of points of star (>2)
angleNumber of degree to rotate the star by

◆ triSpriteMode()

void triSpriteMode ( triFloat  width,
triFloat  height,
triFloat  angle 
)

Set sprite mode.

Parameters
widthWidth of all subsequent sprites to render
heightHeight of all subsequent sprites to render
angleAngle of all subsequent sprites to rotate

◆ triDrawSprite()

void triDrawSprite ( triFloat  x,
triFloat  y,
triFloat  u,
triFloat  v,
triImage img 
)

Render a sprite.

Parameters
xScreen position to draw the sprite to
yScreen position to draw the sprite to
uVertical sprite position to start drawing from (sprite sheet/tile map)
vHorizontal sprite position to start drawing from (sprite sheet/tile map)
imgImage to draw

◆ triBltSprite()

void triBltSprite ( triFloat  x,
triFloat  y,
triFloat  u,
triFloat  v,
triImage img 
)

Render a sprite without effects (no blending, transparency, etc.)

Parameters
xScreen position to draw the sprite to
yScreen position to draw the sprite to
uVertical sprite position to start drawing from (sprite sheet/tile map)
vHorizontal sprite position to start drawing from (sprite sheet/tile map)
imgImage to draw
Note
This only works if sprite has same pixel format as the framebuffer. Else this will fall back to triDrawSprite.

◆ triDrawImageCenterScaled()

void triDrawImageCenterScaled ( triFloat  x,
triFloat  y,
triFloat  scale,
triImage img 
)

Render an image centered at position x,y scaled by a factor.

This supports large images > 512x512.

Parameters
xScreen position to center the image at
yScreen position to center the image at
scaleScale factor to scale image with (> 1.0 is zoom in, < 1.0 is zoom out)
imgImage to draw

◆ triDrawImageScaled()

void triDrawImageScaled ( triFloat  x,
triFloat  y,
triFloat  width,
triFloat  height,
triImage img 
)

Render an image scaled by a factor.

This supports large images > 512x512.

Parameters
xScreen position to draw the image to
yScreen position to draw the image to
widthWidth of image on screen for scaling. A width < 0 flips image vertically.
heightHeight of image on screen for scaling. A height < 0 flips image horizontally.
imgImage to draw

◆ triDrawImage2()

void triDrawImage2 ( triFloat  x,
triFloat  y,
triImage img 
)

Render an image at full size.

This supports large images > 512x512.

Parameters
xScreen position to draw the image to
yScreen position to draw the image to
imgImage to draw

◆ triDrawImage()

void triDrawImage ( triFloat  x,
triFloat  y,
triFloat  width,
triFloat  height,
triFloat  u0,
triFloat  v0,
triFloat  u1,
triFloat  v1,
triImage img 
)

Render an image.

This supports large images > 512x512.

Parameters
xScreen position to draw the image to
yScreen position to draw the image to
widthWidth of image on screen for scaling. A width < 0 flips image vertically.
heightHeight of image on screen for scaling. A height < 0 flips image horizontally.
u0Vertical image position to start drawing from (sprite sheet/tile map)
v0Horizontal image position to start drawing from (sprite sheet/tile map)
u1Vertical image position to end drawing at (sprite sheet/tile map)
v1Horizontal image position to end drawing at (sprite sheet/tile map)
imgImage to draw

◆ triDrawImageRotate2()

void triDrawImageRotate2 ( triFloat  x,
triFloat  y,
triFloat  angle,
triImage img 
)

Render an image with rotation.

Parameters
xScreen position to draw the image to
yScreen position to draw the image to
angleAngle to rotate the image by in degree
imgImage to draw

◆ triDrawImageRotate()

void triDrawImageRotate ( triFloat  x,
triFloat  y,
triFloat  width,
triFloat  height,
triFloat  u0,
triFloat  v0,
triFloat  u1,
triFloat  v1,
triFloat  angle,
triImage img 
)

Render an image with rotation.

Parameters
xScreen position to draw the image to
yScreen position to draw the image to
widthWidth of image on screen for scaling
heightHeight of image on screen for scaling
u0Vertical image position to start drawing from (sprite sheet/tile map)
v0Horizontal image position to start drawing from (sprite sheet/tile map)
u1Vertical image position to end drawing at (sprite sheet/tile map)
v1Horizontal image position to end drawing at (sprite sheet/tile map)
angleAngle to rotate the image by in degree
imgImage to draw

◆ triDrawImageAnimation()

void triDrawImageAnimation ( triFloat  x,
triFloat  y,
triImageAnimation ani 
)

Render an image animation.

Parameters
xScreen position to draw the image to
yScreen position to draw the image to
aniImage animation to draw

◆ triDrawImageAnimationRotate()

void triDrawImageAnimationRotate ( triFloat  x,
triFloat  y,
triFloat  angle,
triImageAnimation ani 
)

Render an image animation with rotation.

Parameters
xScreen position to draw the image to
yScreen position to draw the image to
angleAngle to rotate the image by in degree
aniImage animation to draw