Advanced vertex commands
[Drawing]

Advanced vertex commands and depth management. More...

Defines

#define ulSetDepth(z)   (ul_currentDepth = z)
#define ulGetDepth()   ul_currentDepth
#define ulSetAutoDepth(enable)   (ul_autoDepth = enable)
#define ulVertexBegin(vtype)   ( GFX_BEGIN = vtype )
#define ulVertexEnd()   ( GFX_END = 0 )
#define ulVertexHandleDepth()   ( ul_currentDepth += ul_autoDepth )
#define ulVertexUVXY(u, v, x, y)
#define ulVertexXY(x, y)
#define ulVertexColor(color)   ( GFX_COLOR = color )
#define ulDisableTexture()   (GFX_TEX_FORMAT = 0)

Functions

void ulSetTexture (UL_IMAGE *img)

Detailed Description

Advanced vertex commands and depth management.


Define Documentation

#define ulSetDepth (  )     (ul_currentDepth = z)

Defines the depth of the next object to draw.

 
#define ulGetDepth (  )     ul_currentDepth

Retreives the current depth. Useful when the AutoDepth mode is enabled.

#define ulSetAutoDepth ( enable   )     (ul_autoDepth = enable)

Set whether you want to increment the depth of objects automatically. Enabled by default.

Parameters:
enable 0 = disable, 1 = enable. Do not set to any other value, else priority problems can and will appear.

#define ulVertexBegin ( vtype   )     ( GFX_BEGIN = vtype )

Begins to draw a new 2D/3D object.

Parameters:
vtype Defines the type of object you want to draw.
  • GL_TRIANGLES: individual triangles (3 vertices)
  • GL_QUADS: individual quadliterals (4 vertices)
  • GL_TRIANGLE_STRIP: stripped triangles (3 vertices + 1 per linked triangle)
  • GL_QUAD_STRIP: stripped quads (4 vertices + 2 per linked quad)
Lines are drawn as a flat triangles. That is, to draw a line from (x0,y0) to (x1,y1), you can do this:
ulVertexBegin(GL_TRIANGLES);
ulVertexXY(x0, y0);
ulVertexXY(x1, y1);
ulVertexXY(x1, y1);
ulVertexEnd();
If you want to know how GL_TRIANGLE_STRIP or GL_QUAD_STRIP works, here is a small definition taken from gbatek: http://nocash.emubase.de/gbatek.htm
        Separate Tri.     Triangle Strips   Line Segment
        v0                 v2___v4____v6
        |\      v3         /|\  |\    /\     v0    v1
        | \     /\      v0( | \ | \  /  \     ------
        |__\   /__\        \|__\|__\/____\         v2
        v1 v2 v4  v5       v1   v3  v5   v7
        
        
        Separate Quads          Quadliteral Strips         Prohibited Quads
         v0__v3                 v0__v2____v4     v10__    v0__v3     v4
          /  \   v4____v7        /  \     |\ _____ / /v11   \/       |\
         /    \   |    \        /    \    | |v6 v8| /       /\     v5| \
        /______\  |_____\      /______\___|_|_____|/       /__\     /___\
        v1    v2  v5    v6     v1    v3  v5 v7   v9       v2   v1   v6   v7

 
#define ulVertexEnd (  )     ( GFX_END = 0 )

Call this after you've finished to draw your object. Look at the examples above for more informations.

 
#define ulVertexHandleDepth (  )     ( ul_currentDepth += ul_autoDepth )

You MUST call this after you've terminated to draw any object on the screen. It is necessary to get the auto-depth feature working.

#define ulVertexUVXY ( u,
v,
x,
 ) 

Value:

({ GFX_TEX_COORD = ((u16)(v)) << 20 | ((u16)(u)) << 4;                  \
                                                                                                                GFX_VERTEX16 = (((u16)(y)) << 16) | ((u16)(x)); \
                                                                                                                GFX_VERTEX16 = ul_currentDepth; })
Issues a 2D vertex command.
Parameters:
u,v Texture coordinates
x,y Vertex coordinates
You should first select a texture using ulSetTexture. After your 2D object has finished drawing, make sure to call the auto-increment handling routine! Here is a code sample for a simple drawing routine:
void drawAnImage(UL_IMAGE *img)
{
        ulSetTexture(img);

        //Begins drawing quadliterals
        ulVertexBegin(GL_QUADS);

        //Drawing order for a quad is: top-left, bottom-left, bottom-right, top-right.
        ulVertexUVXY(img->offsetX0, img->offsetY0, img->x, img->y);
        ulVertexUVXY(img->offsetX0, img->offsetY1, img->x, img->y + img->stretchY);
        ulVertexUVXY(img->offsetX1, img->offsetY1, img->x + img->stretchX, img->y + img->stretchY);
        ulVertexUVXY(img->offsetX1, img->offsetY0, img->x + img->stretchX, img->y);

        //End there. You could also continue and draw other quads (issue 4 new vertex commands)
        ulVertexEnd();

        //Auto-increment depth
        ulVertexHandleDepth();
        return;
}

#define ulVertexXY ( x,
 ) 

Value:

({ GFX_VERTEX16 = (((u16)(y)) << 16) | ((u16)(x)); \
                                                                                                                GFX_VERTEX16 = ul_currentDepth; })
Issues a 2D vertex command.
Parameters:
x,y Vertex coordinates
Same remarks as for ulVertexUVXY, except that there is no texture here. You should disable texturing when doing that! Here is a code sample for a simple drawing routine:
void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, UL_COLOR color)
{
        //We're drawing a simple colored triangle (untextured)
        ulDisableTexture();

        //Begins drawing quadliterals
        ulVertexBegin(GL_TRIANGLES);
        
        //You can define the color of each vertex before issuing the vertex command, or once for all, like here. If the vertices have different colors, a gradient will appear between each corner.
        ulVertexColor(color);

        //Draw our triangle (3 vertices)
        ulVertexXY(x0, y0);
        ulVertexXY(x1, y1);
        ulVertexXY(x2, y2);

        //End our drawing.
        ulVertexEnd();

        //Don't forget to auto-increment depth
        ulVertexHandleDepth();
        return;
}

#define ulVertexColor ( color   )     ( GFX_COLOR = color )

Set the next vertex color. In a 2D or 3D object, each vertex can have its own color, just call this before issuing the vertex command to set its color.

 
#define ulDisableTexture (  )     (GFX_TEX_FORMAT = 0)

Disables texturing. Use it if you want to draw a coloured or gradient-filled object.


Function Documentation

void ulSetTexture ( UL_IMAGE img  ) 

Sets the current image as a texture so you can draw on the screen by issuing vertex commands. This function will realize the image if it's not already done.


Generated on Sat Jul 14 23:39:33 2007 by  doxygen 1.5.2