mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-22 15:02:20 +00:00
[CHG] Pure cosmetic update - Made the code more readable and fixed some spelling errors.
This commit is contained in:
parent
c2086fbf93
commit
fc6019ae7b
1 changed files with 207 additions and 216 deletions
|
@ -27,7 +27,7 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int
|
|||
|
||||
/**
|
||||
* 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) {
|
||||
GRRLIB_Rectangle(-40, -40, 680, 520, color, 1);
|
||||
|
@ -35,9 +35,9 @@ inline void GRRLIB_FillScreen(u32 color) {
|
|||
|
||||
/**
|
||||
* 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.
|
||||
* @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.
|
||||
*/
|
||||
inline void GRRLIB_Plot(f32 x, f32 y, u32 color) {
|
||||
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.
|
||||
* @param v array containing the points.
|
||||
* @param color the color of the points in RGBA format.
|
||||
* @param n number of points in the vector array.
|
||||
* @param v Array containing the points.
|
||||
* @param color The color of the points in RGBA format.
|
||||
* @param n Number of points in the vector array.
|
||||
*/
|
||||
void GRRLIB_NPlot(Vector v[], u32 color, long n) {
|
||||
GRRLIB_GXEngine(v, color, n, GX_POINTS);
|
||||
|
@ -57,11 +57,11 @@ void GRRLIB_NPlot(Vector v[], u32 color, long n) {
|
|||
|
||||
/**
|
||||
* Draw a line.
|
||||
* @param x1 start point for line for the x coordinate.
|
||||
* @param y1 start point for line for the y coordinate.
|
||||
* @param x2 end point for line for the x coordinate.
|
||||
* @param y2 end point for line for the x coordinate.
|
||||
* @param color line color in RGBA format.
|
||||
* @param x1 Starting point for line for the x coordinate.
|
||||
* @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.
|
||||
*/
|
||||
inline void GRRLIB_Line(f32 x1, f32 y1, f32 x2, f32 y2, u32 color) {
|
||||
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.
|
||||
* @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 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 true to fill the rectangle with a color.
|
||||
* @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 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(f32 x, f32 y, f32 width, f32 height, u32 color, u8 filled) {
|
||||
f32 x2 = x+width;
|
||||
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}};
|
||||
|
||||
if(!filled) {
|
||||
if (!filled) {
|
||||
GRRLIB_NGone(v, color, 5);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
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.
|
||||
* @author Dark_Link
|
||||
* @param x
|
||||
* @param y
|
||||
* @param radius the radius of the circle.
|
||||
* @param color the color of the circle in RGBA format.
|
||||
* @param filled true to fill the circle with a color.
|
||||
* @param x Specifies the x-coordinate of the circle.
|
||||
* @param y Specifies the y-coordinate of the circle.
|
||||
* @param radius The radius of the circle.
|
||||
* @param color The color of the circle in RGBA format.
|
||||
* @param filled Set to true to fill the circle.
|
||||
*/
|
||||
inline void GRRLIB_Circle(f32 x, f32 y, f32 radius, u32 color, u8 filled) {
|
||||
Vector v[36];
|
||||
|
@ -124,9 +124,9 @@ inline void GRRLIB_Circle(f32 x, f32 y, f32 radius, u32 color, u8 filled) {
|
|||
|
||||
/**
|
||||
* Draw a polygon.
|
||||
* @param v
|
||||
* @param color the color of the polygon in RGBA format.
|
||||
* @param n
|
||||
* @param v The vector containing the coordinates of the polygon.
|
||||
* @param color The color of the filled polygon in RGBA format.
|
||||
* @param n Number of points in the vector.
|
||||
*/
|
||||
void GRRLIB_NGone(Vector v[], u32 color, long n) {
|
||||
GRRLIB_GXEngine(v, color, n, GX_LINESTRIP);
|
||||
|
@ -134,9 +134,9 @@ void GRRLIB_NGone(Vector v[], u32 color, long n) {
|
|||
|
||||
/**
|
||||
* Draw a filled polygon.
|
||||
* @param v
|
||||
* @param color the color of the filled polygon in RGBA format.
|
||||
* @param n
|
||||
* @param v The vector containing the coordinates of the polygon.
|
||||
* @param color The color of the filled polygon in RGBA format.
|
||||
* @param n Number of points in the vector.
|
||||
*/
|
||||
void GRRLIB_NGoneFilled(Vector v[], u32 color, long n) {
|
||||
GRRLIB_GXEngine(v, color, n, GX_TRIANGLEFAN);
|
||||
|
@ -144,17 +144,17 @@ void GRRLIB_NGoneFilled(Vector v[], u32 color, long n) {
|
|||
|
||||
/**
|
||||
* Initialize a tile set.
|
||||
* @param tex texture to initialize.
|
||||
* @param tilew widht of the tile.
|
||||
* @param tileh height of the tile.
|
||||
* @param tilestart offset for starting position.
|
||||
* @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
|
||||
if (tilew) // Avoid division by zero
|
||||
tex->nbtilew = tex->w / tilew;
|
||||
if(tileh) // Avoid division by zero
|
||||
if (tileh) // Avoid division by zero
|
||||
tex->nbtileh = tex->h / tileh;
|
||||
tex->tilestart = tilestart;
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned
|
|||
/**
|
||||
* Load a texture from a buffer.
|
||||
* @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[]) {
|
||||
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
|
||||
* @param src
|
||||
* @param dst
|
||||
|
@ -197,11 +197,11 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int
|
|||
unsigned int gb;
|
||||
unsigned char *p = (unsigned char*)dst;
|
||||
|
||||
for(block = 0; block < height; block += 4) {
|
||||
for(i = 0; i < width; i += 4) {
|
||||
for (block = 0; block < height; block += 4) {
|
||||
for (i = 0; i < width; i += 4) {
|
||||
/* Alpha and Red */
|
||||
for(c = 0; c < 4; ++c) {
|
||||
for(ar = 0; ar < 4; ++ar) {
|
||||
for (c = 0; c < 4; ++c) {
|
||||
for (ar = 0; ar < 4; ++ar) {
|
||||
/* Alpha pixels */
|
||||
*p++ = 255;
|
||||
/* Red pixels */
|
||||
|
@ -210,8 +210,8 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int
|
|||
}
|
||||
|
||||
/* Green and Blue */
|
||||
for(c = 0; c < 4; ++c) {
|
||||
for(gb = 0; gb < 4; ++gb) {
|
||||
for (c = 0; c < 4; ++c) {
|
||||
for (gb = 0; gb < 4; ++gb) {
|
||||
/* Green pixels */
|
||||
*p++ = src[(((i + gb) + ((block + c) * width)) * 3) + 1];
|
||||
/* Blue pixels */
|
||||
|
@ -224,10 +224,10 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int
|
|||
|
||||
/**
|
||||
* 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
|
||||
* @param my_jpg the JPEG buffer to load.
|
||||
* @return A GRRLIB_texImg structure filled with PNG informations.
|
||||
* @param my_jpg The JPEG buffer to load.
|
||||
* @return A GRRLIB_texImg structure filled with image informations.
|
||||
*/
|
||||
GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
|
@ -236,9 +236,9 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
|
|||
int n = 0;
|
||||
unsigned int i;
|
||||
|
||||
if((my_jpg[0]==0xff) && (my_jpg[1]==0xd8) && (my_jpg[2]==0xff)) {
|
||||
while(1) {
|
||||
if((my_jpg[n]==0xff) && (my_jpg[n+1]==0xd9))
|
||||
if ((my_jpg[0]==0xff) && (my_jpg[1]==0xd8) && (my_jpg[2]==0xff)) {
|
||||
while(true) {
|
||||
if ((my_jpg[n]==0xff) && (my_jpg[n+1]==0xd9))
|
||||
break;
|
||||
n++;
|
||||
}
|
||||
|
@ -255,9 +255,9 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
|
|||
JSAMPROW row_pointer[1];
|
||||
row_pointer[0] = (unsigned char*) malloc(cinfo.output_width * cinfo.num_components);
|
||||
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);
|
||||
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 */
|
||||
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);
|
||||
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_destroy_decompress(&cinfo);
|
||||
free(row_pointer[0]);
|
||||
|
@ -283,11 +283,11 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
|
|||
|
||||
/**
|
||||
* Print formatted output.
|
||||
* @param xpos
|
||||
* @param ypos
|
||||
* @param bmf
|
||||
* @param zoom
|
||||
* @param text text to draw.
|
||||
* @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 bmf The ByteMap font to use.
|
||||
* @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_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);
|
||||
|
||||
for(i=0; i<size; i++) {
|
||||
for(j=0; j<bmf.nbChar; j++) {
|
||||
if(tmp[i] == bmf.charDef[j].character) {
|
||||
for (i=0; i<size; i++) {
|
||||
for (j=0; j<bmf.nbChar; j++) {
|
||||
if (tmp[i] == bmf.charDef[j].character) {
|
||||
n=0;
|
||||
for(y=0; y<bmf.charDef[j].height; y++) {
|
||||
for(x=0; x<bmf.charDef[j].width; x++) {
|
||||
if(bmf.charDef[j].data[n]) {
|
||||
for (y=0; y<bmf.charDef[j].height; y++) {
|
||||
for (x=0; x<bmf.charDef[j].width; x++) {
|
||||
if (bmf.charDef[j].data[n]) {
|
||||
GRRLIB_SetPixelTotexImg(xpos + x + bmf.charDef[j].relx, ypos + y + bmf.charDef[j].rely,
|
||||
tex_BMfont, bmf.palette[bmf.charDef[j].data[n]]);
|
||||
//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_DrawImg(0, 0, tex_BMfont, 0, 1, 1, 0xFFFFFFFF);
|
||||
|
||||
free(tex_BMfont.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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
|
||||
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];
|
||||
lineheight = my_bmf[5];
|
||||
sizeover = my_bmf[6];
|
||||
|
@ -355,7 +354,7 @@ GRRLIB_bytemapFont GRRLIB_LoadBMF(const unsigned char my_bmf[]) {
|
|||
nbPalette = my_bmf[16];
|
||||
numcolpal = 3 * nbPalette;
|
||||
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);
|
||||
}
|
||||
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.charDef = (GRRLIB_bytemapChar *)calloc(fontArray.nbChar, sizeof(GRRLIB_bytemapChar));
|
||||
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].width = 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];
|
||||
nbPixels = fontArray.charDef[i].width * fontArray.charDef[i].height;
|
||||
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);
|
||||
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.
|
||||
*/
|
||||
void GRRLIB_FreeBMF(GRRLIB_bytemapFont bmf)
|
||||
{
|
||||
void GRRLIB_FreeBMF(GRRLIB_bytemapFont bmf) {
|
||||
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);
|
||||
|
@ -401,22 +399,22 @@ void GRRLIB_FreeBMF(GRRLIB_bytemapFont bmf)
|
|||
|
||||
/**
|
||||
* Load a texture from a buffer.
|
||||
* @param my_img the JPEG or PNG buffer to load.
|
||||
* @return A GRRLIB_texImg structure filled with imgage informations.
|
||||
* @param my_img The JPEG or PNG buffer to load.
|
||||
* @return A GRRLIB_texImg structure filled with image informations.
|
||||
*/
|
||||
GRRLIB_texImg GRRLIB_LoadTexture(const unsigned char my_img[]) {
|
||||
if(my_img[0]==0xFF && my_img[1]==0xD8 && my_img[2]==0xFF) {
|
||||
return(GRRLIB_LoadTextureJPG(my_img));
|
||||
if (my_img[0]==0xFF && my_img[1]==0xD8 && my_img[2]==0xFF) {
|
||||
return (GRRLIB_LoadTextureJPG(my_img));
|
||||
}
|
||||
else {
|
||||
return(GRRLIB_LoadTexturePNG(my_img));
|
||||
return (GRRLIB_LoadTexturePNG(my_img));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty texture.
|
||||
* @param w width of the new texture to create.
|
||||
* @param h height of the new texture to create.
|
||||
* @param w Width of the new texture to create.
|
||||
* @param h Height of the new texture to create.
|
||||
* @return A GRRLIB_texImg structure newly created.
|
||||
*/
|
||||
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.h = h;
|
||||
// Initialize the texture
|
||||
for(y=0; y<h; y++) {
|
||||
for(x=0; x<w; x++) {
|
||||
for (y = 0; y < h; y++) {
|
||||
for (x = 0; x < w; x++) {
|
||||
GRRLIB_SetPixelTotexImg(x, y, my_texture, 0x00000000);
|
||||
}
|
||||
}
|
||||
|
@ -438,13 +436,13 @@ GRRLIB_texImg GRRLIB_CreateEmptyTexture(unsigned int w, unsigned int h) {
|
|||
|
||||
/**
|
||||
* Draw a texture.
|
||||
* @param xpos specifies the x-coordinate of the upper-left corner.
|
||||
* @param ypos specifies the y-coordinate of the upper-left corner.
|
||||
* @param tex 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
|
||||
* @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.
|
||||
*/
|
||||
inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees, float scaleX, f32 scaleY, u32 color) {
|
||||
GXTexObj texObj;
|
||||
|
@ -495,14 +493,14 @@ inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees,
|
|||
|
||||
/**
|
||||
* Draw a tile.
|
||||
* @param xpos specifies the x-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 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
|
||||
* @param frame specifies the frame to draw.
|
||||
* @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.
|
||||
*/
|
||||
inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees, float scaleX, f32 scaleY, u32 color, int frame) {
|
||||
GXTexObj texObj;
|
||||
|
@ -558,12 +556,12 @@ inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees
|
|||
|
||||
/**
|
||||
* Print formatted output.
|
||||
* @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 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 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(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);
|
||||
va_end(argp);
|
||||
|
||||
for(i=0; i<size; i++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the specified point lies within the specified 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 hotw the width of the rectangle.
|
||||
* @param hoth the height of the rectangle.
|
||||
* @param wpadx specifies the x-coordinate of the point.
|
||||
* @param wpady specifies the y-coordinate of the point.
|
||||
* 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 hoty Specifies the y-coordinate of the upper-left corner of the rectangle.
|
||||
* @param hotw The width of the rectangle.
|
||||
* @param hoth The height of the rectangle.
|
||||
* @param wpadx Specifies the x-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.
|
||||
*/
|
||||
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.
|
||||
* @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 rect1w specifies the width 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 rect2y specifies the y-coordinate of the upper-left corner of the rectangle.
|
||||
* @param rect2w specifies the width of the rectangle.
|
||||
* @param rect2h specifies the height of the 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 rect1y Specifies the y-coordinate of the upper-left corner of the rectangle.
|
||||
* @param rect1w Specifies the width 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 rect2y Specifies the y-coordinate of the upper-left corner of the rectangle.
|
||||
* @param rect2w Specifies the width 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.
|
||||
*/
|
||||
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.
|
||||
* @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 rect1w specifies the width 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 rect2y specifies the y-coordinate of the upper-left corner of the second rectangle.
|
||||
* @param rect2w specifies the width of the second rectangle.
|
||||
* @param rect2h specifies the height of the second 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 rect1y Specifies the y-coordinate of the upper-left corner of the first rectangle.
|
||||
* @param rect1w Specifies the width 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 rect2y Specifies the y-coordinate of the upper-left corner of the second rectangle.
|
||||
* @param rect2w Specifies the width 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.
|
||||
*/
|
||||
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 y The y-coordinate 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() {
|
||||
GX_SetClipMode( GX_CLIP_DISABLE );
|
||||
GX_SetScissor( 0, 0, rmode->fbWidth, rmode->efbHeight );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a texture's X and Y handles. (e.g. for rotation)
|
||||
* @param tex GRRLIB Texture
|
||||
* Set a texture's X and Y handles. (e.g. for rotation)
|
||||
* @param tex The texture to set the handle on.
|
||||
* @param x The handle's x-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)
|
||||
* @param tex GRRLIB Texture
|
||||
* Center a texture's handles. (e.g. for rotation)
|
||||
* @param tex The texture to center.
|
||||
*/
|
||||
void GRRLIB_SetMidHandle( GRRLIB_texImg * tex ) {
|
||||
tex->handlex = 0;
|
||||
|
@ -680,9 +677,9 @@ void GRRLIB_SetMidHandle( GRRLIB_texImg * tex ) {
|
|||
|
||||
/**
|
||||
* Return the color value of a pixel from a GRRLIB_texImg.
|
||||
* @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 tex texture to get the color from.
|
||||
* @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 tex The texture to get the color from.
|
||||
* @return The color of a pixel in RGBA format.
|
||||
*/
|
||||
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);
|
||||
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.
|
||||
* @see GRRLIB_FlushTex
|
||||
* @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 tex texture to set the color to.
|
||||
* @param color the color of the pixel in RGBA format.
|
||||
* @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 tex The texture to set the color to.
|
||||
* @param color The color of the pixel in RGBA format.
|
||||
*/
|
||||
void GRRLIB_SetPixelTotexImg(int x, int y, GRRLIB_texImg tex, u32 color) {
|
||||
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.
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change a texture to gray scale.
|
||||
* @see GRRLIB_FlushTex
|
||||
* @param texsrc the texture source.
|
||||
* @param texdest the texture grayscaled destination.
|
||||
* @param texsrc The texture source.
|
||||
* @param texdest The texture grayscaled destination.
|
||||
*/
|
||||
void GRRLIB_BMFX_Grayscale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
|
||||
unsigned int x, y;
|
||||
u8 gray;
|
||||
u32 color;
|
||||
|
||||
for(y=0; y<texsrc.h; y++) {
|
||||
for(x=0; x<texsrc.w; x++) {
|
||||
for (y = 0; y < texsrc.h; y++) {
|
||||
for (x = 0; x < texsrc.w; x++) {
|
||||
color = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
|
||||
|
||||
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.
|
||||
* @see GRRLIB_FlushTex
|
||||
* @param texsrc the texture source.
|
||||
* @param texdest the texture destination.
|
||||
* @param texsrc The texture source.
|
||||
* @param texdest The texture destination.
|
||||
*/
|
||||
void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
|
||||
unsigned int x, y;
|
||||
u32 color;
|
||||
|
||||
for(y=0; y<texsrc.h; y++) {
|
||||
for(x=0; x<texsrc.w; x++) {
|
||||
for (y = 0; y < texsrc.h; y++) {
|
||||
for (x = 0; x < texsrc.w; x++) {
|
||||
color = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
|
||||
|
||||
GRRLIB_SetPixelTotexImg(x, y, texdest,
|
||||
((0xFFFFFF - (color >> 8 & 0xFFFFFF)) << 8) | (color & 0xFF));
|
||||
}
|
||||
|
@ -776,14 +771,14 @@ void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
|
|||
/**
|
||||
* Flip texture horizontal.
|
||||
* @see GRRLIB_FlushTex
|
||||
* @param texsrc the texture source.
|
||||
* @param texdest the texture destination.
|
||||
* @param texsrc The texture source.
|
||||
* @param texdest The texture destination.
|
||||
*/
|
||||
void GRRLIB_BMFX_FlipH(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
|
||||
unsigned int x, y, txtWidth = texsrc.w - 1;
|
||||
|
||||
for(y=0; y<texsrc.h; y++) {
|
||||
for(x=0; x<texsrc.w; x++) {
|
||||
for (y = 0; y < texsrc.h; y++) {
|
||||
for (x = 0; x < texsrc.w; x++) {
|
||||
GRRLIB_SetPixelTotexImg(txtWidth - x, y, texdest,
|
||||
GRRLIB_GetPixelFromtexImg(x, y, texsrc));
|
||||
}
|
||||
|
@ -793,14 +788,14 @@ void GRRLIB_BMFX_FlipH(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
|
|||
/**
|
||||
* Flip texture vertical.
|
||||
* @see GRRLIB_FlushTex
|
||||
* @param texsrc the texture source.
|
||||
* @param texdest the texture destination.
|
||||
* @param texsrc The texture source.
|
||||
* @param texdest The texture destination.
|
||||
*/
|
||||
void GRRLIB_BMFX_FlipV(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) {
|
||||
unsigned int x, y, texHeight = texsrc.h - 1;
|
||||
|
||||
for(y=0; y<texsrc.h; y++) {
|
||||
for(x=0; x<texsrc.w; x++) {
|
||||
for (y = 0; y < texsrc.h; y++) {
|
||||
for (x = 0; x < texsrc.w; x++) {
|
||||
GRRLIB_SetPixelTotexImg(x, texHeight - y, texdest,
|
||||
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
|
||||
* @param texsrc the texture source.
|
||||
* @param texdest the texture destination.
|
||||
* @param factor the blur factor.
|
||||
* @param texsrc The texture source.
|
||||
* @param texdest The texture destination.
|
||||
* @param factor The blur factor.
|
||||
*/
|
||||
void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
|
||||
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 thiscol;
|
||||
|
||||
for(x = 0; x < texsrc.w; x++) {
|
||||
for(y = 0; y < texsrc.h; y++) {
|
||||
for (x = 0; x < texsrc.w; x++) {
|
||||
for (y = 0; y < texsrc.h; y++) {
|
||||
newr = 0;
|
||||
newg = 0;
|
||||
newb = 0;
|
||||
|
@ -834,18 +829,18 @@ void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) {
|
|||
tmp=0;
|
||||
thiscol = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
|
||||
|
||||
for(k = x - factor; k <= x + factor; k++) {
|
||||
for(l = y - factor; l <= y + factor; l++) {
|
||||
if(k < 0) { colours[tmp] = thiscol; }
|
||||
else if(k >= texsrc.w) { colours[tmp] = thiscol; }
|
||||
else if(l < 0) { colours[tmp] = thiscol; }
|
||||
else if(l >= texsrc.h) { colours[tmp] = thiscol; }
|
||||
for (k = x - factor; k <= x + factor; k++) {
|
||||
for (l = y - factor; l <= y + factor; l++) {
|
||||
if (k < 0) { colours[tmp] = thiscol; }
|
||||
else if (k >= texsrc.w) { colours[tmp] = thiscol; }
|
||||
else if (l < 0) { colours[tmp] = thiscol; }
|
||||
else if (l >= texsrc.h) { colours[tmp] = thiscol; }
|
||||
else { colours[tmp] = GRRLIB_GetPixelFromtexImg(k, l, texsrc); }
|
||||
tmp++;
|
||||
}
|
||||
}
|
||||
|
||||
for(tmp = 0; tmp < numba; tmp++) {
|
||||
for (tmp = 0; tmp < numba; tmp++) {
|
||||
newr += (colours[tmp] >> 24) & 0xFF;
|
||||
newg += (colours[tmp] >> 16) & 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
|
||||
* @param texsrc the texture source.
|
||||
* @param texdest the texture destination.
|
||||
* @param texsrc The texture source.
|
||||
* @param texdest The texture destination.
|
||||
* @param factor The factor level of the effect.
|
||||
*/
|
||||
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;
|
||||
u32 rgb;
|
||||
|
||||
for(x=0; x<texsrc.w-1-factor; x+= factor) {
|
||||
for(y=0; y<texsrc.h-1-factor; y+=factor) {
|
||||
rgb=GRRLIB_GetPixelFromtexImg(x, y, texsrc);
|
||||
for(xx=x; xx<x+factor; xx++) {
|
||||
for(yy=y; yy<y+factor; yy++) {
|
||||
for (x = 0; x < texsrc.w - 1 - factor; x += factor) {
|
||||
for (y = 0; y < texsrc.h - 1 - factor; y +=factor) {
|
||||
rgb = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
|
||||
for (xx = x; xx < x + factor; xx++) {
|
||||
for (yy = y; yy < y + factor; yy++) {
|
||||
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
|
||||
* @param texsrc the texture source.
|
||||
* @param texdest the texture destination.
|
||||
* @param texsrc The texture source.
|
||||
* @param texdest The texture destination.
|
||||
* @param factor The factor level of the effect.
|
||||
*/
|
||||
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;
|
||||
int factorx2 = factor*2;
|
||||
|
||||
for(y=0; y<texsrc.h; y++) {
|
||||
for(x=0; x<texsrc.w; x++) {
|
||||
for (y = 0; y < texsrc.h; y++) {
|
||||
for (x = 0; x < texsrc.w; x++) {
|
||||
val1 = x + (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 {
|
||||
val3 = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
|
||||
|
@ -917,17 +912,13 @@ void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param v
|
||||
* @param color
|
||||
* @param n
|
||||
* @param fmt
|
||||
* Draws a vector.
|
||||
*/
|
||||
void GRRLIB_GXEngine(Vector v[], u32 color, long n, u8 fmt) {
|
||||
int i;
|
||||
|
||||
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_Color1u32(color);
|
||||
}
|
||||
|
@ -945,11 +936,11 @@ void GRRLIB_Init() {
|
|||
|
||||
VIDEO_Init();
|
||||
rmode = VIDEO_GetPreferredMode(NULL);
|
||||
if(rmode == NULL)
|
||||
if (rmode == NULL)
|
||||
return;
|
||||
|
||||
// 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->viXOrigin = (VI_MAX_WIDTH_NTSC - 678)/2;
|
||||
}
|
||||
|
@ -957,26 +948,26 @@ void GRRLIB_Init() {
|
|||
VIDEO_Configure(rmode);
|
||||
xfb[0] = (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;
|
||||
|
||||
VIDEO_SetNextFramebuffer(xfb[fb]);
|
||||
VIDEO_SetBlack(FALSE);
|
||||
VIDEO_Flush();
|
||||
VIDEO_WaitVSync();
|
||||
if(rmode->viTVMode&VI_NON_INTERLACE)
|
||||
if (rmode->viTVMode&VI_NON_INTERLACE)
|
||||
VIDEO_WaitVSync();
|
||||
|
||||
gp_fifo = (u8 *) memalign(32, DEFAULT_FIFO_SIZE);
|
||||
if(gp_fifo == NULL)
|
||||
if (gp_fifo == NULL)
|
||||
return;
|
||||
memset(gp_fifo, 0, 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);
|
||||
|
||||
// other gx setup
|
||||
// Other GX setup
|
||||
yscale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight);
|
||||
xfbHeight = GX_SetDispCopyYScale(yscale);
|
||||
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_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);
|
||||
else
|
||||
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
|
||||
|
@ -993,8 +984,8 @@ void GRRLIB_Init() {
|
|||
GX_SetDispCopyGamma(GX_GM_1_0);
|
||||
|
||||
|
||||
// setup the vertex descriptor
|
||||
// tells the flipper to expect direct data
|
||||
// Setup the vertex descriptor
|
||||
// Tells the flipper to expect direct data
|
||||
GX_ClearVtxDesc();
|
||||
GX_InvVtxCache();
|
||||
GX_InvalidateTexAll();
|
||||
|
@ -1035,7 +1026,7 @@ void GRRLIB_Init() {
|
|||
void GRRLIB_Render() {
|
||||
GX_DrawDone();
|
||||
|
||||
fb ^= 1; // flip framebuffer
|
||||
fb ^= 1; // Flip framebuffer
|
||||
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
|
||||
GX_SetColorUpdate(GX_TRUE);
|
||||
GX_CopyDisp(xfb[fb], GX_TRUE);
|
||||
|
@ -1049,21 +1040,21 @@ void GRRLIB_Render() {
|
|||
*/
|
||||
void GRRLIB_Exit() {
|
||||
GX_SetClipMode( GX_CLIP_DISABLE );
|
||||
GX_SetScissor( 0, 0, WinW, WinH );
|
||||
GX_SetScissor( 0, 0, rmode->fbWidth, rmode->efbHeight );
|
||||
GRRLIB_FillScreen( 0x000000FF );
|
||||
GRRLIB_Render();
|
||||
GX_Flush();
|
||||
GX_AbortFrame();
|
||||
|
||||
if(xfb[0] != NULL) {
|
||||
if (xfb[0] != NULL) {
|
||||
free(MEM_K1_TO_K0(xfb[0]));
|
||||
xfb[0] = NULL;
|
||||
}
|
||||
if(xfb[1] != NULL) {
|
||||
if (xfb[1] != NULL) {
|
||||
free(MEM_K1_TO_K0(xfb[1]));
|
||||
xfb[1] = NULL;
|
||||
}
|
||||
if(gp_fifo != NULL) {
|
||||
if (gp_fifo != NULL) {
|
||||
free(gp_fifo);
|
||||
gp_fifo = NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue