void projectm::render() { if(!init_done) init(); #ifdef _WII_ GXColor bgclr = {0,0,0,0xFF}; // Render the next frame in the visualisation/preset short *data = (short*)theapp->audio_data; pm->pcm()->addPCM16Data(data, 512); pm->renderFrame(); // handle the FB GX_SetCopyClear(bgclr,0); GX_SetAlphaUpdate(GX_TRUE); GX_SetColorUpdate(GX_TRUE); whichfb ^= 1; GX_CopyDisp(xfb[whichfb],GX_TRUE); GX_DrawDone(); VIDEO_SetNextFramebuffer(xfb[whichfb]); VIDEO_Flush(); VIDEO_WaitVSync(); #else short *data = (short*)theapp->audio_data; pm->pcm()->addPCM16Data(data, 512); pm->renderFrame(); #endif }
static void init_vtx(GXRModeObj *mode) { GX_SetViewport(0, 0, mode->fbWidth, mode->efbHeight, 0, 1); GX_SetDispCopyYScale(GX_GetYScaleFactor(mode->efbHeight, mode->xfbHeight)); GX_SetScissor(0, 0, mode->fbWidth, mode->efbHeight); GX_SetDispCopySrc(0, 0, mode->fbWidth, mode->efbHeight); GX_SetDispCopyDst(mode->fbWidth, mode->xfbHeight); GX_SetCopyFilter(mode->aa, mode->sample_pattern, (mode->xfbMode == VI_XFBMODE_SF) ? GX_FALSE : GX_TRUE, mode->vfilter); GX_SetCopyClear((GXColor) { 0, 0, 0, 0xff }, GX_MAX_Z24); GX_SetFieldMode(mode->field_rendering, (mode->viHeight == 2 * mode->xfbHeight) ? GX_ENABLE : GX_DISABLE); GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetZMode(GX_ENABLE, GX_ALWAYS, GX_ENABLE); GX_SetColorUpdate(GX_TRUE); GX_SetAlphaUpdate(GX_FALSE); Mtx44 m; guOrtho(m, 1, -1, -1, 1, 0.4, 0.6); GX_LoadProjectionMtx(m, GX_ORTHOGRAPHIC); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_INDEX8); GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetArray(GX_VA_POS, verts, 3 * sizeof(float)); GX_SetArray(GX_VA_TEX0, tex_coords, 2 * sizeof(float)); GX_SetNumTexGens(1); GX_SetNumChans(0); GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLORNULL); GX_InvVtxCache(); GX_Flush(); }
/**************************************************************************** * ResetVideo_Menu * * Reset the video/rendering mode for the menu ****************************************************************************/ void ResetVideo_Menu() { Mtx44 p; f32 yscale; u32 xfbHeight; VIDEO_Configure (vmode); VIDEO_Flush(); VIDEO_WaitVSync(); if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); else while (VIDEO_GetNextField()) VIDEO_WaitVSync(); // clears the bg to color and clears the z buffer GXColor background = {0, 0, 0, 255}; GX_SetCopyClear (background, 0x00ffffff); yscale = GX_GetYScaleFactor(vmode->efbHeight,vmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetDispCopySrc(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetDispCopyDst(vmode->fbWidth,xfbHeight); GX_SetCopyFilter(vmode->aa,vmode->sample_pattern,GX_TRUE,vmode->vfilter); GX_SetFieldMode(vmode->field_rendering,((vmode->viHeight==2*vmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (vmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); // setup the vertex descriptor // tells the flipper to expect direct data GX_ClearVtxDesc(); GX_InvVtxCache (); GX_InvalidateTexAll(); 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_SetNumChans(1); 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); guMtxIdentity(GXmodelView2D); guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -200.0F); GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0); guOrtho(p,0,479,0,639,0,300); GX_LoadProjectionMtx(p, GX_ORTHOGRAPHIC); GX_SetViewport(0,0,vmode->fbWidth,vmode->efbHeight,0,1); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetAlphaUpdate(GX_TRUE); }
//--------------------------------------------------------------------------------- int main( int argc, char **argv ){ //--------------------------------------------------------------------------------- u32 fb; // initial framebuffer index u32 first_frame; f32 yscale; u32 xfbHeight; Mtx44 perspective; Mtx GXmodelView2D; void *gp_fifo = NULL; GXColor background = {0, 0, 0, 0xff}; int i; VIDEO_Init(); rmode = VIDEO_GetPreferredMode(NULL); fb = 0; first_frame = 1; // allocate 2 framebuffers for double buffering frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); fb ^= 1; // setup the fifo and then init the flipper gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gp_fifo,0,DEFAULT_FIFO_SIZE); GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 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(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); // setup the vertex descriptor // tells the flipper to expect direct data GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetNumChans(1); GX_SetNumTexGens(1); GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_InvalidateTexAll(); TPLFile spriteTPL; TPL_OpenTPLFromMemory(&spriteTPL, (void *)textures_tpl,textures_tpl_size); TPL_GetTexture(&spriteTPL,ballsprites,&texObj); GX_LoadTexObj(&texObj, GX_TEXMAP0); guOrtho(perspective,0,479,0,639,0,300); GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC); PAD_Init(); srand(time(NULL)); for(i = 0; i < NUM_SPRITES; i++) { //random place and speed sprites[i].x = (rand() % (640 - 32 )) << 8; sprites[i].y = (rand() % (480 - 32 )) << 8 ; sprites[i].dx = (rand() & 0xFF) + 0x100; sprites[i].dy = (rand() & 0xFF) + 0x100; sprites[i].image = rand() & 3; if(rand() & 1) sprites[i].dx = -sprites[i].dx; if(rand() & 1) sprites[i].dy = -sprites[i].dy; } GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); guMtxIdentity(GXmodelView2D); guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -5.0F); GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetAlphaUpdate(GX_TRUE); GX_SetColorUpdate(GX_TRUE); while(1) { PAD_ScanPads(); if (PAD_ButtonsDown(0) & PAD_BUTTON_START) exit(0); GX_InvVtxCache(); GX_InvalidateTexAll(); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); for(i = 0; i < NUM_SPRITES; i++) { sprites[i].x += sprites[i].dx; sprites[i].y += sprites[i].dy; //check for collision with the screen boundaries if(sprites[i].x < (1<<8) || sprites[i].x > ((640-32) << 8)) sprites[i].dx = -sprites[i].dx; if(sprites[i].y < (1<<8) || sprites[i].y > ((480-32) << 8)) sprites[i].dy = -sprites[i].dy; drawSpriteTex( sprites[i].x >> 8, sprites[i].y >> 8, 32, 32, sprites[i].image); } GX_DrawDone(); GX_CopyDisp(frameBuffer[fb],GX_TRUE); VIDEO_SetNextFramebuffer(frameBuffer[fb]); if(first_frame) { VIDEO_SetBlack(FALSE); first_frame = 0; } VIDEO_Flush(); VIDEO_WaitVSync(); fb ^= 1; // flip framebuffer } return 0; }
static int drawgx_window_create(sdl_window_info *window, int width, int height) { sdl_info *sdl = window->dxdata; u32 xfbHeight; f32 yscale; Mtx44 perspective; Mtx GXmodelView2D; GXColor background = {0, 0, 0, 0xff}; currfb = 0; // allocate memory for our structures sdl = malloc(sizeof(*sdl)); memset(sdl, 0, sizeof(*sdl)); window->dxdata = sdl; sdl->scale_mode = &scale_modes[window->scale_mode]; sdl->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); sdl->extra_flags |= sdl->scale_mode->extra_flags; /*sdl->sdlsurf = SDL_SetVideoMode(width, height, 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags);*/ //sdl->sdlsurf = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF); //if (!sdl->sdlsurf) // return 1; window->width = gx_screenWidth();//sdl->sdlsurf->w; window->height = 480;//sdl->sdlsurf->h; sdl->safe_hofs = (window->width - window->width * options_get_float(mame_options(), SDLOPTVAL_SAFEAREA)) / 2; sdl->safe_vofs = (window->height - window->height * options_get_float(mame_options(), SDLOPTVAL_SAFEAREA)) / 2; /*if (sdl->scale_mode->is_yuv) yuv_overlay_init(window);*/ sdl->yuv_lookup = NULL; sdl->blittimer = 0; //if (is_inited) return 0; //is_inited = 1; //drawgx_yuv_init(sdl); //SDL_QuitSubSystem(SDL_INIT_VIDEO); if (is_inited) return 0; is_inited = 1; VIDEO_Init(); VIDEO_SetBlack(true); vmode = VIDEO_GetPreferredMode(NULL); switch (vmode->viTVMode >> 2) { case VI_PAL: vmode = &TVPal574IntDfScale; vmode->xfbHeight = 480; vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - 480)/2; vmode->viHeight = 480; break; case VI_NTSC: break; default: break; } VIDEO_Configure(vmode); xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode)); xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode)); VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); VIDEO_SetNextFramebuffer(xfb[currfb]); VIDEO_Flush(); VIDEO_WaitVSync(); if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); else while (VIDEO_GetNextField()) VIDEO_WaitVSync(); gp_fifo = memalign(32, DEFAULT_FIFO_SIZE); memset(gp_fifo, 0, DEFAULT_FIFO_SIZE); GX_Init(gp_fifo, DEFAULT_FIFO_SIZE); atexit(drawgx_shutdown); GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,vmode->fbWidth,vmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(vmode->efbHeight,vmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetDispCopySrc(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetDispCopyDst(vmode->fbWidth,xfbHeight); GX_SetCopyFilter(vmode->aa,vmode->sample_pattern,GX_TRUE,vmode->vfilter); GX_SetFieldMode(vmode->field_rendering,((vmode->viHeight==2*vmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (vmode->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[currfb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); GX_SetNumChans(1); GX_SetNumTexGens(1); GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetAlphaUpdate(GX_TRUE); GX_SetColorUpdate(GX_TRUE); guOrtho(perspective,0,479,0,gx_screenWidth()-1,0,300); GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC); guMtxIdentity(GXmodelView2D); guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -5.0F); GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0); GX_SetViewport(0,0,vmode->fbWidth,vmode->efbHeight,0,1); GX_InvVtxCache(); GX_ClearVtxDesc(); GX_InvalidateTexAll(); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); VIDEO_SetBlack(false); GX_InitTexObj(&blankTex, blanktex, 1, 1, GX_TF_RGB5A3, GX_CLAMP, GX_CLAMP, GX_FALSE); return 0; }
void REV_init() { //Local variables f32 yscale; u32 xfbHeight; //Load the right IOS, so keyboard works fin u32 iosVersion = IOS_GetVersion(); if(iosVersion != 36) { IOS_ReloadIOS(36); } //// VIDEO_Init();//Video Library Init PAD_Init();//Gamecube Pad Library Init WPAD_Init();//Wiimote Library Init rMode = VIDEO_GetPreferredMode(NULL);//Set render mode // allocate 2 framebuffers for double buffering frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rMode)); frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rMode)); //Configure Video System VIDEO_Configure(rMode); VIDEO_SetNextFramebuffer(frameBuffer[fb]);//Initial Framebuffer VIDEO_Flush(); VIDEO_WaitVSync(); if(rMode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); fb ^= 1;//Set next index //Set up the FIFO void *gp_fifo = memalign(32,DEFAULT_FIFO_SIZE);//Allocate memset(gp_fifo,0,DEFAULT_FIFO_SIZE);//and Clear //Init GX hardware GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(DEF_BG_COLOR , 0x00ffffff); //More initialization w = rMode->viWidth; h = rMode->viHeight; yscale = GX_GetYScaleFactor(rMode->efbHeight,rMode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetDispCopySrc(0,0,rMode->fbWidth,rMode->efbHeight); GX_SetDispCopyDst(rMode->fbWidth,xfbHeight); GX_SetFieldMode(rMode->field_rendering,((h==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_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); for(u8 i = 0; i < 4; i++) WPAD_SetVRes(i,w,h); //Hardware Initialized, now engine initialization //Init filesystem fatInitDefault(); //First create a Root mainRoot = new ROOT; mainRoot->init((f32)w,(f32)h); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetColorUpdate(GX_ENABLE); GX_SetAlphaUpdate(GX_ENABLE); GX_SetZCompLoc(GX_TRUE); GX_SetZMode (GX_TRUE, GX_LEQUAL, GX_TRUE); init3dConfig(); init2dConfig(); init2D(w, h); transQueue = NULL; solidQueue = NULL; zQueue = NULL; REV_fontsInit(); KEYBOARD_Init(NULL); keyboardInit(); }
void Particle_Render(Mtx M_view, ParticleSystem* psystem, Camera* camera) { // setup TEV GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); // load model-view matrix Mtx M_modelView; guMtxIdentity(M_modelView); GX_LoadPosMtxImm(M_modelView, GX_PNMTX0); // setup tev GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetAlphaUpdate(GX_TRUE); GX_SetNumChans(1); GX_SetTevColorIn( GX_TEVSTAGE0, GX_CC_TEXC, // a GX_CC_RASC, // b GX_CC_TEXA, // c GX_CC_ZERO); // d GX_SetTevColorOp( GX_TEVSTAGE0, // stage GX_TEV_ADD, // op GX_TB_ZERO, // bias GX_CS_SCALE_2, // scale GX_ENABLE, // clamp 0-255 GX_TEVPREV); // output reg GX_SetTevAlphaIn( GX_TEVSTAGE0, GX_CA_ZERO, // a GX_CA_TEXA, // b GX_CA_RASA, // c GX_CA_ZERO); // d GX_SetTevAlphaOp( GX_TEVSTAGE0, // stage GX_TEV_ADD, // op GX_TB_ZERO, // bias GX_CS_SCALE_1, // scale GX_ENABLE, // clamp 0-255 GX_TEVPREV); // output reg GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetNumTexGens(1); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_LoadTexObj(&psystem->texture, GX_TEXMAP0); int n = psystem->n_particles; f32 texCoords[] = { 0, 0, 0, 1, 1, 1, 1, 0 }; GX_InvVtxCache(); Vec3 camPos = camera->position(); Mtx axisMtx; System::LogClear(); Particle_Sort(M_view, psystem); GX_Begin(GX_QUADS, GX_VTXFMT6, n*4); for (int k = 0; k < n; k++) { int i = psystem->binsAllocations[k].particleIdx; //System::Log(L"p%d", i); Vec3& p = psystem->positions[i]; f32 lifetime = psystem->lifetimes[i]; f32 age = psystem->ages[i]; f32 ratio = age/lifetime; Vec3 forward = Math3D::normalized(camPos - p); Vec3 worldUp = Vec3(0, 1, 0); Vec3 right = Math3D::normalized(Math3D::cross(worldUp, forward)); Vec3 up = Math3D::cross(forward, right); Mtx pm; guMtxCopy(M_view, pm); guMtxTranspose(pm, pm); pm[0][3] = p.x; pm[1][3] = p.y; pm[2][3] = p.z; guMtxConcat(M_view, pm, pm); f32 rotation = psystem->rotations[i]; if (psystem->rotationInterpolator) rotation = psystem->rotationInterpolator->getValue(rotation, ratio); f32 size = psystem->sizes[i]; if (psystem->sizeInterpolator) size = psystem->sizeInterpolator->getValue(size, ratio); if (psystem->colorInterpolator) psystem->colors[i] = psystem->colorInterpolator->getValue(ratio); Matrix34 M_rot = Math3D::matrixRotationZ(rotation); f32 hs = size*0.5f; Vec3 p0(-hs, +hs, 0); Vec3 p1(-hs, -hs, 0); Vec3 p2(+hs, -hs, 0); Vec3 p3(+hs, +hs, 0); Vec3 vs[4] = {p0, p1, p2, p3}; for (int i = 0; i < 4; i++) { vs[i] = M_rot * vs[i]; vs[i] = Math3D::matrixVecMul(pm, vs[i]); } for (int i = 0; i < 4; i++) { f32* coords = &texCoords[2*i]; SendVertex(vs[i], psystem->colors[i], coords[0], coords[1]); } } GX_End(); return; }
// nyanise the system void nyan() { // subsystem VIDEO_Init(); WPAD_Init(); ASND_Init(); MP3Player_Init(); // video setup wichFb = 0; rmode = VIDEO_GetPreferredMode(NULL); xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(xfb[wichFb]); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); wichFb ^= 1; // setup the fifo and then init gx gp_fifo = memalign(32, DEFAULT_FIFO_SIZE); memset(gp_fifo, 0, DEFAULT_FIFO_SIZE); GX_Init(gp_fifo, DEFAULT_FIFO_SIZE); // other gx setup GX_SetViewport(0, 0, rmode->fbWidth, rmode->efbHeight, 0, 1); 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[wichFb], GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetAlphaUpdate(GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_SetCopyClear(background, 0x00ffffff); // empty the vertex descriptor GX_InvVtxCache(); GX_InvalidateTexAll(); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); // tev is like shadow for me (i don't really understand these Chans, and TevOps-nyan-thing things) GX_SetNumChans(1); GX_SetNumTexGens(1); GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_InvalidateTexAll(); // Load the spriteSheet TPLFile spriteTPL; TPL_OpenTPLFromMemory(&spriteTPL, (void *)textures_tpl, textures_tpl_size); TPL_GetTexture(&spriteTPL, spritesheet, &spriteSheetTexture); // no filtering plz GX_InitTexObjLOD(&spriteSheetTexture, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); GX_LoadTexObj(&spriteSheetTexture, GX_TEXMAP0); // Load texture in slot 0 into gx // Setup the view GX_SetViewport(0, 0, rmode->fbWidth, rmode->efbHeight, 0, 1); guOrtho(perspective, 0, 479, 0, 639, 0, 300); GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC); startTime = ticks_to_millisecs(gettime()); bkgTimeCounter = startTime; nyanTimeCounter = startTime; currentBkgStep = 0; currentNyanStep = 0; }
static void ghost_display_effect (sync_info *sync, void *params, int iparam) { glass_data *gdata = (glass_data *) params; /*GXTexObj spiderweb_tex_obj;*/ Mtx mvtmp, rot, mvtmp2; Mtx sep_scale; f32 indmtx[2][3]; /* Channels for indirect lookup go: R -> - G -> U B -> T A -> S We have G/B channels, so map those to S/T. */ indmtx[0][0] = 0.0; indmtx[0][1] = 0.5; indmtx[0][2] = 0.0; indmtx[1][0] = 0.0; indmtx[1][1] = 0.0; indmtx[1][2] = 0.5; GX_SetIndTexMatrix (GX_ITM_0, indmtx, 2); GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_FALSE); GX_SetBlendMode (GX_BM_NONE, GX_BL_ONE, GX_BL_ONE, GX_LO_SET); GX_SetColorUpdate (GX_TRUE); GX_SetAlphaUpdate (GX_FALSE); GX_SetCullMode (GX_CULL_NONE); screenspace_rect (gdata->refraction_postpass_shader, GX_VTXFMT1, 1); /*GX_LoadTexObj (&spiderweb_tex_obj, GX_TEXMAP1); draw_square (1, 128 + 127 * sin (thr * M_PI / 360.0), 128 + 127 * sin (thr * M_PI / 200.0));*/ guMtxIdentity (mvtmp); guMtxRotAxisDeg (rot, &((guVector) { 0, 1, 0 }), gdata->thr); guMtxConcat (rot, mvtmp, mvtmp); guMtxRotAxisDeg (rot, &((guVector) { 1, 0, 0 }), gdata->thr * 0.7); guMtxConcat (rot, mvtmp, mvtmp); /*guMtxScale (sep_scale, 6.0, 6.0, 6.0);*/ set_sep_scale (sep_scale, sync); guMtxTransApply (mvtmp, mvtmp2, gdata->xoffset, 0, 0); object_set_matrices (&scene, &gdata->obj_loc, scene.camera, mvtmp2, sep_scale, perspmat, GX_PERSPECTIVE); shader_load (gdata->glass_postpass_shader); GX_SetBlendMode (GX_BM_BLEND, GX_BL_ONE, GX_BL_SRCALPHA, GX_LO_SET); object_set_arrays (&blobby_thing_obj, OBJECT_POS | OBJECT_NORM, GX_VTXFMT0, 0); object_render (&blobby_thing_obj, OBJECT_POS | OBJECT_NORM, GX_VTXFMT0); /* guMtxTransApply (mvtmp, mvtmp2, 13, 0, 0); object_set_matrices (&scene, &gdata->obj_loc, scene.camera, mvtmp2, sep_scale, NULL, 0); object_render (&spooky_ghost_obj, OBJECT_POS | OBJECT_NORM, GX_VTXFMT0); guMtxTransApply (mvtmp, mvtmp2, -13, 0, 0); object_set_matrices (&scene, &gdata->obj_loc, scene.camera, mvtmp2, sep_scale, NULL, 0); object_render (&spooky_ghost_obj, OBJECT_POS | OBJECT_NORM, GX_VTXFMT0); */ gdata->thr += 1; }
static display_target ghost_prepare_frame (sync_info *sync, void *params, int iparam) { glass_data *gdata = (glass_data *) params; /*GXTexObj spiderweb_tex_obj;*/ Mtx mvtmp, rot, mvtmp2; Mtx sep_scale; /*TPL_GetTexture (&spiderwebTPL, spiderweb, &spiderweb_tex_obj);*/ GX_InvalidateTexAll (); rendertarget_texture (RTT_WIDTH, RTT_HEIGHT, COPYFMT, GX_FALSE, GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_FALSE); GX_SetBlendMode (GX_BM_NONE, GX_BL_ONE, GX_BL_ONE, GX_LO_SET); GX_SetColorUpdate (GX_TRUE); GX_SetAlphaUpdate (GX_FALSE); screenspace_rect (gdata->plain_texture_shader, GX_VTXFMT1, 0); GX_SetCopyClear ((GXColor) { 128, 128, 128, 0 }, 0x00ffffff); GX_CopyTex (gdata->grabbed_texture, GX_TRUE); GX_PixModeSync (); rendertarget_texture (RTT_WIDTH, RTT_HEIGHT, COPYFMT, GX_FALSE, GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetCopyClear ((GXColor) { 128, 128, 128, 0 }, 0x00ffffff); GX_SetColorUpdate (GX_TRUE); GX_SetAlphaUpdate (GX_FALSE); /* We need a grey background! This isn't very efficient though. */ GX_CopyTex (gdata->grabbed_texture, GX_TRUE); GX_SetCopyClear ((GXColor) { 0, 0, 0, 0 }, 0x00ffffff); GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_FALSE); GX_SetBlendMode (GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET); GX_SetColorUpdate (GX_TRUE); GX_SetAlphaUpdate (GX_FALSE); GX_SetCullMode (GX_CULL_NONE); guMtxIdentity (mvtmp); guMtxRotAxisDeg (rot, &((guVector) { 0, 1, 0 }), gdata->thr); guMtxConcat (rot, mvtmp, mvtmp); guMtxRotAxisDeg (rot, &((guVector) { 1, 0, 0 }), gdata->thr * 0.7); guMtxConcat (rot, mvtmp, mvtmp); if (sync->time_offset < 1000) gdata->xoffset = -(float) (1000 - sync->time_offset) / 10.0; else if (sync->time_offset > 16000) gdata->xoffset = (float) (sync->time_offset - 16000) / 10.0; else gdata->xoffset = 0.0; /*guMtxScale (sep_scale, 6.0, 6.0, 6.0);*/ set_sep_scale (sep_scale, sync); guMtxTransApply (mvtmp, mvtmp2, gdata->xoffset, 0, 0); object_set_matrices (&scene, &gdata->obj_loc, scene.camera, mvtmp2, sep_scale, perspmat, GX_PERSPECTIVE); light_update (scene.camera, &light0); shader_load (gdata->refraction_shader); object_set_arrays (&blobby_thing_obj, OBJECT_POS | OBJECT_NORM, GX_VTXFMT0, 0); object_render (&blobby_thing_obj, OBJECT_POS | OBJECT_NORM, GX_VTXFMT0); /* guMtxTransApply (mvtmp, mvtmp2, 13, 0, 0); object_set_matrices (&scene, &gdata->obj_loc, scene.camera, mvtmp2, sep_scale, NULL, 0); object_render (&spooky_ghost_obj, OBJECT_POS | OBJECT_NORM, GX_VTXFMT0); guMtxTransApply (mvtmp, mvtmp2, -13, 0, 0); object_set_matrices (&scene, &gdata->obj_loc, scene.camera, mvtmp2, sep_scale, NULL, 0); object_render (&spooky_ghost_obj, OBJECT_POS | OBJECT_NORM, GX_VTXFMT0); */ GX_CopyTex (gdata->grabbed_texture, GX_TRUE); GX_PixModeSync (); return MAIN_BUFFER; }