[ADD] Added several new functions to change drawing settings like Color, Scale and Rotation for all following drawing commands.

[CHG] Changed all drawing commands accordingly to make use of the settings by the functions specified above.
[NOTE] All examples will have to be adopted to the changed as well, it isn't much of work I might as well do it myself later.
This commit is contained in:
Xane 2009-11-24 21:15:35 +00:00
parent 28e2fcd9f0
commit 9e0b0182a9
8 changed files with 238 additions and 65 deletions

View file

@ -149,6 +149,7 @@ int GRRLIB_Init (void) {
GRRLIB_ClipReset();
// Default settings
GRRLIB_ResetSettings();
GRRLIB_Settings.antialias = true;
GRRLIB_Settings.blend = GRRLIB_BLEND_ALPHA;

View file

@ -31,14 +31,12 @@ THE SOFTWARE.
* @param xpos Specifies the x-coordinate of the upper-left corner of the text.
* @param ypos Specifies the y-coordinate of the upper-left corner of the text.
* @param tex The texture containing the character set.
* @param color Text color in RGBA format. The alpha channel is used to change the opacity of the text.
* @param zoom This is a factor by which the text size will be increase or decrease.
* @param text Text to draw.
* @param ... Optional arguments.
*/
void GRRLIB_Printf (const f32 xpos, const f32 ypos,
const GRRLIB_texImg *tex, const u32 color,
const f32 zoom, const char *text, ...) {
const GRRLIB_texImg *tex,
const char *text, ...) {
if (tex == NULL || tex->data == NULL) {
return;
}
@ -53,7 +51,7 @@ void GRRLIB_Printf (const f32 xpos, const f32 ypos,
for (i = 0; i < size; i++) {
u8 c = tmp[i]-tex->tilestart;
GRRLIB_DrawTile(xpos+i*tex->tilew*zoom, ypos, tex, 0, zoom, zoom, color, c);
GRRLIB_DrawTile(xpos+i*tex->tilew*GRRLIB_GetScaleX(), ypos, tex, c);
}
}
@ -100,6 +98,6 @@ void GRRLIB_PrintBMF (const f32 xpos, const f32 ypos,
}
GRRLIB_FlushTex( tex_BMfont );
GRRLIB_DrawImg(0, 0, tex_BMfont, 0, 1, 1, 0xFFFFFFFF);
GRRLIB_DrawImg(0, 0, tex_BMfont);
GRRLIB_FreeTexture(tex_BMfont);
}

View file

@ -34,14 +34,8 @@ static guVector axis = (guVector){0, 0, 1};
* @param xpos Specifies the x-coordinate of the upper-left corner.
* @param ypos Specifies the y-coordinate of the upper-left corner.
* @param tex The texture to draw.
* @param degrees Angle of rotation.
* @param scaleX Specifies the x-coordinate scale. -1 could be used for flipping the texture horizontally.
* @param scaleY Specifies the y-coordinate scale. -1 could be used for flipping the texture vertically.
* @param color Color in RGBA format.
*/
void GRRLIB_DrawImg (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex,
const f32 degrees, const f32 scaleX, const f32 scaleY,
const u32 color) {
void GRRLIB_DrawImg (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex) {
GXTexObj texObj;
u16 width, height;
Mtx m, m1, m2, mv;
@ -59,6 +53,12 @@ void GRRLIB_DrawImg (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex,
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
// Get current drawing settings.
u32 color = GRRLIB_Settings.colorRGBA;
f32 degrees = GRRLIB_Settings.rotation;
f32 scaleX = GRRLIB_Settings.scaleX;
f32 scaleY = GRRLIB_Settings.scaleY;
guMtxIdentity (m1);
guMtxScaleApply(m1, m1, scaleX, scaleY, 1.0);
guMtxRotAxisDeg(m2, &axis, degrees);
@ -105,10 +105,8 @@ void GRRLIB_DrawImg (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex,
* Draw a textured quad.
* @param pos Vector array of the 4 points.
* @param tex The texture to draw.
* @param color Color in RGBA format.
*/
void GRRLIB_DrawImgQuad (const guVector pos[4], GRRLIB_texImg *tex,
const u32 color) {
void GRRLIB_DrawImgQuad (const guVector pos[4], GRRLIB_texImg *tex) {
GXTexObj texObj;
Mtx m, m1, m2, mv;
@ -125,6 +123,9 @@ void GRRLIB_DrawImgQuad (const guVector pos[4], GRRLIB_texImg *tex,
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
// Get current drawing settings.
u32 color = GRRLIB_Settings.colorRGBA;
guMtxIdentity (m1);
guMtxScaleApply(m1, m1, 1, 1, 1.0);
guMtxRotAxisDeg(m2, &axis, 0);
@ -160,15 +161,9 @@ void GRRLIB_DrawImgQuad (const guVector pos[4], GRRLIB_texImg *tex,
* @param xpos Specifies the x-coordinate of the upper-left corner.
* @param ypos Specifies the y-coordinate of the upper-left corner.
* @param tex The texture containing the tile to draw.
* @param degrees Angle of rotation.
* @param scaleX Specifies the x-coordinate scale. -1 could be used for flipping the texture horizontally.
* @param scaleY Specifies the y-coordinate scale. -1 could be used for flipping the texture vertically.
* @param color Color in RGBA format.
* @param frame Specifies the frame to draw.
*/
void GRRLIB_DrawTile (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex,
const f32 degrees, const f32 scaleX, const f32 scaleY,
const u32 color, const int frame) {
void GRRLIB_DrawTile (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex, const int frame) {
GXTexObj texObj;
f32 width, height;
Mtx m, m1, m2, mv;
@ -197,6 +192,12 @@ void GRRLIB_DrawTile (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex,
width = tex->tilew * 0.5f;
height = tex->tileh * 0.5f;
// Get current drawing settings.
u32 color = GRRLIB_Settings.colorRGBA;
f32 degrees = GRRLIB_Settings.rotation;
f32 scaleX = GRRLIB_Settings.scaleX;
f32 scaleY = GRRLIB_Settings.scaleY;
guMtxIdentity (m1);
guMtxScaleApply(m1, m1, scaleX, scaleY, 1.0f);
guMtxRotAxisDeg(m2, &axis, degrees);
@ -246,15 +247,9 @@ void GRRLIB_DrawTile (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex,
* @param partw Specifies the width in the texture.
* @param parth Specifies the height in the texture.
* @param tex The texture containing the tile to draw.
* @param degrees Angle of rotation.
* @param scaleX Specifies the x-coordinate scale. -1 could be used for flipping the texture horizontally.
* @param scaleY Specifies the y-coordinate scale. -1 could be used for flipping the texture vertically.
* @param color Color in RGBA format.
*/
void GRRLIB_DrawPart (const f32 xpos, const f32 ypos, const f32 partx, const f32 party,
const f32 partw, const f32 parth, const GRRLIB_texImg *tex,
const f32 degrees, const f32 scaleX, const f32 scaleY,
const u32 color) {
const f32 partw, const f32 parth, const GRRLIB_texImg *tex) {
GXTexObj texObj;
f32 width, height;
Mtx m, m1, m2, mv;
@ -276,6 +271,12 @@ void GRRLIB_DrawPart (const f32 xpos, const f32 ypos, const f32 partx, const f3
GX_InitTexObjLOD(&texObj, GX_NEAR, GX_NEAR,
0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1);
// Get current drawing settings.
u32 color = GRRLIB_Settings.colorRGBA;
f32 degrees = GRRLIB_Settings.rotation;
f32 scaleX = GRRLIB_Settings.scaleX;
f32 scaleY = GRRLIB_Settings.scaleY;
GX_LoadTexObj(&texObj, GX_TEXMAP0);
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
@ -327,11 +328,9 @@ void GRRLIB_DrawPart (const f32 xpos, const f32 ypos, const f32 partx, const f3
* Draw a tile in a quad.
* @param pos Vector array of the 4 points.
* @param tex The texture to draw.
* @param color Color in RGBA format.
* @param frame Specifies the frame to draw.
*/
void GRRLIB_DrawTileQuad (const guVector pos[4], GRRLIB_texImg *tex,
const u32 color, const int frame) {
void GRRLIB_DrawTileQuad (const guVector pos[4], GRRLIB_texImg *tex, const int frame) {
GXTexObj texObj;
Mtx m, m1, m2, mv;
f32 s1, s2, t1, t2;
@ -356,6 +355,9 @@ void GRRLIB_DrawTileQuad (const guVector pos[4], GRRLIB_texImg *tex,
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
// Get current drawing settings.
u32 color = GRRLIB_Settings.colorRGBA;
guMtxIdentity (m1);
guMtxScaleApply(m1, m1, 1, 1, 1.0f);
guMtxRotAxisDeg(m2, &axis, 0);

View file

@ -95,6 +95,14 @@ typedef enum GRRLIB_blendMode {
typedef struct GRRLIB_drawSettings {
bool antialias; /**< AntiAlias is enabled when set to true. */
GRRLIB_blendMode blend; /**< Blending Mode. */
u8 colorR; /**< Red component of color. */
u8 colorG; /**< Green component of color. */
u8 colorB; /**< Blue component of color. */
u8 colorA; /**< Alpha component of color. */
u32 colorRGBA; /**< Color in RGBA. */
f32 rotation; /**< Angle of rotation in degrees. */
f32 scaleX; /**< Horizontal scale. */
f32 scaleY; /**< Vertical scale. */
} GRRLIB_drawSettings;
//------------------------------------------------------------------------------

View file

@ -79,12 +79,12 @@ INLINE void GRRLIB_GXEngine (const guVector v[], const u32 color[],
//------------------------------------------------------------------------------
// GRRLIB_fbSimple.h -
INLINE void GRRLIB_FillScreen (const u32 color) ;
INLINE void GRRLIB_Plot (const f32 x, const f32 y, const u32 color) ;
INLINE void GRRLIB_Plot (const f32 x, const f32 y) ;
INLINE void GRRLIB_Line (const f32 x1, const f32 y1,
const f32 x2, const f32 y2, const u32 color) ;
const f32 x2, const f32 y2) ;
INLINE void GRRLIB_Rectangle (const f32 x, const f32 y,
const f32 width, const f32 height,
const u32 color, const u8 filled) ;
const u8 filled) ;
//------------------------------------------------------------------------------
// GRRLIB_handle.h - Texture handle manipulation
@ -111,6 +111,21 @@ INLINE void GRRLIB_SetBlend (const GRRLIB_blendMode blendmo
INLINE GRRLIB_blendMode GRRLIB_GetBlend (void) ;
INLINE void GRRLIB_SetAntiAliasing (const bool aa) ;
INLINE bool GRRLIB_GetAntiAliasing (void) ;
INLINE void GRRLIB_SetColor (const u8 r, const u8 g, const u8 b) ;
INLINE void GRRLIB_SetColorRGBA (const u32 color) ;
INLINE void GRRLIB_SetAlpha (const u32 alpha) ;
INLINE u8 GRRLIB_GetColorRed (void) ;
INLINE u8 GRRLIB_GetColorGreen (void) ;
INLINE u8 GRRLIB_GetColorBlue (void) ;
INLINE u8 GRRLIB_GetAlpha (void) ;
INLINE void GRRLIB_SetRotation (const f32 rot) ;
INLINE f32 GRRLIB_GetRotation (void) ;
INLINE void GRRLIB_SetScale (const f32 sx, const f32 sy) ;
INLINE void GRRLIB_SetScaleX (const f32 sx) ;
INLINE void GRRLIB_SetScaleY (const f32 sy) ;
INLINE f32 GRRLIB_GetScaleX (void) ;
INLINE f32 GRRLIB_GetScaleY (void) ;
INLINE void GRRLIB_ResetSettings (void) ;
//------------------------------------------------------------------------------
// GRRLIB_texSetup.h - Create and setup textures

View file

@ -91,8 +91,8 @@ bool GRRLIB_ScrShot (const char* filename) ;
//------------------------------------------------------------------------------
//! GRRLIB_print.c - Will someome please tell me what these are :)
void GRRLIB_Printf (const f32 xpos, const f32 ypos,
const GRRLIB_texImg *tex, const u32 color,
const f32 zoom, const char *text, ...) ;
const GRRLIB_texImg *tex,
const char *text, ...) ;
void GRRLIB_PrintBMF (const f32 xpos, const f32 ypos,
const GRRLIB_bytemapFont *bmf,
@ -100,23 +100,17 @@ void GRRLIB_PrintBMF (const f32 xpos, const f32 ypos,
//------------------------------------------------------------------------------
// GRRLIB_render.c - Rendering functions
void GRRLIB_DrawImg (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex,
const f32 degrees, const f32 scaleX, const f32 scaleY,
const u32 color) ;
void GRRLIB_DrawImg (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex) ;
void GRRLIB_DrawImgQuad (const guVector pos[4], GRRLIB_texImg *tex,
const u32 color) ;
void GRRLIB_DrawImgQuad (const guVector pos[4], GRRLIB_texImg *tex) ;
void GRRLIB_DrawTile (const f32 xpos, const f32 ypos, const GRRLIB_texImg *tex,
const f32 degrees, const f32 scaleX, const f32 scaleY,
const u32 color, const int frame) ;
const int frame) ;
void GRRLIB_DrawPart (const f32 xpos, const f32 ypos, const f32 partx, const f32 party, const f32 partw, const f32 parth, const GRRLIB_texImg *tex,
const f32 degrees, const f32 scaleX, const f32 scaleY,
const u32 color);
void GRRLIB_DrawPart (const f32 xpos, const f32 ypos, const f32 partx, const f32 party,
const f32 partw, const f32 parth, const GRRLIB_texImg *tex);
void GRRLIB_DrawTileQuad (const guVector pos[4], GRRLIB_texImg *tex,
const u32 color, const int frame) ;
void GRRLIB_DrawTileQuad (const guVector pos[4], GRRLIB_texImg *tex, const int frame) ;
void GRRLIB_Render (void) ;

View file

@ -20,6 +20,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
------------------------------------------------------------------------------*/
extern GRRLIB_drawSettings GRRLIB_Settings;
/**
* @file GRRLIB_fbSimple.h
* Inline functions for primitive point and line drawing.
@ -31,23 +34,23 @@ THE SOFTWARE.
*/
INLINE
void GRRLIB_FillScreen (const u32 color) {
GRRLIB_Rectangle(-40, -40,
rmode->fbWidth +80, rmode->xfbHeight +80,
color, 1);
u32 tmpColor = GRRLIB_Settings.colorRGBA;
GRRLIB_SetColorRGBA(color);
GRRLIB_Rectangle(-40, -40, rmode->fbWidth +80, rmode->xfbHeight +80, 1);
GRRLIB_SetColorRGBA(tmpColor);
}
/**
* Draw a dot.
* @param x Specifies the x-coordinate of the dot.
* @param y Specifies the y-coordinate of the dot.
* @param color The color of the dot in RGBA format.
* @author Jespa
*/
INLINE
void GRRLIB_Plot (const f32 x, const f32 y, const u32 color) {
void GRRLIB_Plot (const f32 x, const f32 y) {
GX_Begin(GX_POINTS, GX_VTXFMT0, 1);
GX_Position3f32(x, y, 0);
GX_Color1u32(color);
GX_Color1u32(GRRLIB_Settings.colorRGBA);
GX_End();
}
@ -57,17 +60,16 @@ void GRRLIB_Plot (const f32 x, const f32 y, const u32 color) {
* @param y1 Starting point for line for the y coordinate.
* @param x2 Ending point for line for the x coordinate.
* @param y2 Ending point for line for the x coordinate.
* @param color Line color in RGBA format.
* @author JESPA
*/
INLINE
void GRRLIB_Line (const f32 x1, const f32 y1,
const f32 x2, const f32 y2, const u32 color) {
const f32 x2, const f32 y2) {
GX_Begin(GX_LINES, GX_VTXFMT0, 2);
GX_Position3f32(x1, y1, 0);
GX_Color1u32(color);
GX_Color1u32(GRRLIB_Settings.colorRGBA);
GX_Position3f32(x2, y2, 0);
GX_Color1u32(color);
GX_Color1u32(GRRLIB_Settings.colorRGBA);
GX_End();
}
@ -77,15 +79,20 @@ void GRRLIB_Line (const f32 x1, const f32 y1,
* @param y Specifies the y-coordinate of the upper-left corner of the rectangle.
* @param width The width of the rectangle.
* @param height The height of the rectangle.
* @param color The color of the rectangle in RGBA format.
* @param filled Set to true to fill the rectangle.
*/
INLINE
void GRRLIB_Rectangle (const f32 x, const f32 y,
const f32 width, const f32 height,
const u32 color, const u8 filled) {
f32 x2 = x + width;
f32 y2 = y + height;
const u8 filled) {
// Get current drawing settings.
u32 color = GRRLIB_Settings.colorRGBA;
f32 scaleX = GRRLIB_Settings.scaleX;
f32 scaleY = GRRLIB_Settings.scaleY;
f32 x2 = x + width * scaleX;
f32 y2 = y + height * scaleY;
if (filled) {
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);

View file

@ -81,3 +81,151 @@ INLINE
bool GRRLIB_GetAntiAliasing (void) {
return GRRLIB_Settings.antialias;
}
/**
* Set global rendering color.
* @param r Red component of color.
* @param g Green component of color.
* @param b Blue component of color.
*/
INLINE
void GRRLIB_SetColor (const u8 r, const u8 g, const u8 b) {
GRRLIB_Settings.colorR = r;
GRRLIB_Settings.colorG = g;
GRRLIB_Settings.colorB = b;
GRRLIB_Settings.colorRGBA = RGBA(r, g, b, GRRLIB_Settings.colorA);
}
/**
* Set global rendering color in RGBA-format.
* @param color Color in RGBA-format.
*/
INLINE
void GRRLIB_SetColorRGBA (const u32 color) {
GRRLIB_Settings.colorR = R(color);
GRRLIB_Settings.colorG = G(color);
GRRLIB_Settings.colorB = B(color);
GRRLIB_Settings.colorA = A(color);
GRRLIB_Settings.colorRGBA = color;
}
/**
* Set global rendering color in RGB-format.
* @param a Alpha component of color.
*/
INLINE
void GRRLIB_SetAlpha (const u32 alpha) {
GRRLIB_Settings.colorA = alpha;
GRRLIB_Settings.colorRGBA = RGBA(GRRLIB_Settings.colorR, GRRLIB_Settings.colorG, GRRLIB_Settings.colorB, alpha);
}
/**
* Get red component of current color.
* @return Red component of color.
*/
INLINE
u8 GRRLIB_GetColorRed (void) {
return GRRLIB_Settings.colorR;
}
/**
* Get green component of current color.
* @return Green component of color.
*/
INLINE
u8 GRRLIB_GetColorGreen (void) {
return GRRLIB_Settings.colorG;
}
/**
* Get blue component of current color.
* @return Blue component of color.
*/
INLINE
u8 GRRLIB_GetColorBlue (void) {
return GRRLIB_Settings.colorB;
}
/**
* Get current alpha.
* @return Alpha.
*/
INLINE
u8 GRRLIB_GetAlpha (void) {
return GRRLIB_Settings.colorA;
}
/**
* Set global rotation.
* @param rot Rotation in degrees.
*/
INLINE
void GRRLIB_SetRotation (const f32 rot) {
GRRLIB_Settings.rotation = rot;
}
/**
* Get current rotation.
* @return Rotation in degrees.
*/
INLINE
f32 GRRLIB_GetRotation (void) {
return GRRLIB_Settings.rotation;
}
/**
* Set global drawing scale.
* @param sx Horizontal scale.
* @param sy Vertical scale.
*/
INLINE
void GRRLIB_SetScale (const f32 sx, const f32 sy) {
GRRLIB_Settings.scaleX = sx;
GRRLIB_Settings.scaleY = sy;
}
/**
* Set global horizontal drawing scale.
* @param sx Horizontal scale.
*/
INLINE
void GRRLIB_SetScaleX (const f32 sx) {
GRRLIB_Settings.scaleX = sx;
}
/**
* Set global vertical drawing scale.
* @param sy Vertical scale.
*/
INLINE
void GRRLIB_SetScaleY (const f32 sy) {
GRRLIB_Settings.scaleY = sy;
}
/**
* Get current horizontal scale
* @return Horizontal scale.
*/
INLINE
f32 GRRLIB_GetScaleX (void) {
return GRRLIB_Settings.scaleX;
}
/**
* Get current vertical scale
* @return Vertical scale.
*/
INLINE
f32 GRRLIB_GetScaleY (void) {
return GRRLIB_Settings.scaleY;
}
/**
* Reset global drawing settings to default.
*/
INLINE
void GRRLIB_ResetSettings (void) {
GRRLIB_SetColorRGBA( 0xFFFFFFFF );
GRRLIB_SetScale( 1.0f, 1.0f );
GRRLIB_SetRotation( 0.0f );
}