static void render_texture (greets_data *gdata, float zpos, float scroll) { world_info *world = gdata->world; Mtx mvtmp; extern Mtx tube_rotmtx; guMtxIdentity (mvtmp); guMtxConcat (mvtmp, tube_rotmtx, mvtmp); object_set_matrices (&world->scene, &gdata->greets_loc, world->scene.camera, mvtmp, NULL, world->projection, world->projection_type); 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_XYZ, GX_F32, 0); GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetCullMode (GX_CULL_NONE); scroll = scroll * 8.0f; scroll = scroll - floorf (scroll); scroll = scroll * 1./8; GX_Begin (GX_TRIANGLESTRIP, GX_VTXFMT0, 4); GX_Position3f32 (-40, 8, 0); GX_TexCoord2f32 (scroll, 0); GX_Position3f32 (40, 8, 0); GX_TexCoord2f32 (4 + scroll, 0); GX_Position3f32 (-40, -8, 0); GX_TexCoord2f32 (scroll, 0.5); GX_Position3f32 (40, -8, 0); GX_TexCoord2f32 (4 + scroll, 0.5); GX_End (); GX_Begin (GX_TRIANGLESTRIP, GX_VTXFMT0, 4); GX_Position3f32 (-40, 0, 8); GX_TexCoord2f32 (scroll, 0); GX_Position3f32 (40, 0, 8); GX_TexCoord2f32 (4 + scroll, 0); GX_Position3f32 (-40, 0, -8); GX_TexCoord2f32 (scroll, 0.5); GX_Position3f32 (40, 0, -8); GX_TexCoord2f32 (4 + scroll, 0.5); GX_End (); }
void InitVideo() { VIDEO_Init(); // If WiiU - Force 16:9 aspect ratio based on WiiU settings if(isWiiU() && Settings.widescreen) { write32(0xd8006a0, 0x30000004), mask32(0xd8006a8, 0, 2); } vmode = VIDEO_GetPreferredMode(NULL); // get default video mode vmode->viWidth = Settings.widescreen ? 708 : 694; if (Settings.PAL50) { vmode->viXOrigin = (VI_MAX_WIDTH_PAL - vmode->viWidth) / 2; } else { vmode->viXOrigin = (VI_MAX_WIDTH_NTSC - vmode->viWidth) / 2; } VIDEO_Configure(vmode); screenheight = 480; screenwidth = vmode->fbWidth; // Allocate the video buffers xfb[0] = (u32 *) MEM_K0_TO_K1 ( SYS_AllocateFramebuffer ( vmode ) ); xfb[1] = (u32 *) MEM_K0_TO_K1 ( SYS_AllocateFramebuffer ( vmode ) ); // Clear framebuffers etc. VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); VIDEO_SetNextFramebuffer(xfb[0]); VIDEO_Flush(); VIDEO_WaitVSync(); if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); // Initialize GX GXColor background = { 0, 0, 0, 0xff }; gp_fifo = (u8 *) memalign(32, GP_FIFO_SIZE); memset (gp_fifo, 0, GP_FIFO_SIZE); GX_Init (gp_fifo, GP_FIFO_SIZE); GX_SetCopyClear (background, 0x00ffffff); GX_SetDispCopyGamma (GX_GM_1_0); GX_SetCullMode (GX_CULL_NONE); ResetVideo_Menu(); VIDEO_SetBlack(FALSE); // Finally, the video is up and ready for use :) }
void drawInit() { Mtx44 GXprojection2D; Mtx GXmodelView2D; // Reset various parameters from gfx plugin GX_SetCoPlanar(GX_DISABLE); GX_SetClipMode(GX_CLIP_ENABLE); // GX_SetScissor(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetAlphaCompare(GX_ALWAYS,0,GX_AOP_AND,GX_ALWAYS,0); guMtxIdentity(GXmodelView2D); GX_LoadTexMtxImm(GXmodelView2D,GX_TEXMTX0,GX_MTX2x4); GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0); guOrtho(GXprojection2D, 0, 479, 0, 639, 0, 700); GX_LoadProjectionMtx(GXprojection2D, GX_ORTHOGRAPHIC); // GX_SetViewport (0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1); GX_SetZMode(GX_DISABLE,GX_ALWAYS,GX_TRUE); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_PTNMTXIDX, GX_PNMTX0); GX_SetVtxDesc(GX_VA_TEX0MTXIDX, GX_TEXMTX0); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); //set vertex attribute formats here GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_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); //enable textures GX_SetNumChans (1); GX_SetNumTexGens (1); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_SetNumTevStages (1); GX_SetTevOrder (GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR); //set blend mode GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); //Fix src alpha GX_SetColorUpdate(GX_ENABLE); // GX_SetAlphaUpdate(GX_ENABLE); // GX_SetDstAlpha(GX_DISABLE, 0xFF); //set cull mode GX_SetCullMode (GX_CULL_NONE); }
/**************************************************************************** * StartGX * * Initialises GX and sets it up for use ***************************************************************************/ static void StartGX () { GXColor background = { 0, 0, 0, 0xff }; /*** Clear out FIFO area ***/ memset (&gp_fifo, 0, DEFAULT_FIFO_SIZE); /*** Initialise GX ***/ GX_Init (&gp_fifo, DEFAULT_FIFO_SIZE); GX_SetCopyClear (background, 0x00ffffff); GX_SetDispCopyGamma (GX_GM_1_0); GX_SetCullMode (GX_CULL_NONE); }
void wii_video_init(void) { VIDEO_Init(); GXRModeObj *mode = VIDEO_GetPreferredMode(NULL); setup_video_mode(mode); GX_Init(gx_fifo, sizeof(gx_fifo)); GX_SetDispCopyGamma(GX_GM_1_0); GX_SetCullMode(GX_CULL_NONE); GX_SetClipMode(GX_CLIP_DISABLE); init_vtx(mode); build_disp_list(); g_filter = true; g_vsync = true; }
void initialise_video(GXRModeObj *m) { VIDEO_Configure (m); if(xfb[0]) free(MEM_K1_TO_K0(xfb[0])); if(xfb[1]) free(MEM_K1_TO_K0(xfb[1])); xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (m)); xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (m)); VIDEO_ClearFrameBuffer (m, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer (m, xfb[1], COLOR_BLACK); VIDEO_SetNextFramebuffer (xfb[0]); VIDEO_SetPostRetraceCallback (ProperScanPADS); VIDEO_SetBlack (0); VIDEO_Flush (); VIDEO_WaitVSync (); if (m->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); else while (VIDEO_GetNextField()) VIDEO_WaitVSync(); // setup the fifo and then init GX if(gp_fifo == NULL) { gp_fifo = MEM_K0_TO_K1 (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 ((GXColor) {0, 0, 0, 0xFF}, GX_MAX_Z24); // init viewport GX_SetViewport (0, 0, m->fbWidth, m->efbHeight, 0, 1); // Set the correct y scaling for efb->xfb copy operation GX_SetDispCopyYScale ((f32) m->xfbHeight / (f32) m->efbHeight); GX_SetDispCopySrc (0, 0, m->fbWidth, m->efbHeight); GX_SetDispCopyDst (m->fbWidth, m->xfbHeight); GX_SetCopyFilter (m->aa, m->sample_pattern, GX_TRUE, m->vfilter); GX_SetFieldMode (m->field_rendering, ((m->viHeight == 2 * m->xfbHeight) ? GX_ENABLE : GX_DISABLE)); if (m->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); // default in rsp init GX_CopyDisp (xfb[0], GX_TRUE); // This clears the efb GX_CopyDisp (xfb[0], GX_TRUE); // This clears the xfb }
void skybox_render (skybox_info *skybox) { const u32 vtxfmt = GX_VTXFMT0; int face; GX_ClearVtxDesc (); GX_SetVtxDesc (GX_VA_POS, GX_INDEX8); GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT); GX_SetArray (GX_VA_POS, vertices, 3 * sizeof (f32)); GX_SetVtxAttrFmt (vtxfmt, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt (vtxfmt, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetCullMode (GX_CULL_BACK); for (face = 0; face < 6; face++) { shader_load (skybox->face_shader[face]); GX_Begin (GX_TRIANGLESTRIP, vtxfmt, 4); GX_Position1x8 (faces[face][0]); GX_TexCoord2f32 (0, 1); GX_Position1x8 (faces[face][1]); GX_TexCoord2f32 (0, 0); GX_Position1x8 (faces[face][2]); GX_TexCoord2f32 (1, 1); GX_Position1x8 (faces[face][3]); GX_TexCoord2f32 (1, 0); GX_End (); } }
//--------------------------------------------------------------------------------- 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; }
void REV_process(tMapQ3 * map) { //Variables f32 preWait = 0, postWait = 0; static u8 firstFrame = 1; TRACKER * auxT; setUp3D(); //Wait just before drawing (instead of after), this should enhance performance VIDEO_Flush(); preWait = (f32)(ticks_to_millisecs(gettime())); VIDEO_WaitVSync(); postWait = (f32)(ticks_to_millisecs(gettime())); GPUWaitTime = 0.001f * (postWait - preWait); //Update physics updatePhysics(); setBGColor(SC_BLUE); //Clasify objects into solid or transparent queues //This is done before everything else because this clasification is the same for every viewport clasify3D(mainRoot->rootNode); //Now we use the clasified queues to render shadows //if(mainRoot->shadowCaster) //mainRoot->shadowScene(); //Render each Viewport into it's texture GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); //GX_SetZMode (GX_TRUE, GX_LEQUAL, GX_TRUE); std::multimap<CAMERA*, TRender2Texture*>::iterator iter = mainRoot->m_Render2Textures.begin(); for(;iter != mainRoot->m_Render2Textures.end(); ++iter) { (*iter).second->setForRender(perspective); (*iter).second->getCamera()->setForRender(view); //Before rendering the scene, render the skyBox GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_TRUE); mainRoot->skyBox.render((*iter).second->getCamera()); GX_SetZMode (GX_TRUE, GX_LEQUAL, GX_TRUE); //Now render the map //GX_LoadPosMtxImm(view, GX_PNMTX0); //if(map) //renderQ3Map(tTex->cam->getPos(), map); //Now render objects GX_SetCullMode(GX_CULL_NONE); auxT = solidQueue; while(auxT) { render(auxT->target, (*iter).second->getCamera()->getPos()); auxT = auxT->next; } orderQueue((*iter).second->getCamera()); auxT = transQueue; while(auxT) { render(auxT->target, (*iter).second->getCamera()->getPos()); auxT = auxT->next; } //Copy the embeded frame buffer to the texture (*iter).second->copyTexture(); } while(solidQueue) { auxT = solidQueue; solidQueue = solidQueue->next; free(auxT); } while(transQueue) { auxT = transQueue; transQueue = transQueue->next; free(auxT); } setBGColor(SC_WHITE); //2D System //GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_TRUE); GX_SetCopyFilter(rMode->aa,rMode->sample_pattern,GX_TRUE,rMode->vfilter); GX_SetViewport(0,0, w, h,0,1); GX_SetScissor(0,0, w, h); guOrtho(perspective,0,h,0,w, 1.0,100.0); GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC); GX_SetCullMode(GX_CULL_NONE); setUp2D(); parse2D(mainRoot->rootN2D); order2D(); render2D(); GX_DrawDone(); GX_CopyDisp(frameBuffer[fb],GX_TRUE); VIDEO_SetNextFramebuffer(frameBuffer[fb]); //Set out black screen after first frame if(firstFrame) { firstFrame = 0; VIDEO_SetBlack(FALSE); } fb ^= 1; }
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; }
void glEnd(void) { GX_SetCullMode(GX_CULL_FRONT); Mtx mvi; Mtx mv; // Mtx inversemodelview; // load the modelview matrix into matrix memory guMtxConcat(view,model,modelview); GX_LoadPosMtxImm(modelview, GX_PNMTX0); //for normals first calculate normal matrix (thanks shagkur) guMtxInverse(modelview,mvi); guMtxTranspose(mvi,modelview); GX_LoadNrmMtxImm(modelview,GX_PNMTX0); //experimtal leave out (hmm works good?) //use global ambient light together with current material ambient and add emissive material color GXColor constcolor; constcolor.r = (gxcurrentmaterialambientcolor.r*gxglobalambientlightcolor.r) * 0xFF; constcolor.g = (gxcurrentmaterialambientcolor.g*gxglobalambientlightcolor.g) * 0xFF; constcolor.b = (gxcurrentmaterialambientcolor.b*gxglobalambientlightcolor.b) * 0xFF; constcolor.a = (gxcurrentmaterialambientcolor.a*gxglobalambientlightcolor.a) * 0xFF; GX_SetTevColor(GX_TEVREG0, constcolor); GXColor emiscolor; emiscolor.r = gxcurrentmaterialemissivecolor.r * 0xFF; emiscolor.g = gxcurrentmaterialemissivecolor.g * 0xFF; emiscolor.b = gxcurrentmaterialemissivecolor.b * 0xFF; emiscolor.a = gxcurrentmaterialemissivecolor.a * 0xFF; GX_SetTevColor(GX_TEVREG1, emiscolor); //first check if a lightdirtyflag is set (thanks ector) so we do not have to set up light every run //also usefull on matrices etc. //now set each light GXColor gxchanambient; gxchanambient.r = gxcurrentmaterialambientcolor.r; gxchanambient.g = gxcurrentmaterialambientcolor.g; gxchanambient.b = gxcurrentmaterialambientcolor.b; gxchanambient.a = gxcurrentmaterialambientcolor.a; GXColor gxchanspecular; gxchanspecular.r = gxcurrentmaterialspecularcolor.r; gxchanspecular.g = gxcurrentmaterialspecularcolor.g; gxchanspecular.b = gxcurrentmaterialspecularcolor.b; gxchanspecular.a = gxcurrentmaterialspecularcolor.a; int lightcounter = 0; for (lightcounter =0; lightcounter < 4; lightcounter++){ if(gxlightenabled[lightcounter]){ //when light is enabled //somewhere here an error happens? //Setup mat/light ambient color gxchanambient.r = ((gxchanambient.r * gxlightambientcolor[lightcounter].r) * 0xFF); gxchanambient.g = ((gxchanambient.g * gxlightambientcolor[lightcounter].g) * 0xFF); gxchanambient.b = ((gxchanambient.b * gxlightambientcolor[lightcounter].b) * 0xFF); gxchanambient.a = ((gxchanambient.a * gxlightambientcolor[lightcounter].a) * 0xFF); GX_SetChanAmbColor(GX_COLOR0A0, gxchanambient ); //Setup diffuse material color GXColor mdc; mdc.r = (gxcurrentmaterialdiffusecolor.r * 0xFF); mdc.g = (gxcurrentmaterialdiffusecolor.g * 0xFF); mdc.b = (gxcurrentmaterialdiffusecolor.b * 0xFF); mdc.a = (gxcurrentmaterialdiffusecolor.a * 0xFF); GX_SetChanMatColor(GX_COLOR0A0, mdc ); //Setup specular material color // gxcurrentmaterialshininess * gxchanspecular.r = (gxchanspecular.r * gxlightspecularcolor[lightcounter].r) * 0xFF; gxchanspecular.g = (gxchanspecular.g * gxlightspecularcolor[lightcounter].g) * 0xFF; gxchanspecular.b = (gxchanspecular.b * gxlightspecularcolor[lightcounter].b) * 0xFF; gxchanspecular.a = (gxchanspecular.a * gxlightspecularcolor[lightcounter].a) * 0xFF; GX_SetChanMatColor(GX_COLOR1A1, gxchanspecular); // use red as test color //Setup light diffuse color GXColor ldc; ldc.r = gxlightdiffusecolor[lightcounter].r * 0xFF; ldc.g = gxlightdiffusecolor[lightcounter].g * 0xFF; ldc.b = gxlightdiffusecolor[lightcounter].b * 0xFF; ldc.a = gxlightdiffusecolor[lightcounter].a * 0xFF; GX_InitLightColor(&gxlight[lightcounter], ldc ); //move call to glend or init?; GX_InitLightColor(&gxlight[lightcounter+4], ldc ); //move call to glend or init?; //Setup light postion //check on w component when 1. light is positional // when 0. light is directional at infinite pos guVector lpos; guVector wpos; lpos.x = gxlightpos[lightcounter].x; lpos.y = gxlightpos[lightcounter].y; lpos.z = gxlightpos[lightcounter].z; if (gxlightpos[lightcounter].w == 0){ guVecNormalize(&lpos); lpos.x *= BIG_NUMBER; lpos.y *= BIG_NUMBER; lpos.z *= BIG_NUMBER; } guVecMultiply(view,&lpos,&wpos); //light position should be transformed by world-to-view matrix (thanks h0lyRS) GX_InitLightPosv(&gxlight[lightcounter], &wpos); //feed corrected coord to light pos GX_InitLightPosv(&gxlight[lightcounter+4], &wpos); //feed corrected coord to light pos //Setup light direction (when w is 1 dan dir = 0,0,0 guVector ldir; if (gxlightpos[lightcounter].w==0){ //lpos.x = gxlightpos[lightcounter].x; //lpos.y = gxlightpos[lightcounter].y; //lpos.z = gxlightpos[lightcounter].z; ldir.x = gxlightpos[lightcounter].x; ldir.y = gxlightpos[lightcounter].y; ldir.z = gxlightpos[lightcounter].z; } else { if (gxspotcutoff[lightcounter] != 180){ //if we have a spot light direction is needed ldir.x = gxspotdirection[lightcounter].x; ldir.y = gxspotdirection[lightcounter].y; ldir.z = gxspotdirection[lightcounter].z; } else { ldir.x = 0; ldir.y = 0; ldir.z = -1; } } //guVecNormalize(&ldir); //ldir.x *= BIG_NUMBER; //ldir.y *= BIG_NUMBER; //ldir.z *= BIG_NUMBER; guMtxInverse(view,mvi); guMtxTranspose(mvi,view); guVecMultiply(view,&ldir,&ldir); //and direction should be transformed by inv-transposed of world-to-view (thanks h0lyRS) GX_InitLightDir(&gxlight[lightcounter], ldir.x, ldir.y, ldir.z); //feed corrected coord to light dir GX_InitLightDir(&gxlight[lightcounter+4], ldir.x, ldir.y, ldir.z); //feed corrected coord to light dir if (gxspotcutoff[lightcounter] != 180){ //Setup specular light (only for spotlight when GL_SPOT_CUTOFF <> 180) //make this line optional? If on it disturbs diffuse light? guVector sdir; sdir.x = gxspotdirection[lightcounter].x; sdir.y = gxspotdirection[lightcounter].y; sdir.z = gxspotdirection[lightcounter].z; //guVecNormalize(&sdir); //sdir.x *= BIG_NUMBER; //sdir.y *= BIG_NUMBER; //sdir.z *= BIG_NUMBER; guVecMultiply(view,&sdir,&sdir); guVector light_dir; guVecSub(&sdir, &lpos, &light_dir); GX_TestInitSpecularDir(&gxlight[lightcounter], light_dir.x, light_dir.y, light_dir.z); //needed to enable specular light GX_TestInitSpecularDir(&gxlight[lightcounter+4], light_dir.x, light_dir.y, light_dir.z); //needed to enable specular light }; //this calls: // #define GX_InitLightShininess(lobj, shininess) (GX_InitLightAttn(lobj, 0.0F, 0.0F, 1.0F, (shininess)/2.0F, 0.0F, 1.0F-(shininess)/2.0F )) //Setup distance attinuation (opengl vs gx differences?) //GX_InitLightDistAttn(&gxlight[lightcounter], 100.0f, gxspotexponent[lightcounter], GX_DA_GENTLE); //gxspotexponent was 0.5f //ref_dist, bright, dist func //k0 = 1.0; //k1 = 0.5f*(1.0f-ref_brite)/(ref_brite*ref_dist); //k2 = 0.5f*(1.0f-ref_brite)/(ref_brite*ref_dist*ref_dist); or 0.0f; //Attenuation factor = 1 / (kc + kl*d + kq*d2) //kc = constant attenuation factor (default = 1.0) //kl = linear attenuation factor (default = 0.0) //kq = quadratic attenuation factor (default = 0.0) float distance = BIG_NUMBER; //either distance of light or falloff factor float factor = 1 / (gxconstantattanuation[lightcounter] + gxlinearattanuation[lightcounter]*distance + gxquadraticattanuation[lightcounter]*distance*distance); //float factor = 5.0; //k0 - 0; //k1 = 0.5f*(1.0f-ref_brite)/(ref_brite*ref_dist); //k2 = 0.5f*(1.0f-ref_brite)/(ref_brite*ref_dist*ref_dist); /* GX_InitLightAttn(&gxlight[lightcounter], 1.0, //filled by initlightspot 0.0, //filled by initlightspot 0.0, //filled by initlightspot gxconstantattanuation[lightcounter], gxlinearattanuation[lightcounter]*distance, gxquadraticattanuation[lightcounter]*distance*distance ) ; // k0 k1 , k2 */ //GX_InitLightAttnK(&gxlight[lightcounter], (gxcurrentmaterialshininess)/2.0F , 0.0F ,1.0F-(gxcurrentmaterialshininess)/2.0F); GX_InitLightDistAttn(&gxlight[lightcounter], factor ,1.0, GX_DA_STEEP); //gxspotexponent[lightcounter] GX_DA_GENTLE GX_InitLightDistAttn(&gxlight[lightcounter+4], factor ,1.0, GX_DA_STEEP); //gxspotexponent[lightcounter] GX_DA_GENTLE //ref_dist //ref_brite // factor / strenght //1.0 is // glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 10.0f); ?? //Setup light type (normal/spotlight) //0-90 / 255-0 //cut_off, spot func //GX_InitLightSpot(&gxlight[lightcounter], 0.0f, GX_SP_OFF); //not this is not a spot light //GX_InitLightShininess(&gxlight[lightcounter], gxcurrentmaterialshininess); // /180? //float testspot = 90 - ((gxcurrentmaterialshininess * 90) / 128); //thanks ector 90 - (x * 90 / 255) //if (gxcurrentmaterialshininess == 0){ // testspot = 90; //} //zid 255-gxcurrentmaterialshininess/(255/90); //setup specular highlight //GX_InitLightSpot(&gxlight[lightcounter], testspot, GX_SP_COS); //not this is not a spot light (gxspotcutoff[lightcounter]) //setup normal spotlight GX_InitLightSpot(&gxlight[lightcounter], gxspotcutoff[lightcounter], GX_SP_RING1); //not this is not a spot light () GX_InitLightSpot(&gxlight[1], gxspotcutoff[lightcounter], GX_SP_RING1); //not this is not a spot light () if ( gxcurrentmaterialshininess != 0 ) { //if (gxspotcutoff[lightcounter] != 180) { GX_TestInitLightShininess(&gxlight[lightcounter+4], gxcurrentmaterialshininess); //} }; //Load the light up switch (lightcounter){ case 0: GX_LoadLightObj(&gxlight[lightcounter], GX_LIGHT0); GX_LoadLightObj(&gxlight[lightcounter+4], GX_LIGHT4); break; case 1: GX_LoadLightObj(&gxlight[lightcounter], GX_LIGHT1); GX_LoadLightObj(&gxlight[lightcounter+4], GX_LIGHT5); break; case 2: GX_LoadLightObj(&gxlight[lightcounter], GX_LIGHT2); GX_LoadLightObj(&gxlight[lightcounter+4], GX_LIGHT6); break; case 3: GX_LoadLightObj(&gxlight[lightcounter], GX_LIGHT3); GX_LoadLightObj(&gxlight[lightcounter+4], GX_LIGHT7); break; // case 4: GX_LoadLightObj(&gxlight[lightcounter], GX_LIGHT4); break; // case 5: GX_LoadLightObj(&gxlight[lightcounter], GX_LIGHT5); break; // case 6: GX_LoadLightObj(&gxlight[lightcounter], GX_LIGHT6); break; // case 7: GX_LoadLightObj(&gxlight[lightcounter], GX_LIGHT7); break; } //GX_LoadLightObj(&gxlight[lightcounter], GX_LIGHT0); //GX_LoadLightObj(&gxlight[1], GX_LIGHT1); } } //set the curtexture if tex2denabled if (tex2denabled){ GX_LoadTexObj(&gxtextures[curtexture], GX_TEXMAP0); //TODO: make GX_TEXMAP0 dynamic for multitexturing }; //now we can draw the gx way (experiment try render in reverse ivm normals pointing the wrong way) int countelements = _numelements*2; if (gxcullfaceanabled==true){ countelements = _numelements; } GX_Begin(_type, GX_VTXFMT0, countelements); //dependend on culling setting int i =0; //default //order dependend on glFrontFace(GL_CCW); //or GL_CW // for( i=0; i<_numelements; i++) //GX_TRIANGLESTRIP GL_TRIANGLE_STRIP //0 1 2 0 1 2 //1 3 2 2 1 3 //2 3 4 2 3 4 //better think of a clever swapping routine //maybe then no need to invert normal for trianglestrip anymore //also GX_TRIANLES need to be drawn in reverse? //but GX_QUAD does not //so GX = CW by default while opengl is CCW by default? //bushing say cannot i be possibel that opengl reorders vertexes //u32 reverse = 0; //int pos = 0; //int temp = 0; //GL_POLYGON: http://www.gamedev.net/reference/articles/article425.asp bool cw = true; bool ccw = true; if(gxcullfaceanabled==true){ cw = false; ccw = false; switch(gxwinding){ case GL_CW: cw = true; break; case GL_CCW: ccw = true; break; } } if (cw==true){ //CW for( i=_numelements-1; i>=0; i--) { UploadVertex(i); } } if (ccw==true){ //CCW for( i=0; i<_numelements; i++) { UploadVertex(i); } } GX_End(); //clean up just to be sure i =0; for( i=0; i<_numelements; i++) { _vertexelements[i].x = 0.0F; _vertexelements[i].y = 0.0F; _vertexelements[i].z = 0.0F; _normalelements[i].x = 0.0F; _normalelements[i].y = 0.0F; _normalelements[i].z = 0.0F; _colorelements[i].r = 0.0F; _colorelements[i].g = 0.0F; _colorelements[i].b = 0.0F; _colorelements[i].a = 0.0F; _texcoordelements[i].s = 0.0F; _texcoordelements[i].t = 0.0F; } _numelements =0; }
//--------------------------------------------------------------------------------- int main( int argc, char **argv ){ //--------------------------------------------------------------------------------- f32 yscale; u32 xfbHeight; Mtx view; Mtx44 perspective; Mtx model, modelview; float rtri = 0.0f , rquad = 0.0f; u32 fb = 0; // initial framebuffer index GXColor background = {0, 0, 0, 0xff}; // init the vi. VIDEO_Init(); WPAD_Init(); rmode = VIDEO_GetPreferredMode(NULL); // 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(); // setup the fifo and then init the flipper void *gp_fifo = NULL; 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)); 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_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); // setup the vertex attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGB8, 0); GX_SetNumChans(1); GX_SetNumTexGens(0); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); // setup our camera at the origin // looking down the -z axis with y up guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution f32 w = rmode->viWidth; f32 h = rmode->viHeight; guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); guVector Yaxis = {0,1,0}; guVector Xaxis = {1,0,0}; while(1) { WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) exit(0); // do this before drawing GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); guMtxIdentity(model); guMtxRotAxisDeg(model, &Yaxis, rtri); guMtxTransApply(model, model, -1.5f,0.0f,-6.0f); guMtxConcat(view,model,modelview); // load the modelview matrix into matrix memory GX_LoadPosMtxImm(modelview, GX_PNMTX0); GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 3); GX_Position3f32( 0.0f, 1.0f, 0.0f); // Top GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_End(); guMtxIdentity(model); guMtxRotAxisDeg(model, &Xaxis, rquad); guMtxTransApply(model, model, 1.5f,0.0f,-6.0f); guMtxConcat(view,model,modelview); // load the modelview matrix into matrix memory GX_LoadPosMtxImm(modelview, GX_PNMTX0); GX_Begin(GX_QUADS, GX_VTXFMT0, 4); // Draw A Quad GX_Position3f32(-1.0f, 1.0f, 0.0f); // Top Left GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue GX_Position3f32( 1.0f, 1.0f, 0.0f); // Top Right GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue GX_End(); // Done Drawing The Quad // do this stuff after drawing GX_DrawDone(); fb ^= 1; // flip framebuffer GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); rtri+=0.2f; // Increase The Rotation Variable For The Triangle ( NEW ) rquad-=0.15f; // Decrease The Rotation Variable For The Quad ( NEW ) } 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; }
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; }
void BoxCover::Draw() { u8 BoxAlpha = (int) (alpha+alphaDyn) & 0xFF; GX_LoadProjectionMtx(projection, GX_PERSPECTIVE); GX_ClearVtxDesc(); GX_InvVtxCache(); GX_SetVtxDesc(GX_VA_POS, GX_INDEX8); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8); //! don't draw inside of the box GX_SetCullMode(GX_CULL_FRONT); Mtx modelView; Mtx modelView2; Mtx modelView3; guVector cubeAxis = {0,0,1}; guVector cubeAxis2 = {0,1,0}; guVector cubeAxis3 = {1,0,0}; guMtxIdentity(modelView); guMtxRotAxisDeg(modelView3, &cubeAxis3, RotX-Animation2); guMtxRotAxisDeg(modelView2, &cubeAxis2, RotY+Animation2+xoffsetDyn/2.0f); guMtxRotAxisDeg(modelView, &cubeAxis, RotZ-Animation); guMtxConcat(modelView3, modelView2, modelView2); guMtxConcat(modelView2, modelView, modelView); if(Settings.widescreen) guMtxScaleApply(modelView, modelView, Settings.WSFactor, 1.0f, 1.0f); guMtxTransApply(modelView, modelView, PosX+xoffsetDyn/680.0f+movePosX, PosY+yoffsetDyn/680.0f+movePosY, PosZ); guMtxConcat(view,modelView,modelView); GX_LoadPosMtxImm(modelView, GX_PNMTX0); //! Border quads GX_LoadTexObj(&boxBorderTex, GX_TEXMAP0); GX_InvalidateTexAll(); GX_SetArray(GX_VA_POS, (void *) &g_boxMeshQ[0].pos, sizeof(g_boxMeshQ[0])); GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshQ[0].texCoord, sizeof(g_boxMeshQ[0])); GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxMeshQSize); for (u32 j = 0; j < g_boxMeshQSize; ++j) { GX_Position1x8(j); GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha); GX_TexCoord1x8(j); } GX_End(); //! Border triangles GX_SetArray(GX_VA_POS, (void *) &g_boxMeshT[0].pos, sizeof(g_boxMeshT[0])); GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshT[0].texCoord, sizeof(g_boxMeshT[0])); GX_Begin(GX_TRIANGLES, GX_VTXFMT0, g_boxMeshTSize); for (u32 j = 0; j < g_boxMeshTSize; ++j) { GX_Position1x8(j); GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha); GX_TexCoord1x8(j); } GX_End(); //! Back Cover (Might be flat) GX_LoadTexObj(flatCover ? &defaultBoxTex : &coverTex, GX_TEXMAP0); GX_InvalidateTexAll(); GX_SetArray(GX_VA_POS, (void *) &g_boxBackCoverMesh[0].pos, sizeof(g_boxBackCoverMesh[0])); GX_SetArray(GX_VA_TEX0, (void *) &g_boxBackCoverMesh[0].texCoord, sizeof(g_boxBackCoverMesh[0])); GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxBackCoverMeshSize); for (u32 j = 0; j < g_boxBackCoverMeshSize; ++j) { GX_Position1x8(j); if(flatCover) GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha); else GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha); GX_TexCoord1x8(j); } GX_End(); if(flatCover) { //! Front Flat Cover GX_LoadTexObj(&coverTex, GX_TEXMAP0); GX_InvalidateTexAll(); GX_SetArray(GX_VA_POS, (void *) &g_flatCoverMesh[0].pos, sizeof(g_flatCoverMesh[0])); GX_SetArray(GX_VA_TEX0, (void *) &g_flatCoverMesh[0].texCoord, sizeof(g_flatCoverMesh[0])); GX_Begin(GX_QUADS, GX_VTXFMT0, g_flatCoverMeshSize); for (u32 j = 0; j < g_flatCoverMeshSize; ++j) { GX_Position1x8(j); GX_Color4u8(0xff, 0xff, 0xff, 0xff); GX_TexCoord1x8(j); } GX_End(); } else { //! Front Cover GX_SetArray(GX_VA_POS, (void *) &g_boxCoverMesh[0].pos, sizeof(g_boxCoverMesh[0])); GX_SetArray(GX_VA_TEX0, (void *) &g_boxCoverMesh[0].texCoord, sizeof(g_boxCoverMesh[0])); GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxCoverMeshSize); for (u32 j = 0; j < g_boxCoverMeshSize; ++j) { GX_Position1x8(j); GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha); GX_TexCoord1x8(j); } GX_End(); } //! stop cull GX_SetCullMode(GX_CULL_NONE); UpdateEffects(); }
// 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; }
//--------------------------------------------------------------------------------- int main( int argc, char **argv ){ //--------------------------------------------------------------------------------- f32 yscale; u32 xfbHeight; Mtx view; Mtx44 perspective; u32 fb = 0; // initial framebuffer index GXColor background = {0, 0, 0, 0xff}; // init the vi. VIDEO_Init(); WPAD_Init(); rmode = VIDEO_GetPreferredMode(NULL); // 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(); // setup the fifo and then init the flipper void *gp_fifo = NULL; 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)); GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); // setup our camera at the origin // looking down the -z axis with y up guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution f32 w = rmode->viWidth; f32 h = rmode->viHeight; guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); while(1) { WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) exit(0); // do this before drawing GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); // do this stuff after drawing GX_DrawDone(); fb ^= 1; // flip framebuffer GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); } return 0; }
//--------------------------------------------------------------------------------- int main( int argc, char **argv ){ //--------------------------------------------------------------------------------- f32 yscale; u32 xfbHeight; // various matrices for things like view Mtx view,mv,mr; Mtx44 perspective; // the texure we're going to paint GXTexObj texture; TPLFile mudTPL; u32 fb = 0; // initial framebuffer index GXColor background = {0, 0, 0, 0xff}; // init the vi. VIDEO_Init(); rmode = VIDEO_GetPreferredMode(NULL); WPAD_Init(); // 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 and wait for the screen to blank VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); // setup the fifo... void *gp_fifo = NULL; gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gp_fifo,0,DEFAULT_FIFO_SIZE); // ...then init the flipper 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 attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_InvVtxCache(); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); // setup texture coordinate generation // args: texcoord slot 0-7, matrix type, source to generate texture coordinates from, matrix to use GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_TEX0, GX_IDENTITY); f32 w = rmode->viWidth; f32 h = rmode->viHeight; guLightPerspective(mv,45, (f32)w/h, 1.05F, 1.0F, 0.0F, 0.0F); guMtxTrans(mr, 0.0F, 0.0F, -1.0F); guMtxConcat(mv, mr, mv); GX_LoadTexMtxImm(mv, GX_TEXMTX0, GX_MTX3x4); GX_InvalidateTexAll(); TPL_OpenTPLFromMemory(&mudTPL, (void *)mud_tpl,mud_tpl_size); TPL_GetTexture(&mudTPL,mud,&texture); // setup our camera at the origin // looking down the -z axis with y up guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); // get the room ready to render SetupWorld(); while(1) { WPAD_ScanPads(); s8 tpad = PAD_StickX(0); // Rotate left or right. if ((tpad < -8) || (tpad > 8)) yrot -= (float)tpad / 50.f; // NOTE: walkbiasangle = head bob tpad = PAD_StickY(0); // Go forward. if(tpad > 50) { xpos -= (float)sin(DegToRad(yrot)) * 0.05f; // Move on the x-plane based on player direction zpos -= (float)cos(DegToRad(yrot)) * 0.05f; // Move on the z-plane based on player direction if (walkbiasangle >= 359.0f) walkbiasangle = 0.0f; // Bring walkbiasangle back around else walkbiasangle += 10; // if walkbiasangle < 359 increase it by 10 walkbias = (float)sin(DegToRad(walkbiasangle))/20.0f; } // Go backward if(tpad < -50) { xpos += (float)sin(DegToRad(yrot)) * 0.05f; zpos += (float)cos(DegToRad(yrot)) * 0.05f; if (walkbiasangle <= 1.0f) walkbiasangle = 359.0f; else walkbiasangle -= 10; walkbias = (float)sin(DegToRad(walkbiasangle))/20.0f; } tpad = PAD_SubStickY(0); // Tilt up/down if (((tpad > 8) || (tpad < -8)) && ((90 >= lookupdown) && (lookupdown >= -90))) { zdepth -= ((f32)tpad * 0.01f); lookupdown -= ((f32)tpad * 0.01f); if (lookupdown > 90) lookupdown = 90.0F; if (lookupdown < -90) lookupdown = -90.0F; } if ( PAD_ButtonsDown(0) & PAD_BUTTON_START) { exit(0); } // do this before drawing GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); //set number of textures to generate GX_SetNumTexGens(1); // Draw things DrawScene(view,texture); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); // do this stuff after drawing GX_DrawDone(); fb ^= 1; // flip framebuffer VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); } return 0; }
void reduce_cubemap (cubemap_info *cubemap, int subdiv) { int x, y, face; const u32 vtxfmt = GX_VTXFMT0; Mtx mvtmp; Mtx44 ortho; object_loc rect_loc; scene_info rect_scene; int half_subdiv = subdiv / 2; float scale_factor = 1.0 / ((float) half_subdiv - 0.5); /* Using an even number of subdivisions and spreading evenly from -1...1 ensures we don't try to evaluate the singularity point at the back of the sphere. */ assert ((subdiv & 1) == 0); scene_set_pos (&rect_scene, (guVector) { 0, 0, -5 }); scene_set_lookat (&rect_scene, (guVector) { 0, 0, 0 }); scene_set_up (&rect_scene, (guVector) { 0, 1, 0 }); scene_update_camera (&rect_scene); guOrtho (ortho, -1, 1, -1, 1, 1, 15); object_loc_initialise (&rect_loc, GX_PNMTX0); guMtxIdentity (mvtmp); object_set_matrices (&rect_scene, &rect_loc, rect_scene.camera, mvtmp, NULL, ortho, GX_ORTHOGRAPHIC); GX_ClearVtxDesc (); GX_SetVtxDesc (GX_VA_POS, GX_DIRECT); GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT); GX_SetVtxAttrFmt (vtxfmt, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt (vtxfmt, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetCullMode (GX_CULL_BACK); rendertarget_texture (cubemap->sphsize, cubemap->sphsize, cubemap->sphfmt, GX_FALSE, GX_PF_RGB8_Z24, GX_ZC_LINEAR); for (face = 0; face < 6; face++) { shader_load (cubemap->face_shader[face]); for (x = -half_subdiv; x < half_subdiv - 1; x++) { float a = ((float) x + 0.5) * scale_factor; float a1 = ((float) x + 1.5) * scale_factor; GX_Begin (GX_TRIANGLESTRIP, vtxfmt, subdiv * 2); for (y = -half_subdiv; y < half_subdiv; y++) { float b = ((float) y + 0.5) * scale_factor; guVector tmp; face_to_sphere (&tmp, face, a, b); GX_Position3f32 (tmp.x, tmp.y, tmp.z); GX_TexCoord2f32 ((a + 1.0) / 2.0, (b + 1.0) / 2.0); face_to_sphere (&tmp, face, a1, b); GX_Position3f32 (tmp.x, tmp.y, tmp.z); GX_TexCoord2f32 ((a1 + 1.0) / 2.0, (b + 1.0) / 2.0); } GX_End (); } } GX_CopyTex (cubemap->sphtexels, GX_TRUE); GX_PixModeSync (); }
int main(int argc,char **argv) { f32 yscale; u32 xfbHeight; u32 fb = 0; u32 first_frame = 1; GXTexObj texture; Mtx view; // view and perspective matrices Mtx44 perspective; void *gpfifo = NULL; GXColor background = {0x00, 0x00, 0x00, 0xFF}; guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; TPLFile cubeTPL; VIDEO_Init(); PAD_Init(); rmode = VIDEO_GetPreferredMode(NULL); // allocate the fifo buffer gpfifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gpfifo,0,DEFAULT_FIFO_SIZE); // allocate 2 framebuffers for double buffering frameBuffer[0] = SYS_AllocateFramebuffer(rmode); frameBuffer[1] = SYS_AllocateFramebuffer(rmode); // configure video VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); fb ^= 1; // init the flipper GX_Init(gpfifo,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 attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGB8, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); // set number of rasterized color channels GX_SetNumChans(1); //set number of textures to generate GX_SetNumTexGens(1); GX_InvVtxCache(); GX_InvalidateTexAll(); TPL_OpenTPLFromMemory(&cubeTPL, (void *)Cube_tpl,Cube_tpl_size); TPL_GetTexture(&cubeTPL,cube,&texture); // setup our camera at the origin // looking down the -z axis with y up guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution f32 w = rmode->viWidth; f32 h = rmode->viHeight; guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); if (BuildLists(texture)) { // Build the display lists exit(1); // Exit if failed. } while(1) { PAD_ScanPads(); if ( PAD_ButtonsDown(0) & PAD_BUTTON_START) { exit(0); } u16 directions = PAD_ButtonsHeld(0); if ( directions & PAD_BUTTON_LEFT ) yrot += 0.5f; if ( directions & PAD_BUTTON_RIGHT ) yrot -= 0.5f; if ( yrot > 360.f ) yrot -= 360.f; if ( yrot < 0 ) yrot += 360.f; if ( directions & PAD_BUTTON_UP ) xrot -= 0.5f; if ( directions & PAD_BUTTON_DOWN ) xrot += 0.5f; if ( xrot > 360.f ) xrot -= 360.f; if ( xrot < 0 ) xrot += 360.f; if(first_frame) { first_frame = 0; VIDEO_SetBlack(FALSE); } // draw things DrawScene(view); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_DrawDone(); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); fb ^= 1; } }
int main(int argc,char **argv) { f32 yscale,zt = 0; u32 xfbHeight; u32 fb = 0; f32 rquad = 0.0f; u32 first_frame = 1; GXTexObj texture; Mtx view; // view and perspective matrices Mtx model, modelview; Mtx44 perspective; void *gpfifo = NULL; GXColor background = {0, 0, 0, 0xff}; guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; TPLFile crateTPL; VIDEO_Init(); WPAD_Init(); rmode = VIDEO_GetPreferredMode(NULL); // allocate the fifo buffer gpfifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gpfifo,0,DEFAULT_FIFO_SIZE); // allocate 2 framebuffers for double buffering frameBuffer[0] = SYS_AllocateFramebuffer(rmode); frameBuffer[1] = SYS_AllocateFramebuffer(rmode); // configure video VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); fb ^= 1; // init the flipper GX_Init(gpfifo,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 attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. 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_VTXFMT0, GX_VA_POS, GX_POS_XYZ, 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_RGB8, 0); GX_InvVtxCache(); GX_InvalidateTexAll(); TPL_OpenTPLFromMemory(&crateTPL, (void *)crate_tpl,crate_tpl_size); TPL_GetTexture(&crateTPL,crate,&texture); // setup our camera at the origin // looking down the -z axis with y up guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution f32 w = rmode->viWidth; f32 h = rmode->viHeight; guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); guVector cubeAxis = {1,1,1}; while(1) { WPAD_ScanPads(); if(WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) exit(0); else if (WPAD_ButtonsHeld(0)&WPAD_BUTTON_UP) zt -= 0.25f; else if (WPAD_ButtonsHeld(0)&WPAD_BUTTON_DOWN) zt += 0.25f; // set number of rasterized color channels GX_SetNumChans(1); //set number of textures to generate GX_SetNumTexGens(1); // setup texture coordinate generation // args: texcoord slot 0-7, matrix type, source to generate texture coordinates from, matrix to use GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_SetTevOp(GX_TEVSTAGE0,GX_REPLACE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_LoadTexObj(&texture, GX_TEXMAP0); guMtxIdentity(model); guMtxRotAxisDeg(model, &cubeAxis, rquad); guMtxTransApply(model, model, 0.0f,0.0f,zt-7.0f); guMtxConcat(view,model,modelview); // load the modelview matrix into matrix memory GX_LoadPosMtxImm(modelview, GX_PNMTX3); GX_SetCurrentMtx(GX_PNMTX3); GX_Begin(GX_QUADS, GX_VTXFMT0, 24); // Draw a Cube GX_Position3f32(-1.0f, 1.0f, -1.0f); // Top Left of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(-1.0f, 1.0f, 1.0f); // Top Right of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(-1.0f, -1.0f, 1.0f); // Bottom Right of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32(- 1.0f, -1.0f, -1.0f); // Bottom Left of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( 1.0f,1.0f, -1.0f); // Top Left of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(1.0f,-1.0f, -1.0f); // Top Right of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(1.0f,-1.0f,1.0f); // Bottom Right of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( 1.0f,1.0f,1.0f); // Bottom Left of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( -1.0f, -1.0f, 1.0f); // Top Right Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(1.0f, -1.0f, 1.0f); // Top Left Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(1.0f,-1.0f, -1.0f); // Bottom Left Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( -1.0f,-1.0f, -1.0f); // Bottom Right Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( -1.0f,1.0f,1.0f); // Bottom Left Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(-1.0f,1.0f,-1.0f); // Bottom Right Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( 1.0f, 1.0f,1.0f); // Top Left Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32(1.0f, -1.0f, -1.0f); // Top Right Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(-1.0f,1.0f,-1.0f); // Bottom Left Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32(-1.0f,-1.0f, -1.0f); // Bottom Right Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( 1.0f, -1.0f,1.0f); // Top Right Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32( -1.0f, -1.0f, 1.0f); // Top Left Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32( -1.0f,1.0f, 1.0f); // Bottom Left Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( 1.0f,1.0f,1.0f); // Bottom Right Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(0.0f,1.0f); GX_End(); // Done Drawing The Quad GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_DrawDone(); VIDEO_SetNextFramebuffer(frameBuffer[fb]); if(first_frame) { first_frame = 0; VIDEO_SetBlack(FALSE); } VIDEO_Flush(); VIDEO_WaitVSync(); fb ^= 1; rquad -= 0.15f; // Decrease The Rotation Variable For The Quad ( NEW ) } }
/** * Taken from the devkitPPC template... */ void WiiEnvironment::setup() { // Mtx view; Mtx model, modelview; GXColor background = {0, 0, 0, 0xff}; // init the vi. VIDEO_Init(); WPAD_Init(); WPAD_SetDataFormat( WPAD_CHAN_0, WPAD_FMT_BTNS_ACC ); rmode = VIDEO_GetPreferredMode(NULL); // Attempt to initiate the fat filesystem... if ( !fatInitDefault() ) { // TODO: Logging somehow? exit( 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(); // setup the fifo and then init the flipper void *gp_fifo = NULL; 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)); 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_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); // setup the vertex attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGB8, 0); GX_SetNumChans(1); GX_SetNumTexGens(0); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); // setup our camera at the origin // looking down the -z axis with y up guVector cam = {0.0F, 0.0F, -100.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, 0.0F}; guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution f32 w = rmode->viWidth; f32 h = rmode->viHeight; guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); }