[CHG] Code formatting and some doxygen comments

This commit is contained in:
Crayon2000 2009-01-18 17:59:43 +00:00
parent 89e3071ffc
commit f5d25a55a5
3 changed files with 316 additions and 256 deletions

View file

@ -7,33 +7,54 @@
#include "GRRLIB.h"
#define DEFAULT_FIFO_SIZE (256 * 1024)
u32 fb=0;
u32 fb = 0;
static void *xfb[2] = { NULL, NULL};
GXRModeObj *rmode;
void *gp_fifo = NULL;
/**
* Clear screen with a specific color.
* @param color the color to use to fill the screen.
*/
inline void GRRLIB_FillScreen(u32 color){
GRRLIB_Rectangle(-40, -40, 680,520, color, 1);
}
/**
*
*/
inline void GRRLIB_Plot(f32 x,f32 y, u32 color){
Vector v[]={{x,y,0.0f}};
GRRLIB_NPlot(v,color,1);
}
/**
*
*/
void GRRLIB_NPlot(Vector v[],u32 color,long n){
GRRLIB_GXEngine(v,color,n,GX_POINTS);
}
/**
* 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.
*/
inline void GRRLIB_Line(f32 x1, f32 y1, f32 x2, f32 y2, u32 color){
Vector v[]={{x1,y1,0.0f},{x2,y2,0.0f}};
GRRLIB_NGone(v,color,2);
}
/**
* Draw a rectangle.
*/
inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8 filled){
Vector v[]={{x,y,0.0f},{x+width,y,0.0f},{x+width,y+height,0.0f},{x,y+height,0.0f},{x,y,0.0f}};
Vector v[] = {{x,y,0.0f},{x+width,y,0.0f},{x+width,y+height,0.0f},{x,y+height,0.0f},{x,y,0.0f}};
if(!filled){
GRRLIB_NGone(v,color,5);
@ -42,22 +63,37 @@ inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8
GRRLIB_NGoneFilled(v,color,4);
}
}
/**
*
*/
void GRRLIB_NGone(Vector v[],u32 color,long n){
GRRLIB_GXEngine(v,color,n,GX_LINESTRIP);
}
/**
*
*/
void GRRLIB_NGoneFilled(Vector v[],u32 color,long n){
GRRLIB_GXEngine(v,color,n,GX_TRIANGLEFAN);
}
/**
*
*/
void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned int tileh, unsigned int tilestart){
tex->tilew=tilew;
tex->tileh=tileh;
tex->nbtilew=tex->w/tilew;
tex->nbtileh=tex->h/tileh;
tex->tilestart=tilestart;
tex->tilew = tilew;
tex->tileh = tileh;
tex->nbtilew = tex->w/tilew;
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 PNG informations.
*/
GRRLIB_texImg GRRLIB_LoadTexture(const unsigned char my_png[]) {
PNGUPROP imgProp;
IMGCTX ctx;
@ -69,15 +105,18 @@ GRRLIB_texImg GRRLIB_LoadTexture(const unsigned char my_png[]) {
PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, my_texture.data, 255);
PNGU_ReleaseImageContext (ctx);
DCFlushRange (my_texture.data, imgProp.imgWidth * imgProp.imgHeight * 4);
my_texture.w= imgProp.imgWidth;
my_texture.h= imgProp.imgHeight;
my_texture.w = imgProp.imgWidth;
my_texture.h = imgProp.imgHeight;
return my_texture;
}
// GRRLIB_LoadTextureFromFile
// Contribution by GRILLO
/**
* Load a texture from a file.
* @author GRILLO
* @param filename the PNG file to load.
* @return A GRRLIB_texImg structure filled with PNG informations.
*/
GRRLIB_texImg GRRLIB_LoadTextureFromFile(const char *filename) {
PNGUPROP imgProp;
IMGCTX ctx;
GRRLIB_texImg my_texture;
@ -88,16 +127,18 @@ GRRLIB_texImg GRRLIB_LoadTextureFromFile(const char *filename) {
PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, my_texture.data, 255);
PNGU_ReleaseImageContext (ctx);
DCFlushRange (my_texture.data, imgProp.imgWidth * imgProp.imgHeight * 4);
my_texture.w= imgProp.imgWidth;
my_texture.h= imgProp.imgHeight;
my_texture.w = imgProp.imgWidth;
my_texture.h = imgProp.imgHeight;
return my_texture;
}
/**
*
*/
inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees, float scaleX, f32 scaleY, u32 color ){
GXTexObj texObj;
u16 width,height;
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);
GX_LoadTexObj(&texObj, GX_TEXMAP0);
@ -139,18 +180,20 @@ inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees,
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
}
/**
*
*/
inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees, float scaleX, f32 scaleY, u32 color, int frame){
GXTexObj texObj;
// Frame Correction by spiffen
f32 FRAME_CORR = 0.001f;
f32 s1= (((frame%tex.nbtilew))/(f32)tex.nbtilew)+(FRAME_CORR/tex.w);
f32 s2= (((frame%tex.nbtilew)+1)/(f32)tex.nbtilew)-(FRAME_CORR/tex.w);
f32 t1= (((int)(frame/tex.nbtilew))/(f32)tex.nbtileh)+(FRAME_CORR/tex.h);
f32 t2= (((int)(frame/tex.nbtilew)+1)/(f32)tex.nbtileh)-(FRAME_CORR/tex.h);
f32 width,height;
GXTexObj texObj;
// Frame Correction by spiffen
f32 FRAME_CORR = 0.001f;
f32 s1 = (((frame%tex.nbtilew))/(f32)tex.nbtilew)+(FRAME_CORR/tex.w);
f32 s2 = (((frame%tex.nbtilew)+1)/(f32)tex.nbtilew)-(FRAME_CORR/tex.w);
f32 t1 = (((int)(frame/tex.nbtilew))/(f32)tex.nbtileh)+(FRAME_CORR/tex.h);
f32 t2 = (((int)(frame/tex.nbtilew)+1)/(f32)tex.nbtileh)-(FRAME_CORR/tex.h);
f32 width,height;
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);
@ -160,11 +203,11 @@ f32 width,height;
GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
Mtx m,m1,m2, mv;
width =tex.tilew * 0.5f;
width = tex.tilew * 0.5f;
height = tex.tileh * 0.5f;
guMtxIdentity (m1);
guMtxScaleApply(m1,m1,scaleX,scaleY,1.0f);
Vector axis =(Vector) {0 , 0, 1 };
Vector axis = (Vector) {0 , 0, 1 };
guMtxRotAxisDeg (m2, &axis, degrees);
guMtxConcat(m2,m1,m);
guMtxTransApply(m,m, xpos+width,ypos+height,0);
@ -191,13 +234,15 @@ f32 width,height;
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
}
/**
*
*/
void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, char *text,...){
int i ;
int i;
char tmp[1024];
int size=0;
int size;
va_list argp;
va_start(argp, text);
@ -205,26 +250,29 @@ void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, c
va_end(argp);
size = strlen(tmp);
for(i=0;i<strlen(tmp);i++){
for(i=0; i<strlen(tmp); i++){
u8 c = tmp[i]-tex.tilestart;
GRRLIB_DrawTile(xpos+i*tex.tilew*zoom, ypos, tex, 0, zoom, zoom, color, c);
}
}
/**
*
*/
void GRRLIB_GXEngine(Vector v[], u32 color, long n,u8 fmt){
int i=0;
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);
}
GX_End();
}
//********************************************************************************************
/**
*
*/
void GRRLIB_InitVideo () {
VIDEO_Init();
rmode = VIDEO_GetPreferredMode(NULL);
@ -238,12 +286,13 @@ void GRRLIB_InitVideo () {
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
gp_fifo = (u8 *) memalign(32,DEFAULT_FIFO_SIZE);
}
/**
*
*/
void GRRLIB_Start(){
f32 yscale;
u32 xfbHeight;
Mtx perspective;
@ -307,6 +356,9 @@ void GRRLIB_Start(){
GX_SetCullMode(GX_CULL_NONE);
}
/**
*
*/
void GRRLIB_Render () {
GX_DrawDone ();
@ -317,6 +369,4 @@ void GRRLIB_Render () {
VIDEO_SetNextFramebuffer(xfb[fb]);
VIDEO_Flush();
VIDEO_WaitVSync();
}

View file

@ -16,6 +16,18 @@
#include "../libpng/pngu/pngu.h"
/**
* @struct GRRLIB_texImg
* @brief Structure to hold the texture informations.
* @param w width of the texture.
* @param h height of the texture.
* @param tilew widht of a tile.
* @param tileh height of a tile.
* @param nbtilew number of tiles for the x axis.
* @param nbtileh number of tiles for the y axis.
* @param tilestart
* @param data pointer to the texture data.
*/
typedef struct GRRLIB_texImg{
unsigned int w;
unsigned int h;
@ -52,7 +64,6 @@ inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees
void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, char *text,...);
void GRRLIB_GXEngine(Vector v[], u32 color, long count,u8 fmt);

View file

@ -26,7 +26,7 @@
Mtx GXmodelView2D;
int main(){
int rot=0;
int rot = 0;
GRRLIB_InitVideo();
GRRLIB_Start();
@ -52,9 +52,8 @@ int rot=0;
while(1){
WPAD_SetVRes(0, 640, 480);
WPAD_ScanPads();
u32 wpaddown=WPAD_ButtonsDown(0);
u32 wpadheld=WPAD_ButtonsHeld(0);
u32 wpaddown = WPAD_ButtonsDown(0);
u32 wpadheld = WPAD_ButtonsHeld(0);
ir_t ir1;
WPAD_IR(WPAD_CHAN_0, &ir1);