[CHG] Pure cosmetic update - Made the code more readable and fixed some spelling errors.

This commit is contained in:
Xane 2009-03-07 22:21:43 +00:00
parent c2086fbf93
commit fc6019ae7b

View file

@ -27,7 +27,7 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int
/** /**
* Clear screen with a specific color. * Clear screen with a specific color.
* @param color the color to use to fill the screen. * @param color The color to use to fill the screen.
*/ */
inline void GRRLIB_FillScreen(u32 color) { inline void GRRLIB_FillScreen(u32 color) {
GRRLIB_Rectangle(-40, -40, 680, 520, color, 1); GRRLIB_Rectangle(-40, -40, 680, 520, color, 1);
@ -35,9 +35,9 @@ inline void GRRLIB_FillScreen(u32 color) {
/** /**
* Draw a dot. * Draw a dot.
* @param x specifies the x-coordinate of the dot. * @param x Specifies the x-coordinate of the dot.
* @param y specifies the y-coordinate of the dot. * @param y Specifies the y-coordinate of the dot.
* @param color the color of the dot in RGBA format. * @param color The color of the dot in RGBA format.
*/ */
inline void GRRLIB_Plot(f32 x, f32 y, u32 color) { inline void GRRLIB_Plot(f32 x, f32 y, u32 color) {
Vector v[] = {{x,y,0.0f}}; Vector v[] = {{x,y,0.0f}};
@ -47,9 +47,9 @@ inline void GRRLIB_Plot(f32 x, f32 y, u32 color) {
/** /**
* Draw an array of points. * Draw an array of points.
* @param v array containing the points. * @param v Array containing the points.
* @param color the color of the points in RGBA format. * @param color The color of the points in RGBA format.
* @param n number of points in the vector array. * @param n Number of points in the vector array.
*/ */
void GRRLIB_NPlot(Vector v[], u32 color, long n) { void GRRLIB_NPlot(Vector v[], u32 color, long n) {
GRRLIB_GXEngine(v, color, n, GX_POINTS); GRRLIB_GXEngine(v, color, n, GX_POINTS);
@ -57,11 +57,11 @@ void GRRLIB_NPlot(Vector v[], u32 color, long n) {
/** /**
* Draw a line. * Draw a line.
* @param x1 start point for line for the x coordinate. * @param x1 Starting point for line for the x coordinate.
* @param y1 start point for line for the y coordinate. * @param y1 Starting point for line for the y coordinate.
* @param x2 end point for line for the x coordinate. * @param x2 Ending point for line for the x coordinate.
* @param y2 end point for line for the x coordinate. * @param y2 Ending point for line for the x coordinate.
* @param color line color in RGBA format. * @param color Line color in RGBA format.
*/ */
inline void GRRLIB_Line(f32 x1, f32 y1, f32 x2, f32 y2, u32 color) { inline void GRRLIB_Line(f32 x1, f32 y1, f32 x2, f32 y2, u32 color) {
Vector v[] = {{x1,y1,0.0f}, {x2,y2,0.0f}}; Vector v[] = {{x1,y1,0.0f}, {x2,y2,0.0f}};
@ -71,22 +71,22 @@ inline void GRRLIB_Line(f32 x1, f32 y1, f32 x2, f32 y2, u32 color) {
/** /**
* Draw a rectangle. * Draw a rectangle.
* @param x specifies the x-coordinate of the upper-left corner of the rectangle. * @param x Specifies the x-coordinate of the upper-left corner of the rectangle.
* @param y specifies the y-coordinate of the upper-left corner of the rectangle. * @param y Specifies the y-coordinate of the upper-left corner of the rectangle.
* @param width the width of the rectangle. * @param width The width of the rectangle.
* @param height the height of the rectangle. * @param height The height of the rectangle.
* @param color the color of the rectangle in RGBA format. * @param color The color of the rectangle in RGBA format.
* @param filled true to fill the rectangle with a color. * @param filled Set to true to fill the rectangle.
*/ */
inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8 filled) { inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8 filled) {
f32 x2 = x+width; f32 x2 = x+width;
f32 y2 = y+height; f32 y2 = y+height;
Vector v[] = {{x,y,0.0f}, {x2,y,0.0f}, {x2,y2,0.0f}, {x,y2,0.0f}, {x,y,0.0f}}; Vector v[] = {{x,y,0.0f}, {x2,y,0.0f}, {x2,y2,0.0f}, {x,y2,0.0f}, {x,y,0.0f}};
if(!filled) { if (!filled) {
GRRLIB_NGone(v, color, 5); GRRLIB_NGone(v, color, 5);
} }
else{ else {
GRRLIB_NGoneFilled(v, color, 4); GRRLIB_NGoneFilled(v, color, 4);
} }
} }
@ -94,11 +94,11 @@ inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8
/** /**
* Draw a circle. * Draw a circle.
* @author Dark_Link * @author Dark_Link
* @param x * @param x Specifies the x-coordinate of the circle.
* @param y * @param y Specifies the y-coordinate of the circle.
* @param radius the radius of the circle. * @param radius The radius of the circle.
* @param color the color of the circle in RGBA format. * @param color The color of the circle in RGBA format.
* @param filled true to fill the circle with a color. * @param filled Set to true to fill the circle.
*/ */
inline void GRRLIB_Circle(f32 x, f32 y, f32 radius, u32 color, u8 filled) { inline void GRRLIB_Circle(f32 x, f32 y, f32 radius, u32 color, u8 filled) {
Vector v[36]; Vector v[36];
@ -124,9 +124,9 @@ inline void GRRLIB_Circle(f32 x, f32 y, f32 radius, u32 color, u8 filled) {
/** /**
* Draw a polygon. * Draw a polygon.
* @param v * @param v The vector containing the coordinates of the polygon.
* @param color the color of the polygon in RGBA format. * @param color The color of the filled polygon in RGBA format.
* @param n * @param n Number of points in the vector.
*/ */
void GRRLIB_NGone(Vector v[], u32 color, long n) { void GRRLIB_NGone(Vector v[], u32 color, long n) {
GRRLIB_GXEngine(v, color, n, GX_LINESTRIP); GRRLIB_GXEngine(v, color, n, GX_LINESTRIP);
@ -134,9 +134,9 @@ void GRRLIB_NGone(Vector v[], u32 color, long n) {
/** /**
* Draw a filled polygon. * Draw a filled polygon.
* @param v * @param v The vector containing the coordinates of the polygon.
* @param color the color of the filled polygon in RGBA format. * @param color The color of the filled polygon in RGBA format.
* @param n * @param n Number of points in the vector.
*/ */
void GRRLIB_NGoneFilled(Vector v[], u32 color, long n) { void GRRLIB_NGoneFilled(Vector v[], u32 color, long n) {
GRRLIB_GXEngine(v, color, n, GX_TRIANGLEFAN); GRRLIB_GXEngine(v, color, n, GX_TRIANGLEFAN);
@ -144,17 +144,17 @@ void GRRLIB_NGoneFilled(Vector v[], u32 color, long n) {
/** /**
* Initialize a tile set. * Initialize a tile set.
* @param tex texture to initialize. * @param tex The texture to initialize.
* @param tilew widht of the tile. * @param tilew Width of the tile.
* @param tileh height of the tile. * @param tileh Height of the tile.
* @param tilestart offset for starting position. * @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) { void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned int tileh, unsigned int tilestart) {
tex->tilew = tilew; tex->tilew = tilew;
tex->tileh = tileh; tex->tileh = tileh;
if(tilew) // Avoid division by zero if (tilew) // Avoid division by zero
tex->nbtilew = tex->w / tilew; tex->nbtilew = tex->w / tilew;
if(tileh) // Avoid division by zero if (tileh) // Avoid division by zero
tex->nbtileh = tex->h / tileh; tex->nbtileh = tex->h / tileh;
tex->tilestart = tilestart; tex->tilestart = tilestart;
} }
@ -162,7 +162,7 @@ void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned
/** /**
* Load a texture from a buffer. * Load a texture from a buffer.
* @param my_png the PNG buffer to load. * @param my_png the PNG buffer to load.
* @return A GRRLIB_texImg structure filled with PNG informations. * @return A GRRLIB_texImg structure filled with image informations.
*/ */
GRRLIB_texImg GRRLIB_LoadTexturePNG(const unsigned char my_png[]) { GRRLIB_texImg GRRLIB_LoadTexturePNG(const unsigned char my_png[]) {
PNGUPROP imgProp; PNGUPROP imgProp;
@ -182,7 +182,7 @@ GRRLIB_texImg GRRLIB_LoadTexturePNG(const unsigned char my_png[]) {
} }
/** /**
* Convert a raw bmp (RGB, no alpha) to 4x4RGBA. * Convert a raw BMP (RGB, no alpha) to 4x4RGBA.
* @author DragonMinded * @author DragonMinded
* @param src * @param src
* @param dst * @param dst
@ -197,11 +197,11 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int
unsigned int gb; unsigned int gb;
unsigned char *p = (unsigned char*)dst; unsigned char *p = (unsigned char*)dst;
for(block = 0; block < height; block += 4) { for (block = 0; block < height; block += 4) {
for(i = 0; i < width; i += 4) { for (i = 0; i < width; i += 4) {
/* Alpha and Red */ /* Alpha and Red */
for(c = 0; c < 4; ++c) { for (c = 0; c < 4; ++c) {
for(ar = 0; ar < 4; ++ar) { for (ar = 0; ar < 4; ++ar) {
/* Alpha pixels */ /* Alpha pixels */
*p++ = 255; *p++ = 255;
/* Red pixels */ /* Red pixels */
@ -210,8 +210,8 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int
} }
/* Green and Blue */ /* Green and Blue */
for(c = 0; c < 4; ++c) { for (c = 0; c < 4; ++c) {
for(gb = 0; gb < 4; ++gb) { for (gb = 0; gb < 4; ++gb) {
/* Green pixels */ /* Green pixels */
*p++ = src[(((i + gb) + ((block + c) * width)) * 3) + 1]; *p++ = src[(((i + gb) + ((block + c) * width)) * 3) + 1];
/* Blue pixels */ /* Blue pixels */
@ -224,10 +224,10 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int
/** /**
* Load a texture from a buffer. * Load a texture from a buffer.
* Take Care to have a JPG finnishing by 0xFF 0xD9 !!!! * Take care to have the JPG finnish with 0xFF 0xD9!!
* @author DrTwox * @author DrTwox
* @param my_jpg the JPEG buffer to load. * @param my_jpg The JPEG buffer to load.
* @return A GRRLIB_texImg structure filled with PNG informations. * @return A GRRLIB_texImg structure filled with image informations.
*/ */
GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) { GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
struct jpeg_decompress_struct cinfo; struct jpeg_decompress_struct cinfo;
@ -236,9 +236,9 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
int n = 0; int n = 0;
unsigned int i; unsigned int i;
if((my_jpg[0]==0xff) && (my_jpg[1]==0xd8) && (my_jpg[2]==0xff)) { if ((my_jpg[0]==0xff) && (my_jpg[1]==0xd8) && (my_jpg[2]==0xff)) {
while(1) { while(true) {
if((my_jpg[n]==0xff) && (my_jpg[n+1]==0xd9)) if ((my_jpg[n]==0xff) && (my_jpg[n+1]==0xd9))
break; break;
n++; n++;
} }
@ -255,9 +255,9 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
JSAMPROW row_pointer[1]; JSAMPROW row_pointer[1];
row_pointer[0] = (unsigned char*) malloc(cinfo.output_width * cinfo.num_components); row_pointer[0] = (unsigned char*) malloc(cinfo.output_width * cinfo.num_components);
size_t location = 0; size_t location = 0;
while(cinfo.output_scanline < cinfo.output_height) { while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, row_pointer, 1); jpeg_read_scanlines(&cinfo, row_pointer, 1);
for(i = 0; i < cinfo.image_width * cinfo.num_components; i++) { for (i = 0; i < cinfo.image_width * cinfo.num_components; i++) {
/* Put the decoded scanline into the tempBuffer */ /* Put the decoded scanline into the tempBuffer */
tempBuffer[ location++ ] = row_pointer[0][i]; tempBuffer[ location++ ] = row_pointer[0][i];
} }
@ -267,7 +267,7 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
my_texture.data = memalign(32, cinfo.output_width * cinfo.output_height * 4); my_texture.data = memalign(32, cinfo.output_width * cinfo.output_height * 4);
RawTo4x4RGBA(tempBuffer, my_texture.data, cinfo.output_width, cinfo.output_height); RawTo4x4RGBA(tempBuffer, my_texture.data, cinfo.output_width, cinfo.output_height);
/* Done - do cleanup and release memory */ /* Done - Do cleanup and release allocated memory */
jpeg_finish_decompress(&cinfo); jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
free(row_pointer[0]); free(row_pointer[0]);
@ -283,11 +283,11 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
/** /**
* Print formatted output. * Print formatted output.
* @param xpos * @param xpos Specifies the x-coordinate of the upper-left corner of the text.
* @param ypos * @param ypos Specifies the y-coordinate of the upper-left corner of the text.
* @param bmf * @param bmf The ByteMap font to use.
* @param zoom * @param zoom This is a factor by which the text size will be increase or decrease.
* @param text text to draw. * @param text Text to draw.
* @param ... Optional arguments. * @param ... Optional arguments.
*/ */
void GRRLIB_PrintBMF(f32 xpos, f32 ypos, GRRLIB_bytemapFont bmf, f32 zoom, const char *text, ...) { void GRRLIB_PrintBMF(f32 xpos, f32 ypos, GRRLIB_bytemapFont bmf, f32 zoom, const char *text, ...) {
@ -301,13 +301,13 @@ void GRRLIB_PrintBMF(f32 xpos, f32 ypos, GRRLIB_bytemapFont bmf, f32 zoom, const
GRRLIB_texImg tex_BMfont = GRRLIB_CreateEmptyTexture(640, 480); GRRLIB_texImg tex_BMfont = GRRLIB_CreateEmptyTexture(640, 480);
for(i=0; i<size; i++) { for (i=0; i<size; i++) {
for(j=0; j<bmf.nbChar; j++) { for (j=0; j<bmf.nbChar; j++) {
if(tmp[i] == bmf.charDef[j].character) { if (tmp[i] == bmf.charDef[j].character) {
n=0; n=0;
for(y=0; y<bmf.charDef[j].height; y++) { for (y=0; y<bmf.charDef[j].height; y++) {
for(x=0; x<bmf.charDef[j].width; x++) { for (x=0; x<bmf.charDef[j].width; x++) {
if(bmf.charDef[j].data[n]) { if (bmf.charDef[j].data[n]) {
GRRLIB_SetPixelTotexImg(xpos + x + bmf.charDef[j].relx, ypos + y + bmf.charDef[j].rely, GRRLIB_SetPixelTotexImg(xpos + x + bmf.charDef[j].relx, ypos + y + bmf.charDef[j].rely,
tex_BMfont, bmf.palette[bmf.charDef[j].data[n]]); tex_BMfont, bmf.palette[bmf.charDef[j].data[n]]);
//GRRLIB_Plot(xpos + x + bmf.charDef[j].relx, ypos + y + bmf.charDef[j].rely, //GRRLIB_Plot(xpos + x + bmf.charDef[j].relx, ypos + y + bmf.charDef[j].rely,
@ -321,16 +321,15 @@ void GRRLIB_PrintBMF(f32 xpos, f32 ypos, GRRLIB_bytemapFont bmf, f32 zoom, const
} }
} }
} }
GRRLIB_FlushTex(tex_BMfont); GRRLIB_FlushTex(tex_BMfont);
GRRLIB_DrawImg(0, 0, tex_BMfont, 0, 1, 1, 0xFFFFFFFF); GRRLIB_DrawImg(0, 0, tex_BMfont, 0, 1, 1, 0xFFFFFFFF);
free(tex_BMfont.data); free(tex_BMfont.data);
} }
/** /**
* Load a ByteMap font structure from a buffer. * Load a ByteMap font structure from a buffer.
* @param my_bmf the ByteMap font buffer to load. * @param my_bmf The ByteMap font buffer to load.
* @return A GRRLIB_bytemapFont structure filled with BMF informations. * @return A GRRLIB_bytemapFont structure filled with BMF informations.
*/ */
GRRLIB_bytemapFont GRRLIB_LoadBMF(const unsigned char my_bmf[]) { GRRLIB_bytemapFont GRRLIB_LoadBMF(const unsigned char my_bmf[]) {
@ -343,7 +342,7 @@ GRRLIB_bytemapFont GRRLIB_LoadBMF(const unsigned char my_bmf[]) {
// Initialize everything to zero // Initialize everything to zero
memset(&fontArray, 0, sizeof(fontArray)); memset(&fontArray, 0, sizeof(fontArray));
if(my_bmf[0]==0xE1 && my_bmf[1]==0xE6 && my_bmf[2]==0xD5 && my_bmf[3]==0x1A) { if (my_bmf[0]==0xE1 && my_bmf[1]==0xE6 && my_bmf[2]==0xD5 && my_bmf[3]==0x1A) {
fontArray.version = my_bmf[4]; fontArray.version = my_bmf[4];
lineheight = my_bmf[5]; lineheight = my_bmf[5];
sizeover = my_bmf[6]; sizeover = my_bmf[6];
@ -355,7 +354,7 @@ GRRLIB_bytemapFont GRRLIB_LoadBMF(const unsigned char my_bmf[]) {
nbPalette = my_bmf[16]; nbPalette = my_bmf[16];
numcolpal = 3 * nbPalette; numcolpal = 3 * nbPalette;
fontArray.palette = (u32 *)calloc(nbPalette + 1, sizeof(u32)); fontArray.palette = (u32 *)calloc(nbPalette + 1, sizeof(u32));
for(i=0; i < numcolpal; i+=3) { for (i=0; i < numcolpal; i+=3) {
fontArray.palette[j++] = ((((my_bmf[i+17]<<2)+3)<<24) | (((my_bmf[i+18]<<2)+3)<<16) | (((my_bmf[i+19]<<2)+3)<<8) | 0xFF); fontArray.palette[j++] = ((((my_bmf[i+17]<<2)+3)<<24) | (((my_bmf[i+18]<<2)+3)<<16) | (((my_bmf[i+19]<<2)+3)<<8) | 0xFF);
} }
j = my_bmf[17 + numcolpal]; j = my_bmf[17 + numcolpal];
@ -365,7 +364,7 @@ GRRLIB_bytemapFont GRRLIB_LoadBMF(const unsigned char my_bmf[]) {
fontArray.nbChar = (my_bmf[j] | my_bmf[j+1]<<8); fontArray.nbChar = (my_bmf[j] | my_bmf[j+1]<<8);
fontArray.charDef = (GRRLIB_bytemapChar *)calloc(fontArray.nbChar, sizeof(GRRLIB_bytemapChar)); fontArray.charDef = (GRRLIB_bytemapChar *)calloc(fontArray.nbChar, sizeof(GRRLIB_bytemapChar));
j++; j++;
for(i=0; i < fontArray.nbChar; i++) { for (i=0; i < fontArray.nbChar; i++) {
fontArray.charDef[i].character = my_bmf[++j]; fontArray.charDef[i].character = my_bmf[++j];
fontArray.charDef[i].width = my_bmf[++j]; fontArray.charDef[i].width = my_bmf[++j];
fontArray.charDef[i].height = my_bmf[++j]; fontArray.charDef[i].height = my_bmf[++j];
@ -374,7 +373,7 @@ GRRLIB_bytemapFont GRRLIB_LoadBMF(const unsigned char my_bmf[]) {
fontArray.charDef[i].shift = my_bmf[++j]; fontArray.charDef[i].shift = my_bmf[++j];
nbPixels = fontArray.charDef[i].width * fontArray.charDef[i].height; nbPixels = fontArray.charDef[i].width * fontArray.charDef[i].height;
fontArray.charDef[i].data = malloc(nbPixels); fontArray.charDef[i].data = malloc(nbPixels);
if(nbPixels && fontArray.charDef[i].data) { if (nbPixels && fontArray.charDef[i].data) {
memcpy(fontArray.charDef[i].data, &my_bmf[++j], nbPixels); memcpy(fontArray.charDef[i].data, &my_bmf[++j], nbPixels);
j += (nbPixels - 1); j += (nbPixels - 1);
} }
@ -384,14 +383,13 @@ GRRLIB_bytemapFont GRRLIB_LoadBMF(const unsigned char my_bmf[]) {
} }
/** /**
* Free memory. * Free memory allocated by ByteMap fonts.
* @param bmf a GRRLIB_bytemapFont structure. * @param bmf a GRRLIB_bytemapFont structure.
*/ */
void GRRLIB_FreeBMF(GRRLIB_bytemapFont bmf) void GRRLIB_FreeBMF(GRRLIB_bytemapFont bmf) {
{
unsigned int i; unsigned int i;
for(i=0; i<bmf.nbChar; i++) { for (i=0; i<bmf.nbChar; i++) {
free(bmf.charDef[i].data); free(bmf.charDef[i].data);
} }
free(bmf.charDef); free(bmf.charDef);
@ -401,22 +399,22 @@ void GRRLIB_FreeBMF(GRRLIB_bytemapFont bmf)
/** /**
* Load a texture from a buffer. * Load a texture from a buffer.
* @param my_img the JPEG or PNG buffer to load. * @param my_img The JPEG or PNG buffer to load.
* @return A GRRLIB_texImg structure filled with imgage informations. * @return A GRRLIB_texImg structure filled with image informations.
*/ */
GRRLIB_texImg GRRLIB_LoadTexture(const unsigned char my_img[]) { GRRLIB_texImg GRRLIB_LoadTexture(const unsigned char my_img[]) {
if(my_img[0]==0xFF && my_img[1]==0xD8 && my_img[2]==0xFF) { if (my_img[0]==0xFF && my_img[1]==0xD8 && my_img[2]==0xFF) {
return(GRRLIB_LoadTextureJPG(my_img)); return (GRRLIB_LoadTextureJPG(my_img));
} }
else { else {
return(GRRLIB_LoadTexturePNG(my_img)); return (GRRLIB_LoadTexturePNG(my_img));
} }
} }
/** /**
* Create an empty texture. * Create an empty texture.
* @param w width of the new texture to create. * @param w Width of the new texture to create.
* @param h height of the new texture to create. * @param h Height of the new texture to create.
* @return A GRRLIB_texImg structure newly created. * @return A GRRLIB_texImg structure newly created.
*/ */
GRRLIB_texImg GRRLIB_CreateEmptyTexture(unsigned int w, unsigned int h) { GRRLIB_texImg GRRLIB_CreateEmptyTexture(unsigned int w, unsigned int h) {
@ -427,8 +425,8 @@ GRRLIB_texImg GRRLIB_CreateEmptyTexture(unsigned int w, unsigned int h) {
my_texture.w = w; my_texture.w = w;
my_texture.h = h; my_texture.h = h;
// Initialize the texture // Initialize the texture
for(y=0; y<h; y++) { for (y = 0; y < h; y++) {
for(x=0; x<w; x++) { for (x = 0; x < w; x++) {
GRRLIB_SetPixelTotexImg(x, y, my_texture, 0x00000000); GRRLIB_SetPixelTotexImg(x, y, my_texture, 0x00000000);
} }
} }
@ -438,13 +436,13 @@ GRRLIB_texImg GRRLIB_CreateEmptyTexture(unsigned int w, unsigned int h) {
/** /**
* Draw a texture. * Draw a texture.
* @param xpos specifies the x-coordinate of the upper-left corner. * @param xpos Specifies the x-coordinate of the upper-left corner.
* @param ypos specifies the y-coordinate of the upper-left corner. * @param ypos Specifies the y-coordinate of the upper-left corner.
* @param tex texture to draw. * @param tex The texture to draw.
* @param degrees angle of rotation. * @param degrees Angle of rotation.
* @param scaleX specifies the x-coordinate scale. -1 could be used for flipping the texture horizontally. * @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 scaleY Specifies the y-coordinate scale. -1 could be used for flipping the texture vertically.
* @param color * @param color Color in RGBA format.
*/ */
inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees, float scaleX, f32 scaleY, u32 color) { inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees, float scaleX, f32 scaleY, u32 color) {
GXTexObj texObj; GXTexObj texObj;
@ -495,14 +493,14 @@ inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees,
/** /**
* Draw a tile. * Draw a tile.
* @param xpos specifies the x-coordinate of the upper-left corner. * @param xpos Specifies the x-coordinate of the upper-left corner.
* @param ypos specifies the y-coordinate of the upper-left corner. * @param ypos Specifies the y-coordinate of the upper-left corner.
* @param tex texture containing the tile to draw. * @param tex The texture containing the tile to draw.
* @param degrees angle of rotation. * @param degrees Angle of rotation.
* @param scaleX specifies the x-coordinate scale. -1 could be used for flipping the texture horizontally. * @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 scaleY Specifies the y-coordinate scale. -1 could be used for flipping the texture vertically.
* @param color * @param color Color in RGBA format.
* @param frame specifies the frame to draw. * @param frame Specifies the frame to draw.
*/ */
inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees, float scaleX, f32 scaleY, u32 color, int frame) { inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees, float scaleX, f32 scaleY, u32 color, int frame) {
GXTexObj texObj; GXTexObj texObj;
@ -558,12 +556,12 @@ inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees
/** /**
* Print formatted output. * Print formatted output.
* @param xpos specifies the x-coordinate of the upper-left corner of the text. * @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 ypos Specifies the y-coordinate of the upper-left corner of the text.
* @param tex texture containing the character set. * @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 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 zoom This is a factor by which the text size will be increase or decrease.
* @param text text to draw. * @param text Text to draw.
* @param ... Optional arguments. * @param ... Optional arguments.
*/ */
void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, const char *text, ...) { void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, const char *text, ...) {
@ -575,20 +573,20 @@ void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, c
size = vsprintf(tmp, text, argp); size = vsprintf(tmp, text, argp);
va_end(argp); va_end(argp);
for(i=0; i<size; i++) { for (i = 0; i < size; i++) {
u8 c = tmp[i]-tex.tilestart; 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*zoom, ypos, tex, 0, zoom, zoom, color, c);
} }
} }
/** /**
* Determines whether the specified point lies within the specified rectangle. * Determine whether the specified point lies within the specified rectangle.
* @param hotx specifies the x-coordinate of the upper-left corner of the rectangle. * @param hotx Specifies the x-coordinate of the upper-left corner of the rectangle.
* @param hoty specifies the y-coordinate of the upper-left corner of the rectangle. * @param hoty Specifies the y-coordinate of the upper-left corner of the rectangle.
* @param hotw the width of the rectangle. * @param hotw The width of the rectangle.
* @param hoth the height of the rectangle. * @param hoth The height of the rectangle.
* @param wpadx specifies the x-coordinate of the point. * @param wpadx Specifies the x-coordinate of the point.
* @param wpady specifies the y-coordinate of the point. * @param wpady Specifies the y-coordinate of the point.
* @return If the specified point lies within the rectangle, the return value is true otherwise it's false. * @return If the specified point lies within the rectangle, the return value is true otherwise it's false.
*/ */
bool GRRLIB_PtInRect(int hotx, int hoty, int hotw, int hoth, int wpadx, int wpady) { bool GRRLIB_PtInRect(int hotx, int hoty, int hotw, int hoth, int wpadx, int wpady) {
@ -596,15 +594,15 @@ bool GRRLIB_PtInRect(int hotx, int hoty, int hotw, int hoth, int wpadx, int wpad
} }
/** /**
* Determines whether a specified rectangle lies within another rectangle. * Determine whether a specified rectangle lies within another rectangle.
* @param rect1x specifies the x-coordinate of the upper-left corner of the rectangle. * @param rect1x Specifies the x-coordinate of the upper-left corner of the rectangle.
* @param rect1y specifies the y-coordinate of the upper-left corner of the rectangle. * @param rect1y Specifies the y-coordinate of the upper-left corner of the rectangle.
* @param rect1w specifies the width of the rectangle. * @param rect1w Specifies the width of the rectangle.
* @param rect1h specifies the height of the rectangle. * @param rect1h Specifies the height of the rectangle.
* @param rect2x specifies the x-coordinate of the upper-left corner of the rectangle. * @param rect2x Specifies the x-coordinate of the upper-left corner of the rectangle.
* @param rect2y specifies the y-coordinate of the upper-left corner of the rectangle. * @param rect2y Specifies the y-coordinate of the upper-left corner of the rectangle.
* @param rect2w specifies the width of the rectangle. * @param rect2w Specifies the width of the rectangle.
* @param rect2h specifies the height of the rectangle. * @param rect2h Specifies the height of the rectangle.
* @return If the specified rectangle lies within the other rectangle, the return value is true otherwise it's false. * @return If the specified rectangle lies within the other rectangle, the return value is true otherwise it's false.
*/ */
bool GRRLIB_RectInRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2x, int rect2y, int rect2w, int rect2h) { bool GRRLIB_RectInRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2x, int rect2y, int rect2w, int rect2h) {
@ -613,15 +611,15 @@ bool GRRLIB_RectInRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2
} }
/** /**
* Determines whether a part of a specified rectangle lies on another rectangle. * Determine whether a part of a specified rectangle lies on another rectangle.
* @param rect1x specifies the x-coordinate of the upper-left corner of the first rectangle. * @param rect1x Specifies the x-coordinate of the upper-left corner of the first rectangle.
* @param rect1y specifies the y-coordinate of the upper-left corner of the first rectangle. * @param rect1y Specifies the y-coordinate of the upper-left corner of the first rectangle.
* @param rect1w specifies the width of the first rectangle. * @param rect1w Specifies the width of the first rectangle.
* @param rect1h specifies the height of the first rectangle. * @param rect1h Specifies the height of the first rectangle.
* @param rect2x specifies the x-coordinate of the upper-left corner of the second rectangle. * @param rect2x Specifies the x-coordinate of the upper-left corner of the second rectangle.
* @param rect2y specifies the y-coordinate of the upper-left corner of the second rectangle. * @param rect2y Specifies the y-coordinate of the upper-left corner of the second rectangle.
* @param rect2w specifies the width of the second rectangle. * @param rect2w Specifies the width of the second rectangle.
* @param rect2h specifies the height of the second rectangle. * @param rect2h Specifies the height of the second rectangle.
* @return If the specified rectangle lies on the other rectangle, the return value is true otherwise it's false. * @return If the specified rectangle lies on the other rectangle, the return value is true otherwise it's false.
*/ */
bool GRRLIB_RectOnRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2x, int rect2y, int rect2w, int rect2h) { bool GRRLIB_RectOnRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2x, int rect2y, int rect2w, int rect2h) {
@ -633,7 +631,7 @@ bool GRRLIB_RectOnRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2
/** /**
* Clips the drawing area to an rectangle * Clip the drawing area to an rectangle
* @param x The x-coordinate of the rectangle. * @param x The x-coordinate of the rectangle.
* @param y The y-coordinate of the rectangle. * @param y The y-coordinate of the rectangle.
* @param width The width of the rectangle. * @param width The width of the rectangle.
@ -645,17 +643,16 @@ void GRRLIB_ClipDrawing( int x, int y, int width, int height ) {
} }
/** /**
* Resets the clipping to normal * Reset the clipping to normal
*/ */
void GRRLIB_ClipReset() { void GRRLIB_ClipReset() {
GX_SetClipMode( GX_CLIP_DISABLE ); GX_SetClipMode( GX_CLIP_DISABLE );
GX_SetScissor( 0, 0, rmode->fbWidth, rmode->efbHeight ); GX_SetScissor( 0, 0, rmode->fbWidth, rmode->efbHeight );
} }
/** /**
* Sets a texture's X and Y handles. (e.g. for rotation) * Set a texture's X and Y handles. (e.g. for rotation)
* @param tex GRRLIB Texture * @param tex The texture to set the handle on.
* @param x The handle's x-coordinate * @param x The handle's x-coordinate
* @param y The handle's y-coordinate * @param y The handle's y-coordinate
*/ */
@ -667,8 +664,8 @@ void GRRLIB_SetHandle( GRRLIB_texImg * tex, int x, int y ) {
} }
/** /**
* Centers a texture's handles. (e.g. for rotation) * Center a texture's handles. (e.g. for rotation)
* @param tex GRRLIB Texture * @param tex The texture to center.
*/ */
void GRRLIB_SetMidHandle( GRRLIB_texImg * tex ) { void GRRLIB_SetMidHandle( GRRLIB_texImg * tex ) {
tex->handlex = 0; tex->handlex = 0;
@ -680,9 +677,9 @@ void GRRLIB_SetMidHandle( GRRLIB_texImg * tex ) {
/** /**
* Return the color value of a pixel from a GRRLIB_texImg. * Return the color value of a pixel from a GRRLIB_texImg.
* @param x specifies the x-coordinate of the pixel in the texture. * @param x Specifies the x-coordinate of the pixel in the texture.
* @param y specifies the y-coordinate of the pixel in the texture. * @param y Specifies the y-coordinate of the pixel in the texture.
* @param tex texture to get the color from. * @param tex The texture to get the color from.
* @return The color of a pixel in RGBA format. * @return The color of a pixel in RGBA format.
*/ */
u32 GRRLIB_GetPixelFromtexImg(int x, int y, GRRLIB_texImg tex) { u32 GRRLIB_GetPixelFromtexImg(int x, int y, GRRLIB_texImg tex) {
@ -697,16 +694,16 @@ u32 GRRLIB_GetPixelFromtexImg(int x, int y, GRRLIB_texImg tex) {
g=*(truc+offset+32); g=*(truc+offset+32);
b=*(truc+offset+33); b=*(truc+offset+33);
return((r<<24) | (g<<16) | (b<<8) | a); return ((r<<24) | (g<<16) | (b<<8) | a);
} }
/** /**
* Set the color value of a pixel to a GRRLIB_texImg. * Set the color value of a pixel to a GRRLIB_texImg.
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex
* @param x specifies the x-coordinate of the pixel in the texture. * @param x Specifies the x-coordinate of the pixel in the texture.
* @param y specifies the y-coordinate of the pixel in the texture. * @param y Specifies the y-coordinate of the pixel in the texture.
* @param tex texture to set the color to. * @param tex The texture to set the color to.
* @param color the color of the pixel in RGBA format. * @param color The color of the pixel in RGBA format.
*/ */
void GRRLIB_SetPixelTotexImg(int x, int y, GRRLIB_texImg tex, u32 color) { void GRRLIB_SetPixelTotexImg(int x, int y, GRRLIB_texImg tex, u32 color) {
u8 *truc = (u8*)tex.data; u8 *truc = (u8*)tex.data;
@ -721,28 +718,27 @@ void GRRLIB_SetPixelTotexImg(int x, int y, GRRLIB_texImg tex, u32 color) {
} }
/** /**
* Writes the contents of a texture in the data cache down to main memory. * Write the contents of a texture in the data cache down to main memory.
* For performance the CPU holds a data cache where modifications are stored before they get written down to mainmemory. * For performance the CPU holds a data cache where modifications are stored before they get written down to mainmemory.
* @param tex the texture to flush. * @param tex The texture to flush.
*/ */
void GRRLIB_FlushTex(GRRLIB_texImg tex) void GRRLIB_FlushTex(GRRLIB_texImg tex) {
{
DCFlushRange(tex.data, tex.w * tex.h * 4); DCFlushRange(tex.data, tex.w * tex.h * 4);
} }
/** /**
* Change a texture to gray scale. * Change a texture to gray scale.
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex
* @param texsrc the texture source. * @param texsrc The texture source.
* @param texdest the texture grayscaled destination. * @param texdest The texture grayscaled destination.
*/ */
void GRRLIB_BMFX_Grayscale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { void GRRLIB_BMFX_Grayscale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
unsigned int x, y; unsigned int x, y;
u8 gray; u8 gray;
u32 color; u32 color;
for(y=0; y<texsrc.h; y++) { for (y = 0; y < texsrc.h; y++) {
for(x=0; x<texsrc.w; x++) { for (x = 0; x < texsrc.w; x++) {
color = GRRLIB_GetPixelFromtexImg(x, y, texsrc); color = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
gray = (((color >> 24 & 0xFF)*77 + (color >> 16 & 0xFF)*150 + (color >> 8 & 0xFF)*28) / (255)); gray = (((color >> 24 & 0xFF)*77 + (color >> 16 & 0xFF)*150 + (color >> 8 & 0xFF)*28) / (255));
@ -756,17 +752,16 @@ void GRRLIB_BMFX_Grayscale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
/** /**
* Invert colors of the texture. * Invert colors of the texture.
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex
* @param texsrc the texture source. * @param texsrc The texture source.
* @param texdest the texture destination. * @param texdest The texture destination.
*/ */
void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
unsigned int x, y; unsigned int x, y;
u32 color; u32 color;
for(y=0; y<texsrc.h; y++) { for (y = 0; y < texsrc.h; y++) {
for(x=0; x<texsrc.w; x++) { for (x = 0; x < texsrc.w; x++) {
color = GRRLIB_GetPixelFromtexImg(x, y, texsrc); color = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
GRRLIB_SetPixelTotexImg(x, y, texdest, GRRLIB_SetPixelTotexImg(x, y, texdest,
((0xFFFFFF - (color >> 8 & 0xFFFFFF)) << 8) | (color & 0xFF)); ((0xFFFFFF - (color >> 8 & 0xFFFFFF)) << 8) | (color & 0xFF));
} }
@ -776,14 +771,14 @@ void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
/** /**
* Flip texture horizontal. * Flip texture horizontal.
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex
* @param texsrc the texture source. * @param texsrc The texture source.
* @param texdest the texture destination. * @param texdest The texture destination.
*/ */
void GRRLIB_BMFX_FlipH(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { void GRRLIB_BMFX_FlipH(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
unsigned int x, y, txtWidth = texsrc.w - 1; unsigned int x, y, txtWidth = texsrc.w - 1;
for(y=0; y<texsrc.h; y++) { for (y = 0; y < texsrc.h; y++) {
for(x=0; x<texsrc.w; x++) { for (x = 0; x < texsrc.w; x++) {
GRRLIB_SetPixelTotexImg(txtWidth - x, y, texdest, GRRLIB_SetPixelTotexImg(txtWidth - x, y, texdest,
GRRLIB_GetPixelFromtexImg(x, y, texsrc)); GRRLIB_GetPixelFromtexImg(x, y, texsrc));
} }
@ -793,14 +788,14 @@ void GRRLIB_BMFX_FlipH(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
/** /**
* Flip texture vertical. * Flip texture vertical.
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex
* @param texsrc the texture source. * @param texsrc The texture source.
* @param texdest the texture destination. * @param texdest The texture destination.
*/ */
void GRRLIB_BMFX_FlipV(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { void GRRLIB_BMFX_FlipV(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
unsigned int x, y, texHeight = texsrc.h - 1; unsigned int x, y, texHeight = texsrc.h - 1;
for(y=0; y<texsrc.h; y++) { for (y = 0; y < texsrc.h; y++) {
for(x=0; x<texsrc.w; x++) { for (x = 0; x < texsrc.w; x++) {
GRRLIB_SetPixelTotexImg(x, texHeight - y, texdest, GRRLIB_SetPixelTotexImg(x, texHeight - y, texdest,
GRRLIB_GetPixelFromtexImg(x, y, texsrc)); GRRLIB_GetPixelFromtexImg(x, y, texsrc));
} }
@ -808,11 +803,11 @@ void GRRLIB_BMFX_FlipV(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
} }
/** /**
* Blur a texture. * A texture effect. (Blur)
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex
* @param texsrc the texture source. * @param texsrc The texture source.
* @param texdest the texture destination. * @param texdest The texture destination.
* @param factor the blur factor. * @param factor The blur factor.
*/ */
void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) { void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
int numba = (1+(factor<<1))*(1+(factor<<1)); int numba = (1+(factor<<1))*(1+(factor<<1));
@ -824,8 +819,8 @@ void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
u32 colours[numba]; u32 colours[numba];
u32 thiscol; u32 thiscol;
for(x = 0; x < texsrc.w; x++) { for (x = 0; x < texsrc.w; x++) {
for(y = 0; y < texsrc.h; y++) { for (y = 0; y < texsrc.h; y++) {
newr = 0; newr = 0;
newg = 0; newg = 0;
newb = 0; newb = 0;
@ -834,18 +829,18 @@ void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
tmp=0; tmp=0;
thiscol = GRRLIB_GetPixelFromtexImg(x, y, texsrc); thiscol = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
for(k = x - factor; k <= x + factor; k++) { for (k = x - factor; k <= x + factor; k++) {
for(l = y - factor; l <= y + factor; l++) { for (l = y - factor; l <= y + factor; l++) {
if(k < 0) { colours[tmp] = thiscol; } if (k < 0) { colours[tmp] = thiscol; }
else if(k >= texsrc.w) { colours[tmp] = thiscol; } else if (k >= texsrc.w) { colours[tmp] = thiscol; }
else if(l < 0) { colours[tmp] = thiscol; } else if (l < 0) { colours[tmp] = thiscol; }
else if(l >= texsrc.h) { colours[tmp] = thiscol; } else if (l >= texsrc.h) { colours[tmp] = thiscol; }
else { colours[tmp] = GRRLIB_GetPixelFromtexImg(k, l, texsrc); } else { colours[tmp] = GRRLIB_GetPixelFromtexImg(k, l, texsrc); }
tmp++; tmp++;
} }
} }
for(tmp = 0; tmp < numba; tmp++) { for (tmp = 0; tmp < numba; tmp++) {
newr += (colours[tmp] >> 24) & 0xFF; newr += (colours[tmp] >> 24) & 0xFF;
newg += (colours[tmp] >> 16) & 0xFF; newg += (colours[tmp] >> 16) & 0xFF;
newb += (colours[tmp] >> 8) & 0xFF; newb += (colours[tmp] >> 8) & 0xFF;
@ -863,10 +858,10 @@ void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
} }
/** /**
* A texture effect. * A texture effect. (Pixelate)
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex
* @param texsrc the texture source. * @param texsrc The texture source.
* @param texdest the texture destination. * @param texdest The texture destination.
* @param factor The factor level of the effect. * @param factor The factor level of the effect.
*/ */
void GRRLIB_BMFX_Pixelate(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) { void GRRLIB_BMFX_Pixelate(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
@ -874,11 +869,11 @@ void GRRLIB_BMFX_Pixelate(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int facto
unsigned int xx, yy; unsigned int xx, yy;
u32 rgb; u32 rgb;
for(x=0; x<texsrc.w-1-factor; x+= factor) { for (x = 0; x < texsrc.w - 1 - factor; x += factor) {
for(y=0; y<texsrc.h-1-factor; y+=factor) { for (y = 0; y < texsrc.h - 1 - factor; y +=factor) {
rgb=GRRLIB_GetPixelFromtexImg(x, y, texsrc); rgb = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
for(xx=x; xx<x+factor; xx++) { for (xx = x; xx < x + factor; xx++) {
for(yy=y; yy<y+factor; yy++) { for (yy = y; yy < y + factor; yy++) {
GRRLIB_SetPixelTotexImg(xx, yy, texdest, rgb); GRRLIB_SetPixelTotexImg(xx, yy, texdest, rgb);
} }
} }
@ -887,10 +882,10 @@ void GRRLIB_BMFX_Pixelate(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int facto
} }
/** /**
* A texture effect. * A texture effect. (Scatter)
* @see GRRLIB_FlushTex * @see GRRLIB_FlushTex
* @param texsrc the texture source. * @param texsrc The texture source.
* @param texdest the texture destination. * @param texdest The texture destination.
* @param factor The factor level of the effect. * @param factor The factor level of the effect.
*/ */
void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) { void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
@ -899,12 +894,12 @@ void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor
u32 val3, val4; u32 val3, val4;
int factorx2 = factor*2; int factorx2 = factor*2;
for(y=0; y<texsrc.h; y++) { for (y = 0; y < texsrc.h; y++) {
for(x=0; x<texsrc.w; x++) { for (x = 0; x < texsrc.w; x++) {
val1 = x + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor; val1 = x + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor;
val2 = y + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor; val2 = y + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor;
if((val1 >= texsrc.w) || (val1 <0) || (val2 >= texsrc.h) || (val2 <0)) { if ((val1 >= texsrc.w) || (val1 < 0) || (val2 >= texsrc.h) || (val2 < 0)) {
} }
else { else {
val3 = GRRLIB_GetPixelFromtexImg(x, y, texsrc); val3 = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
@ -917,17 +912,13 @@ void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor
} }
/** /**
* * Draws a vector.
* @param v
* @param color
* @param n
* @param fmt
*/ */
void GRRLIB_GXEngine(Vector v[], u32 color, long n, u8 fmt) { void GRRLIB_GXEngine(Vector v[], u32 color, long n, u8 fmt) {
int i; int i;
GX_Begin(fmt, GX_VTXFMT0, n); GX_Begin(fmt, GX_VTXFMT0, n);
for(i=0; i<n; i++) { for (i = 0; i < n; i++) {
GX_Position3f32(v[i].x, v[i].y, v[i].z); GX_Position3f32(v[i].x, v[i].y, v[i].z);
GX_Color1u32(color); GX_Color1u32(color);
} }
@ -945,11 +936,11 @@ void GRRLIB_Init() {
VIDEO_Init(); VIDEO_Init();
rmode = VIDEO_GetPreferredMode(NULL); rmode = VIDEO_GetPreferredMode(NULL);
if(rmode == NULL) if (rmode == NULL)
return; return;
// Widescreen patch by CashMan's Productions (http://www.CashMan-Productions.fr.nf) // Widescreen patch by CashMan's Productions (http://www.CashMan-Productions.fr.nf)
if(CONF_GetAspectRatio() == CONF_ASPECT_16_9) { if (CONF_GetAspectRatio() == CONF_ASPECT_16_9) {
rmode->viWidth = 678; rmode->viWidth = 678;
rmode->viXOrigin = (VI_MAX_WIDTH_NTSC - 678)/2; rmode->viXOrigin = (VI_MAX_WIDTH_NTSC - 678)/2;
} }
@ -957,26 +948,26 @@ void GRRLIB_Init() {
VIDEO_Configure(rmode); VIDEO_Configure(rmode);
xfb[0] = (u32 *)MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); xfb[0] = (u32 *)MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
xfb[1] = (u32 *)MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); xfb[1] = (u32 *)MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
if(xfb[0] == NULL || xfb[1] == NULL) if (xfb[0] == NULL || xfb[1] == NULL)
return; return;
VIDEO_SetNextFramebuffer(xfb[fb]); VIDEO_SetNextFramebuffer(xfb[fb]);
VIDEO_SetBlack(FALSE); VIDEO_SetBlack(FALSE);
VIDEO_Flush(); VIDEO_Flush();
VIDEO_WaitVSync(); VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) if (rmode->viTVMode&VI_NON_INTERLACE)
VIDEO_WaitVSync(); VIDEO_WaitVSync();
gp_fifo = (u8 *) memalign(32, DEFAULT_FIFO_SIZE); gp_fifo = (u8 *) memalign(32, DEFAULT_FIFO_SIZE);
if(gp_fifo == NULL) if (gp_fifo == NULL)
return; return;
memset(gp_fifo, 0, DEFAULT_FIFO_SIZE); memset(gp_fifo, 0, DEFAULT_FIFO_SIZE);
GX_Init(gp_fifo, DEFAULT_FIFO_SIZE); GX_Init(gp_fifo, DEFAULT_FIFO_SIZE);
// clears the bg to color and clears the z buffer // Clears the BG to color and clears the z-buffer
GX_SetCopyClear((GXColor){ 0, 0, 0, 0xff }, GX_MAX_Z24); GX_SetCopyClear((GXColor){ 0, 0, 0, 0xff }, GX_MAX_Z24);
// other gx setup // Other GX setup
yscale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight); yscale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight);
xfbHeight = GX_SetDispCopyYScale(yscale); xfbHeight = GX_SetDispCopyYScale(yscale);
GX_SetScissor(0, 0, rmode->fbWidth, rmode->efbHeight); GX_SetScissor(0, 0, rmode->fbWidth, rmode->efbHeight);
@ -985,7 +976,7 @@ void GRRLIB_Init() {
GX_SetCopyFilter(rmode->aa, rmode->sample_pattern, GX_TRUE, rmode->vfilter); GX_SetCopyFilter(rmode->aa, rmode->sample_pattern, GX_TRUE, rmode->vfilter);
GX_SetFieldMode(rmode->field_rendering, ((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); GX_SetFieldMode(rmode->field_rendering, ((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE));
if(rmode->aa) if (rmode->aa)
GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR);
else else
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
@ -993,8 +984,8 @@ void GRRLIB_Init() {
GX_SetDispCopyGamma(GX_GM_1_0); GX_SetDispCopyGamma(GX_GM_1_0);
// setup the vertex descriptor // Setup the vertex descriptor
// tells the flipper to expect direct data // Tells the flipper to expect direct data
GX_ClearVtxDesc(); GX_ClearVtxDesc();
GX_InvVtxCache(); GX_InvVtxCache();
GX_InvalidateTexAll(); GX_InvalidateTexAll();
@ -1035,7 +1026,7 @@ void GRRLIB_Init() {
void GRRLIB_Render() { void GRRLIB_Render() {
GX_DrawDone(); GX_DrawDone();
fb ^= 1; // flip framebuffer fb ^= 1; // Flip framebuffer
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
GX_SetColorUpdate(GX_TRUE); GX_SetColorUpdate(GX_TRUE);
GX_CopyDisp(xfb[fb], GX_TRUE); GX_CopyDisp(xfb[fb], GX_TRUE);
@ -1049,21 +1040,21 @@ void GRRLIB_Render() {
*/ */
void GRRLIB_Exit() { void GRRLIB_Exit() {
GX_SetClipMode( GX_CLIP_DISABLE ); GX_SetClipMode( GX_CLIP_DISABLE );
GX_SetScissor( 0, 0, WinW, WinH ); GX_SetScissor( 0, 0, rmode->fbWidth, rmode->efbHeight );
GRRLIB_FillScreen( 0x000000FF ); GRRLIB_FillScreen( 0x000000FF );
GRRLIB_Render(); GRRLIB_Render();
GX_Flush(); GX_Flush();
GX_AbortFrame(); GX_AbortFrame();
if(xfb[0] != NULL) { if (xfb[0] != NULL) {
free(MEM_K1_TO_K0(xfb[0])); free(MEM_K1_TO_K0(xfb[0]));
xfb[0] = NULL; xfb[0] = NULL;
} }
if(xfb[1] != NULL) { if (xfb[1] != NULL) {
free(MEM_K1_TO_K0(xfb[1])); free(MEM_K1_TO_K0(xfb[1]));
xfb[1] = NULL; xfb[1] = NULL;
} }
if(gp_fifo != NULL) { if (gp_fifo != NULL) {
free(gp_fifo); free(gp_fifo);
gp_fifo = NULL; gp_fifo = NULL;
} }