You are not logged in.

#1 2008-07-27 03:52:20

Wil
Member

Fixed Graphical Green-Flash Bug at Start

Edit two: Fixed a small bug where if an image had transparent pixels they would appear as a "blue grid" -- It was simple changing "GXColor background = {0x00, 0x00, 0x00, 0x00};" to "GXColor background = {0x00, 0x00, 0x00, 0xff};".

Edited: I've been messing with it more and I think I've got it nailed down. Again, I'm sure some might understand this better so have at it. I made quite a number of changes this time. I completely removed GRRLIB_Start() and moved all functions right over to GRRLIB_InitVideo(), I moved VIDEO_Init() from being a function called in main to a function called within the GRRLIB_InitVideo(). Also, I added a GRRLIB_Stop() function to make exiting a little cleaner. On a positive note, because of these changes, GRRLIB_ScrShot() from one of the topics below doesn't cause any frame buffer glitches when you first take a screen shot anymore.

I tested this on my own program I'm working on. Last night I continued to get glitches when starting and exiting the program so I spent some time this morning trying to get those sorted out. Taking a screen shot also had some negative results (frame buffer glitching). Now, however, I can not see any glitches at all. Also, maybe it is just my eyes being less tired, but it seems like the graphics are sharper and cleaner as well. Hopefully others have the same result.

Inside of GRRLIB.c, you just copy/paste over GRRLIB_InitVideo() and GRRLIB_Start()

Code:

void GRRLIB_InitVideo () {

    f32 yscale;
    u32 xfbHeight;
    Mtx perspective;

    VIDEO_Init();
    rmode = VIDEO_GetPreferredMode(NULL);
    xfb[0] = (u32 *)MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
    xfb[1] = (u32 *)MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
    VIDEO_Configure (rmode);
    VIDEO_SetNextFramebuffer(xfb[fb]);
    VIDEO_SetBlack(FALSE);
    VIDEO_Flush();
    VIDEO_WaitVSync();
    if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
    fb ^= 1;

    gp_fifo = (u8 *) memalign(32,DEFAULT_FIFO_SIZE);
    memset(gp_fifo, 0, DEFAULT_FIFO_SIZE);
    GX_Init (gp_fifo, DEFAULT_FIFO_SIZE);
    GXColor background = {0x00, 0x00, 0x00, 0xff};
    GX_SetCopyClear(background, 0x00ffffff);

    // other gx setup
    yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight);
    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));

    if (rmode->aa) {
        GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR);
    } else {
        GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
    }

    GX_SetCullMode(GX_CULL_NONE);
    GX_CopyDisp(xfb[0],GX_TRUE);

    GX_ClearVtxDesc();
    GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
    GX_SetVtxDesc(GX_VA_POS, 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_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
    GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
    GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_TRUE);
    
    GX_InvVtxCache ();

    GX_SetNumChans(1);
    GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHTNULL, GX_DF_NONE, GX_AF_NONE);
    
    GX_SetNumTexGens(1);
    GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
    GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
    GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
    
    GX_InvalidateTexAll();

    guMtxIdentity(GXmodelView2D);
    guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -50.0F);
    GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0);

    guOrtho(perspective,0,479,0,639,0,300);
    GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC);
    GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
    GX_SetAlphaUpdate(GX_TRUE);
    GX_SetCullMode(GX_CULL_NONE);
    
}

void GRRLIB_Stop() {

    GX_AbortFrame();
    GX_Flush();

    free(MEM_K1_TO_K0(xfb[0])); xfb[0] = NULL;
    free(MEM_K1_TO_K0(xfb[1])); xfb[1] = NULL;
    free(gp_fifo); gp_fifo = NULL;

}

And in GRRLIB.h you just replace void GRRLIB_StartVideo(); with

Code:

void GRRLIB_Stop ();

Because of these changes, some modifications need to be made to the way you init and exit GRRLIB...

Code:

Mtx GXmodelView2D;

int main() {

    GRRLIB_InitVideo();
    WPAD_Init();

    while(1) {
        WPAD_ScanPads();
        u32 wpaddown = WPAD_ButtonsDown(0);

Code:

        if (wpaddown & WPAD_BUTTON_HOME) break;
    }
    
    GRRLIB_Stop();
    exit(0);
    return 0;
}

Hopefully it works for people. It seems to work very nicely for me.

Last edited by Wil (2008-08-01 08:45:06)

Offline

 

#2 2008-08-02 23:56:28

RedShade
Member

Re: Fixed Graphical Green-Flash Bug at Start

Code:

Mtx perspective;

should be

Code:

Mtx44 orthographic;

Offline

 

#3 2008-08-03 14:06:01

JustWoody
Member

Re: Fixed Graphical Green-Flash Bug at Start

Nice work Wil, looks a lot better at startup now

Offline

 

#4 2008-08-08 01:25:55

CarstenK
Member

Re: Fixed Graphical Green-Flash Bug at Start

Works great for me too! Good idea to include VIDEO_Init and eliminate GRRLIB_StartVideo.

gx.h says You have to call GX_SetDispCopySrc before GX_SetDispCopyYScale but I didn't notice any difference.

Code:

// other gx setup
GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight);
GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight);
yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight);
xfbHeight = GX_SetDispCopyYScale(yscale);
GX_SetDispCopyDst(rmode->fbWidth,xfbHeight);

Offline

 

Board footer

Powered by FluxBB