I'm using GRRLIB and I'm having trouble drawing tiles on the screen. Vertically I get a glitch between the tiles from 50% of the screen and it continues for about 50px to the right, and horizontally tiles get a little stretched from 50% and continues 30-40px down.
I wrote a function that took a screenshot.
I've looked around alot and what I can understand this is a libogc fault, have you heard about this before?
I managed to fix this in a kind of ugly way. It's not a 100% fix, but it works quite good.
Code: Select all
...
// NEW - Correction value
f32 FRAME_CORR = 0.001
...
void GRRLIB_DrawTile(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[], float degrees, float scaleX, f32 scaleY, u8 alpha, f32 frame,f32 maxframe ){
GXTexObj texObj;
/*
* REMOVE (BEGIN) - Old code to calculate TexCoord pairs
f32 s1= frame/maxframe;
f32 s2= (frame+1)/maxframe;
f32 t1=0;
f32 t2=1;
* REMOVE (END)
*/
/*
* NEW (BEGIN) - New code including correction parameter
*/
f32 s1= (frame/maxframe)+(FRAME_CORR/(width*maxframe)); // X begin
f32 s2= ((frame+1)/maxframe)-(FRAME_CORR/(width*maxframe)); // X end
f32 t1= 0+(FRAME_CORR/height); // Y begin
f32 t2= 1-(FRAME_CORR/height); // Y end
/*
* NEW (END)
*/
GX_InitTexObj(&texObj, data, width*maxframe,height, 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_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
Mtx m,m1,m2, mv;
width *=.5;
height*=.5;
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);
guMtxConcat (GXmodelView2D, m, mv);
GX_LoadPosMtxImm (mv, GX_PNMTX0);
GX_Begin(GX_QUADS, GX_VTXFMT0,4);
GX_Position3f32(-width, -height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(s1, t1);
GX_Position3f32(width, -height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(s2, t1);
GX_Position3f32(width, height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(s2, t2);
GX_Position3f32(-width, height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(s1, t2);
GX_End();
GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0);
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
}