[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,316 +7,366 @@
#include "GRRLIB.h" #include "GRRLIB.h"
#define DEFAULT_FIFO_SIZE (256 * 1024) #define DEFAULT_FIFO_SIZE (256 * 1024)
u32 fb=0; u32 fb = 0;
static void *xfb[2] = { NULL, NULL}; static void *xfb[2] = { NULL, NULL};
GXRModeObj *rmode; GXRModeObj *rmode;
void *gp_fifo = NULL; 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){ inline void GRRLIB_FillScreen(u32 color){
GRRLIB_Rectangle(-40, -40, 680,520, color, 1); GRRLIB_Rectangle(-40, -40, 680,520, color, 1);
} }
/**
*
*/
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}};
GRRLIB_NPlot(v,color,1); GRRLIB_NPlot(v,color,1);
} }
/**
*
*/
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);
} }
/**
* 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){ 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}};
GRRLIB_NGone(v,color,2); GRRLIB_NGone(v,color,2);
} }
/**
* Draw a 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){
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){ if(!filled){
GRRLIB_NGone(v,color,5); GRRLIB_NGone(v,color,5);
} }
else{ else{
GRRLIB_NGoneFilled(v,color,4); GRRLIB_NGoneFilled(v,color,4);
} }
} }
/**
*
*/
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);
} }
/**
*
*/
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);
} }
/**
*
*/
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;
tex->nbtilew=tex->w/tilew; tex->nbtilew = tex->w/tilew;
tex->nbtileh=tex->h/tileh; tex->nbtileh = tex->h/tileh;
tex->tilestart=tilestart; 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[]) { GRRLIB_texImg GRRLIB_LoadTexture(const unsigned char my_png[]) {
PNGUPROP imgProp; PNGUPROP imgProp;
IMGCTX ctx; IMGCTX ctx;
GRRLIB_texImg my_texture; GRRLIB_texImg my_texture;
ctx = PNGU_SelectImageFromBuffer(my_png); ctx = PNGU_SelectImageFromBuffer(my_png);
PNGU_GetImageProperties (ctx, &imgProp); PNGU_GetImageProperties (ctx, &imgProp);
my_texture.data = memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4); my_texture.data = memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4);
PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, my_texture.data, 255); PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, my_texture.data, 255);
PNGU_ReleaseImageContext (ctx); PNGU_ReleaseImageContext (ctx);
DCFlushRange (my_texture.data, imgProp.imgWidth * imgProp.imgHeight * 4); DCFlushRange (my_texture.data, imgProp.imgWidth * imgProp.imgHeight * 4);
my_texture.w= imgProp.imgWidth; my_texture.w = imgProp.imgWidth;
my_texture.h= imgProp.imgHeight; my_texture.h = imgProp.imgHeight;
return my_texture;
}
// GRRLIB_LoadTextureFromFile
// Contribution by GRILLO
GRRLIB_texImg GRRLIB_LoadTextureFromFile(const char *filename) {
PNGUPROP imgProp;
IMGCTX ctx;
GRRLIB_texImg my_texture;
ctx = PNGU_SelectImageFromDevice(filename);
PNGU_GetImageProperties (ctx, &imgProp);
my_texture.data = memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4);
PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, my_texture.data, 255);
PNGU_ReleaseImageContext (ctx);
DCFlushRange (my_texture.data, imgProp.imgWidth * imgProp.imgHeight * 4);
my_texture.w= imgProp.imgWidth;
my_texture.h= imgProp.imgHeight;
return my_texture; return my_texture;
} }
/**
* 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;
ctx = PNGU_SelectImageFromDevice(filename);
PNGU_GetImageProperties (ctx, &imgProp);
my_texture.data = memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4);
PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, my_texture.data, 255);
PNGU_ReleaseImageContext (ctx);
DCFlushRange (my_texture.data, imgProp.imgWidth * imgProp.imgHeight * 4);
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 ){ inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees, float scaleX, f32 scaleY, u32 color ){
GXTexObj texObj; GXTexObj texObj;
u16 width,height; 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);
GX_InitTexObj(&texObj, tex.data, tex.w,tex.h, GX_TF_RGBA8,GX_CLAMP, GX_CLAMP,GX_FALSE); GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_InitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1); GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
GX_LoadTexObj(&texObj, GX_TEXMAP0);
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE); Mtx m,m1,m2, mv;
GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT); width=tex.w * .5;
height=tex.h * .5;
guMtxIdentity (m1);
guMtxScaleApply(m1,m1,scaleX,scaleY,1.0);
Vector axis =(Vector) {0 , 0, 1 };
guMtxRotAxisDeg (m2, &axis, degrees);
guMtxConcat(m2,m1,m);
Mtx m,m1,m2, mv; guMtxTransApply(m,m, xpos+width,ypos+height,0);
width=tex.w * .5; guMtxConcat (GXmodelView2D, m, mv);
height=tex.h * .5; GX_LoadPosMtxImm (mv, GX_PNMTX0);
guMtxIdentity (m1);
guMtxScaleApply(m1,m1,scaleX,scaleY,1.0);
Vector axis =(Vector) {0 , 0, 1 };
guMtxRotAxisDeg (m2, &axis, degrees);
guMtxConcat(m2,m1,m);
guMtxTransApply(m,m, xpos+width,ypos+height,0); GX_Begin(GX_QUADS, GX_VTXFMT0,4);
guMtxConcat (GXmodelView2D, m, mv); GX_Position3f32(-width, -height, 0);
GX_LoadPosMtxImm (mv, GX_PNMTX0); GX_Color1u32(color);
GX_TexCoord2f32(0, 0);
GX_Begin(GX_QUADS, GX_VTXFMT0,4); GX_Position3f32(width, -height, 0);
GX_Position3f32(-width, -height, 0); GX_Color1u32(color);
GX_Color1u32(color); GX_TexCoord2f32(1, 0);
GX_TexCoord2f32(0, 0);
GX_Position3f32(width, -height, 0); GX_Position3f32(width, height, 0);
GX_Color1u32(color); GX_Color1u32(color);
GX_TexCoord2f32(1, 0); GX_TexCoord2f32(1, 1);
GX_Position3f32(width, height, 0); GX_Position3f32(-width, height, 0);
GX_Color1u32(color); GX_Color1u32(color);
GX_TexCoord2f32(1, 1); GX_TexCoord2f32(0, 1);
GX_End();
GX_Position3f32(-width, height, 0); GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0);
GX_Color1u32(color);
GX_TexCoord2f32(0, 1);
GX_End();
GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0);
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
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){ 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;
// Frame Correction by spiffen // Frame Correction by spiffen
f32 FRAME_CORR = 0.001f; f32 FRAME_CORR = 0.001f;
f32 s1= (((frame%tex.nbtilew))/(f32)tex.nbtilew)+(FRAME_CORR/tex.w); 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 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 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 t2 = (((int)(frame/tex.nbtilew)+1)/(f32)tex.nbtileh)-(FRAME_CORR/tex.h);
f32 width,height; 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_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); GX_InitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1);
GX_LoadTexObj(&texObj, GX_TEXMAP0); GX_LoadTexObj(&texObj, GX_TEXMAP0);
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE); GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT); GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
Mtx m,m1,m2, mv; Mtx m,m1,m2, mv;
width =tex.tilew * 0.5f; width = tex.tilew * 0.5f;
height = tex.tileh * 0.5f; height = tex.tileh * 0.5f;
guMtxIdentity (m1); guMtxIdentity (m1);
guMtxScaleApply(m1,m1,scaleX,scaleY,1.0f); guMtxScaleApply(m1,m1,scaleX,scaleY,1.0f);
Vector axis =(Vector) {0 , 0, 1 }; Vector axis = (Vector) {0 , 0, 1 };
guMtxRotAxisDeg (m2, &axis, degrees); guMtxRotAxisDeg (m2, &axis, degrees);
guMtxConcat(m2,m1,m); guMtxConcat(m2,m1,m);
guMtxTransApply(m,m, xpos+width,ypos+height,0); guMtxTransApply(m,m, xpos+width,ypos+height,0);
guMtxConcat (GXmodelView2D, m, mv); guMtxConcat (GXmodelView2D, m, mv);
GX_LoadPosMtxImm (mv, GX_PNMTX0); GX_LoadPosMtxImm (mv, GX_PNMTX0);
GX_Begin(GX_QUADS, GX_VTXFMT0,4); GX_Begin(GX_QUADS, GX_VTXFMT0,4);
GX_Position3f32(-width, -height, 0); GX_Position3f32(-width, -height, 0);
GX_Color1u32(color); GX_Color1u32(color);
GX_TexCoord2f32(s1, t1); GX_TexCoord2f32(s1, t1);
GX_Position3f32(width, -height, 0); GX_Position3f32(width, -height, 0);
GX_Color1u32(color); GX_Color1u32(color);
GX_TexCoord2f32(s2, t1); GX_TexCoord2f32(s2, t1);
GX_Position3f32(width, height, 0); GX_Position3f32(width, height, 0);
GX_Color1u32(color); GX_Color1u32(color);
GX_TexCoord2f32(s2, t2); GX_TexCoord2f32(s2, t2);
GX_Position3f32(-width, height, 0); GX_Position3f32(-width, height, 0);
GX_Color1u32(color); GX_Color1u32(color);
GX_TexCoord2f32(s1, t2); GX_TexCoord2f32(s1, t2);
GX_End(); GX_End();
GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0); GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0);
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
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,...){ void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, char *text,...){
int i ; int i;
char tmp[1024]; char tmp[1024];
int size=0; int size;
va_list argp; va_list argp;
va_start(argp, text); va_start(argp, text);
vsprintf(tmp, text, argp); vsprintf(tmp, text, argp);
va_end(argp); va_end(argp);
size = strlen(tmp); size = strlen(tmp);
for(i=0;i<strlen(tmp);i++){ for(i=0; i<strlen(tmp); 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);
} }
} }
/**
*
*/
void GRRLIB_GXEngine(Vector v[], u32 color, long n,u8 fmt){ void GRRLIB_GXEngine(Vector v[], u32 color, long n,u8 fmt){
int i=0; int i=0;
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);
} }
GX_End(); GX_End();
} }
/**
*
//******************************************************************************************** */
void GRRLIB_InitVideo () { void GRRLIB_InitVideo () {
VIDEO_Init(); VIDEO_Init();
rmode = VIDEO_GetPreferredMode(NULL); rmode = VIDEO_GetPreferredMode(NULL);
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));
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) VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
gp_fifo = (u8 *) memalign(32,DEFAULT_FIFO_SIZE);
gp_fifo = (u8 *) memalign(32,DEFAULT_FIFO_SIZE);
} }
/**
*
*/
void GRRLIB_Start(){ void GRRLIB_Start(){
f32 yscale;
u32 xfbHeight;
Mtx perspective;
f32 yscale; GX_Init (gp_fifo, DEFAULT_FIFO_SIZE);
u32 xfbHeight;
Mtx perspective;
GX_Init (gp_fifo, DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer
GXColor background = { 0, 0, 0, 0xff };
GX_SetCopyClear (background, GX_MAX_Z24);
// clears the bg to color and clears the z buffer // other gx setup
GXColor background = { 0, 0, 0, 0xff }; yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight);
GX_SetCopyClear (background, GX_MAX_Z24); xfbHeight = GX_SetDispCopyYScale(yscale);
GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight);
GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight);
GX_SetDispCopyDst(rmode->fbWidth,xfbHeight);
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));
// other gx setup if (rmode->aa)
yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR);
xfbHeight = GX_SetDispCopyYScale(yscale); else
GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight);
GX_SetDispCopyDst(rmode->fbWidth,xfbHeight);
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) GX_SetDispCopyGamma(GX_GM_1_0);
GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR);
else
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
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();
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
GX_SetVtxDesc (GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc (GX_VA_CLR0, GX_DIRECT);
GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_TRUE); GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_TRUE);
GX_SetNumChans(1); GX_SetNumChans(1);
GX_SetNumTexGens(1); GX_SetNumTexGens(1);
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR); GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
guMtxIdentity(GXmodelView2D); guMtxIdentity(GXmodelView2D);
guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -50.0F); guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -50.0F);
GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0); GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0);
guOrtho(perspective,0,479,0,639,0,300); guOrtho(perspective,0,479,0,639,0,300);
GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC); GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC);
GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1);
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
GX_SetAlphaUpdate(GX_TRUE); GX_SetAlphaUpdate(GX_TRUE);
GX_SetCullMode(GX_CULL_NONE); GX_SetCullMode(GX_CULL_NONE);
} }
/**
*
*/
void GRRLIB_Render () { void GRRLIB_Render () {
GX_DrawDone (); GX_DrawDone ();
fb ^= 1; // flip framebuffer
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
GX_SetColorUpdate(GX_TRUE);
GX_CopyDisp(xfb[fb],GX_TRUE);
VIDEO_SetNextFramebuffer(xfb[fb]);
VIDEO_Flush();
VIDEO_WaitVSync();
fb ^= 1; // flip framebuffer
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
GX_SetColorUpdate(GX_TRUE);
GX_CopyDisp(xfb[fb],GX_TRUE);
VIDEO_SetNextFramebuffer(xfb[fb]);
VIDEO_Flush();
VIDEO_WaitVSync();
} }

