mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-22 15:02:20 +00:00
[ADD] Added a basic struct for image settings.
[ADD] Added GRRLIB_SetAntiAlias to turn AntiAliasing on/off. It's enabled by default.
This commit is contained in:
parent
6c33b53d49
commit
f979db4aa4
2 changed files with 109 additions and 77 deletions
|
@ -24,6 +24,16 @@ GXRModeObj *rmode;
|
|||
void *gp_fifo = NULL;
|
||||
|
||||
static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int width, const unsigned int height);
|
||||
static GRRLIB_drawSettings GRRLIB_Settings;
|
||||
|
||||
|
||||
/**
|
||||
* Turn AntiAliasing on/off
|
||||
* @param aa Set to true to enable AntiAliasing. (Default: Enabled)
|
||||
*/
|
||||
void GRRLIB_SetAntiAliasing( bool aa ) {
|
||||
GRRLIB_Settings.antialias = aa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear screen with a specific color.
|
||||
|
@ -142,44 +152,6 @@ void GRRLIB_NGoneFilled(Vector v[], u32 color, long n) {
|
|||
GRRLIB_GXEngine(v, color, n, GX_TRIANGLEFAN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a tile set.
|
||||
* @param tex The texture to initialize.
|
||||
* @param tilew Width of the tile.
|
||||
* @param tileh Height of the tile.
|
||||
* @param tilestart Offset for starting position. (Used in fonts)
|
||||
*/
|
||||
void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned int tileh, unsigned int tilestart) {
|
||||
tex->tilew = tilew;
|
||||
tex->tileh = tileh;
|
||||
if (tilew) // Avoid division by zero
|
||||
tex->nbtilew = tex->w / tilew;
|
||||
if (tileh) // Avoid division by zero
|
||||
tex->nbtileh = tex->h / tileh;
|
||||
tex->tilestart = tilestart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a texture from a buffer.
|
||||
* @param my_png the PNG buffer to load.
|
||||
* @return A GRRLIB_texImg structure filled with image informations.
|
||||
*/
|
||||
GRRLIB_texImg GRRLIB_LoadTexturePNG(const unsigned char my_png[]) {
|
||||
PNGUPROP imgProp;
|
||||
IMGCTX ctx;
|
||||
GRRLIB_texImg my_texture;
|
||||
|
||||
ctx = PNGU_SelectImageFromBuffer(my_png);
|
||||
PNGU_GetImageProperties(ctx, &imgProp);
|
||||
my_texture.data = memalign(32, imgProp.imgWidth * imgProp.imgHeight * 4);
|
||||
PNGU_DecodeTo4x4RGBA8(ctx, imgProp.imgWidth, imgProp.imgHeight, my_texture.data, 255);
|
||||
PNGU_ReleaseImageContext(ctx);
|
||||
my_texture.w = imgProp.imgWidth;
|
||||
my_texture.h = imgProp.imgHeight;
|
||||
GRRLIB_SetHandle( &my_texture, 0, 0 );
|
||||
GRRLIB_FlushTex(my_texture);
|
||||
return my_texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a raw BMP (RGB, no alpha) to 4x4RGBA.
|
||||
|
@ -222,6 +194,46 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int
|
|||
} /* block */
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize a tile set.
|
||||
* @param tex The texture to initialize.
|
||||
* @param tilew Width of the tile.
|
||||
* @param tileh Height of the tile.
|
||||
* @param tilestart Offset for starting position. (Used in fonts)
|
||||
*/
|
||||
void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned int tileh, unsigned int tilestart) {
|
||||
tex->tilew = tilew;
|
||||
tex->tileh = tileh;
|
||||
if (tilew) // Avoid division by zero
|
||||
tex->nbtilew = tex->w / tilew;
|
||||
if (tileh) // Avoid division by zero
|
||||
tex->nbtileh = tex->h / tileh;
|
||||
tex->tilestart = tilestart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a texture from a buffer.
|
||||
* @param my_png the PNG buffer to load.
|
||||
* @return A GRRLIB_texImg structure filled with image informations.
|
||||
*/
|
||||
GRRLIB_texImg GRRLIB_LoadTexturePNG(const unsigned char my_png[]) {
|
||||
PNGUPROP imgProp;
|
||||
IMGCTX ctx;
|
||||
GRRLIB_texImg my_texture;
|
||||
|
||||
ctx = PNGU_SelectImageFromBuffer(my_png);
|
||||
PNGU_GetImageProperties(ctx, &imgProp);
|
||||
my_texture.data = memalign(32, imgProp.imgWidth * imgProp.imgHeight * 4);
|
||||
PNGU_DecodeTo4x4RGBA8(ctx, imgProp.imgWidth, imgProp.imgHeight, my_texture.data, 255);
|
||||
PNGU_ReleaseImageContext(ctx);
|
||||
my_texture.w = imgProp.imgWidth;
|
||||
my_texture.h = imgProp.imgHeight;
|
||||
GRRLIB_SetHandle( &my_texture, 0, 0 );
|
||||
GRRLIB_FlushTex(my_texture);
|
||||
return my_texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a texture from a buffer.
|
||||
* Take care to have the JPG finnish with 0xFF 0xD9!!
|
||||
|
@ -450,7 +462,7 @@ inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees,
|
|||
Mtx m, m1, m2, mv;
|
||||
|
||||
GX_InitTexObj(&texObj, tex.data, tex.w, tex.h, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
|
||||
GX_InitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1);
|
||||
if (GRRLIB_Settings.antialias == false) { GX_InitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1); }
|
||||
GX_LoadTexObj(&texObj, GX_TEXMAP0);
|
||||
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
|
@ -466,24 +478,24 @@ inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees,
|
|||
|
||||
guMtxTransApply(m, m, xpos+width+tex.handlex-tex.offsetx+(scaleX*( -tex.handley*sin(-DegToRad(degrees)) - tex.handlex*cos(-DegToRad(degrees)) )), ypos+height+tex.handley-tex.offsety+(scaleX*( -tex.handley*cos(-DegToRad(degrees)) + tex.handlex*sin(-DegToRad(degrees)) )), 0);
|
||||
guMtxConcat(GXmodelView2D, m, mv);
|
||||
|
||||
GX_LoadPosMtxImm(mv, GX_PNMTX0);
|
||||
|
||||
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
|
||||
GX_Position3f32(-width, -height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(0, 0);
|
||||
|
||||
GX_Position3f32(width, -height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(1, 0);
|
||||
|
||||
GX_Position3f32(width, height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(1, 1);
|
||||
|
||||
GX_Position3f32(-width, height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(0, 1);
|
||||
GX_Position3f32(-width, -height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(0, 0);
|
||||
|
||||
GX_Position3f32(width, -height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(1, 0);
|
||||
|
||||
GX_Position3f32(width, height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(1, 1);
|
||||
|
||||
GX_Position3f32(-width, height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(0, 1);
|
||||
GX_End();
|
||||
GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0);
|
||||
|
||||
|
@ -515,7 +527,7 @@ inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees
|
|||
f32 t2 = (((int)(frame/tex.nbtilew)+1)/(f32)tex.nbtileh)-(FRAME_CORR/tex.h);
|
||||
|
||||
GX_InitTexObj(&texObj, tex.data, tex.tilew*tex.nbtilew, tex.tileh*tex.nbtileh, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
|
||||
GX_InitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1);
|
||||
if (GRRLIB_Settings.antialias == false) { GX_InitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1); }
|
||||
GX_LoadTexObj(&texObj, GX_TEXMAP0);
|
||||
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||
|
@ -525,28 +537,30 @@ inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees
|
|||
height = tex.tileh * 0.5f;
|
||||
guMtxIdentity(m1);
|
||||
guMtxScaleApply(m1, m1, scaleX, scaleY, 1.0f);
|
||||
|
||||
Vector axis = (Vector) {0, 0, 1 };
|
||||
guMtxRotAxisDeg(m2, &axis, degrees);
|
||||
guMtxConcat(m2, m1, m);
|
||||
guMtxTransApply(m, m, xpos+width, ypos+height, 0);
|
||||
guMtxTransApply(m, m, xpos+width+tex.handlex-tex.offsetx+(scaleX*( -tex.handley*sin(-DegToRad(degrees)) - tex.handlex*cos(-DegToRad(degrees)) )), ypos+height+tex.handley-tex.offsety+(scaleX*( -tex.handley*cos(-DegToRad(degrees)) + tex.handlex*sin(-DegToRad(degrees)) )), 0);
|
||||
guMtxConcat(GXmodelView2D, m, mv);
|
||||
|
||||
GX_LoadPosMtxImm(mv, GX_PNMTX0);
|
||||
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
|
||||
GX_Position3f32(-width, -height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(s1, t1);
|
||||
|
||||
GX_Position3f32(width, -height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(s2, t1);
|
||||
|
||||
GX_Position3f32(width, height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(s2, t2);
|
||||
|
||||
GX_Position3f32(-width, height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(s1, t2);
|
||||
GX_Position3f32(-width, -height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(s1, t1);
|
||||
|
||||
GX_Position3f32(width, -height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(s2, t1);
|
||||
|
||||
GX_Position3f32(width, height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(s2, t2);
|
||||
|
||||
GX_Position3f32(-width, height, 0);
|
||||
GX_Color1u32(color);
|
||||
GX_TexCoord2f32(s1, t2);
|
||||
GX_End();
|
||||
GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0);
|
||||
|
||||
|
@ -657,8 +671,13 @@ void GRRLIB_ClipReset() {
|
|||
* @param y The handle's y-coordinate
|
||||
*/
|
||||
void GRRLIB_SetHandle( GRRLIB_texImg * tex, int x, int y ) {
|
||||
tex->handlex = -(tex->w/2) + x;
|
||||
tex->handley = -(tex->h/2) + y;
|
||||
if (tex->tilew) {
|
||||
tex->handlex = -(tex->tilew/2) + x;
|
||||
tex->handley = -(tex->tileh/2) + y;
|
||||
} else {
|
||||
tex->handlex = -(tex->w/2) + x;
|
||||
tex->handley = -(tex->h/2) + y;
|
||||
}
|
||||
tex->offsetx = x;
|
||||
tex->offsety = y;
|
||||
}
|
||||
|
@ -1019,6 +1038,9 @@ void GRRLIB_Init() {
|
|||
|
||||
GX_SetCullMode(GX_CULL_NONE);
|
||||
VIDEO_SetBlack(false);
|
||||
|
||||
// Default settings
|
||||
GRRLIB_Settings.antialias = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,10 +19,18 @@
|
|||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/**
|
||||
* Structure to hold the current drawing settings.
|
||||
*/
|
||||
typedef struct GRRLIB_drawSettings {
|
||||
bool antialias; /**< Flag for AntiAlias On/Off */
|
||||
} GRRLIB_drawSettings;
|
||||
|
||||
/**
|
||||
* Structure to hold the texture informations.
|
||||
*/
|
||||
typedef struct GRRLIB_texImg{
|
||||
typedef struct GRRLIB_texImg {
|
||||
unsigned int w; /**< Width of the texture. */
|
||||
unsigned int h; /**< Height of the texture. */
|
||||
int handlex; /**< handle x of the texture */
|
||||
|
@ -40,7 +48,7 @@ typedef struct GRRLIB_texImg{
|
|||
/**
|
||||
* Structure to hold the bytemap character informations.
|
||||
*/
|
||||
typedef struct GRRLIB_bytemapChar{
|
||||
typedef struct GRRLIB_bytemapChar {
|
||||
u8 character; /**< Which character. */
|
||||
u8 width; /**< Character width. */
|
||||
u8 height; /**< Character height. */
|
||||
|
@ -53,7 +61,7 @@ typedef struct GRRLIB_bytemapChar{
|
|||
/**
|
||||
* Structure to hold the bytemap font informations.
|
||||
*/
|
||||
typedef struct GRRLIB_bytemapFont{
|
||||
typedef struct GRRLIB_bytemapFont {
|
||||
u8 version; /**< Version. */
|
||||
s8 addSpace; /**< Add-space after each char (-128 to 127). */
|
||||
u32 *palette; /**< Font palette. */
|
||||
|
@ -65,6 +73,8 @@ typedef struct GRRLIB_bytemapFont{
|
|||
|
||||
extern Mtx GXmodelView2D;
|
||||
|
||||
void GRRLIB_SetAntiAliasing( bool aa );
|
||||
|
||||
inline void GRRLIB_FillScreen(u32 color);
|
||||
|
||||
inline void GRRLIB_Plot(f32 x, f32 y, u32 color);
|
||||
|
|
Loading…
Reference in a new issue