View file

@ -16,15 +16,27 @@
#include "../libpng/pngu/pngu.h" #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{ typedef struct GRRLIB_texImg{
unsigned int w; unsigned int w;
unsigned int h; unsigned int h;
unsigned int tilew; unsigned int tilew;
unsigned int tileh; unsigned int tileh;
unsigned int nbtilew; unsigned int nbtilew;
unsigned int nbtileh; unsigned int nbtileh;
unsigned int tilestart; unsigned int tilestart;
void *data; void *data;
} GRRLIB_texImg; } GRRLIB_texImg;
extern Mtx GXmodelView2D; extern Mtx GXmodelView2D;
@ -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_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); void GRRLIB_GXEngine(Vector v[], u32 color, long count,u8 fmt);

View file

@ -26,7 +26,7 @@
Mtx GXmodelView2D; Mtx GXmodelView2D;
int main(){ int main(){
int rot=0; int rot = 0;
GRRLIB_InitVideo(); GRRLIB_InitVideo();
GRRLIB_Start(); GRRLIB_Start();
@ -50,25 +50,24 @@ int rot=0;
while(1){ while(1){
WPAD_SetVRes(0, 640, 480); WPAD_SetVRes(0, 640, 480);
WPAD_ScanPads(); WPAD_ScanPads();
u32 wpaddown=WPAD_ButtonsDown(0); u32 wpaddown = WPAD_ButtonsDown(0);
u32 wpadheld=WPAD_ButtonsHeld(0); u32 wpadheld = WPAD_ButtonsHeld(0);
ir_t ir1;
ir_t ir1; WPAD_IR(WPAD_CHAN_0, &ir1);
WPAD_IR(WPAD_CHAN_0, &ir1);
GRRLIB_FillScreen(0x000000FF); GRRLIB_FillScreen(0x000000FF);
GRRLIB_Printf(rot, 200, tex_BMfont1, 0xFFFFFFFF, 1, "X VALUE:%d",(int)ir1.sx); GRRLIB_Printf(rot, 200, tex_BMfont1, 0xFFFFFFFF, 1, "X VALUE:%d",(int)ir1.sx);
GRRLIB_Printf(rot, 250, tex_BMfont4, 0xFFFFFFFF, 1, "X VALUE:%d",(int)ir1.sx); GRRLIB_Printf(rot, 250, tex_BMfont4, 0xFFFFFFFF, 1, "X VALUE:%d",(int)ir1.sx);
GRRLIB_Printf(rot, 300, tex_BMfont3, 0xFFFFFFFF, 1 , "X VALUE : 1"); GRRLIB_Printf(rot, 300, tex_BMfont3, 0xFFFFFFFF, 1 , "X VALUE : 1");
GRRLIB_Printf(rot, 350, tex_BMfont2, 0xFFFFFFFF, 1 , "X VALUE : 1"); GRRLIB_Printf(rot, 350, tex_BMfont2, 0xFFFFFFFF, 1 , "X VALUE : 1");
GRRLIB_Render(); GRRLIB_Render();
if (wpaddown & WPAD_BUTTON_A) exit(0); if (wpaddown & WPAD_BUTTON_A) exit(0);
if (wpadheld & WPAD_BUTTON_B) rot++; if (wpadheld & WPAD_BUTTON_B) rot++;
} }
return 0; return 0;
} }