void DoClearFrontBuffer(void) // CLEAR DX BUFFER { if (menuActive) return; // clear the screen, and flush it DEBUG_print("DoClearFrontBuffer",DBG_GPU1); // printf("DoClearFrontBuffer\n"); //Write menu/debug text on screen GXColor fontColor = {150,255,150,255}; IplFont_drawInit(fontColor); if((ulKeybits&KEY_SHOWFPS)&&showFPSonScreen) IplFont_drawString(10,35,szDispBuf, 1.0, false); int i = 0; DEBUG_update(); for (i=0;i<DEBUG_TEXT_HEIGHT;i++) IplFont_drawString(10,(10*i+60),text[i], 0.5, false); //reset swap table from GUI/DEBUG GX_SetTevSwapModeTable(GX_TEV_SWAP0, GX_CH_RED, GX_CH_GREEN, GX_CH_BLUE, GX_CH_ALPHA); GX_SetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP0); GX_DrawDone(); whichfb ^= 1; GX_CopyDisp(xfb[0], GX_TRUE); GX_DrawDone(); VIDEO_SetNextFramebuffer(xfb[0]); VIDEO_Flush(); // VIDEO_WaitVSync(); }
// rulez nyan scene int main(int argc, char **argv) { bool nyaning = true; // self explain nyan(); MP3Player_PlayBuffer(nyannyannyan_mp3, nyannyannyan_mp3_size, NULL); VIDEO_SetBlack(FALSE); while(nyaning) { u64 cticks = ticks_to_millisecs(gettime()); // Loop the sound if ended if(!MP3Player_IsPlaying()) MP3Player_PlayBuffer(nyannyannyan_mp3, nyannyannyan_mp3_size, NULL); //Check wiimote input WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); if (pressed & WPAD_BUTTON_HOME) nyaning = false; // blackscreen until 3,8s like the youtube video (not extreme precison ;)) if(cticks < startTime+3900) continue; // bkg frame counter (tick each 100ms) if(cticks > bkgTimeCounter+100) { bkgTimeCounter = cticks; currentBkgStep = (currentBkgStep+1) % BKG_STEP; } // nyan frame counter (tick each 60ms) if(cticks > nyanTimeCounter+60) { nyanTimeCounter = cticks; currentNyanStep = (currentNyanStep+1) % NYAN_STEP; } // Set the 2d matrix guMtxIdentity(GXmodelView2D); GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0); // nyan f32 move = delta % BKG_SIZE; f32 x = -move; while(x < rmode->fbWidth) { drawBkgSprite(x, currentBkgStep); x += BKG_SIZE; } // nyan nyan drawNyan(-5, 240 - ((NYAN_HEIGHT*8)/2), currentNyanStep); // Copy & switch fb GX_DrawDone(); GX_CopyDisp(xfb[wichFb], GX_TRUE); VIDEO_SetNextFramebuffer(xfb[wichFb]); VIDEO_Flush(); VIDEO_WaitVSync(); wichFb ^= 1; delta += 8; } return 0; }
static void DrawChar(unsigned char c, int xpos, int ypos, int size, GXColor color) { /* reintialize texture object */ GXTexObj texobj; GX_InitTexObj(&texobj, fontTexture, fontHeader->cell_width, fontHeader->cell_height, GX_TF_I4, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_LoadTexObj(&texobj, GX_TEXMAP0); /* reinitialize font texture data */ memset(fontTexture,0,fontHeader->cell_width * fontHeader->cell_height / 2); GetFontTexel(c,fontTexture,0,fontHeader->cell_width/2); DCFlushRange(fontTexture, fontHeader->cell_width * fontHeader->cell_height / 2); GX_InvalidateTexAll(); /* adjust texture width */ s32 width = (fontHeader->cell_width * size) / fontHeader->cell_height; /* GX rendering */ GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position2s16(xpos, ypos - size); GX_Color4u8(color.r, color.g, color.b, 0xff); GX_TexCoord2f32(0.0, 0.0); GX_Position2s16(xpos + width, ypos - size); GX_Color4u8(color.r, color.g, color.b, 0xff); GX_TexCoord2f32(1.0, 0.0); GX_Position2s16(xpos + width, ypos); GX_Color4u8(color.r, color.g, color.b, 0xff); GX_TexCoord2f32(1.0, 1.0); GX_Position2s16(xpos, ypos); GX_Color4u8(color.r, color.g, color.b, 0xff); GX_TexCoord2f32(0.0, 1.0); GX_End (); GX_DrawDone(); }
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 }
void PEOPS_GX_Flush() { GX_CopyDisp (xfb[whichfb], GX_TRUE); GX_DrawDone(); VIDEO_SetNextFramebuffer(xfb[whichfb]); VIDEO_Flush(); whichfb ^= 1; }
/**************************************************************************** * Menu_Render * * Renders everything current sent to GX, and flushes video ***************************************************************************/ void Menu_Render() { whichfb ^= 1; // flip framebuffer GX_CopyDisp(xfb[whichfb], GX_TRUE); GX_DrawDone(); VIDEO_SetNextFramebuffer(xfb[whichfb]); VIDEO_Flush(); VIDEO_WaitVSync(); frameCount++; }
/**************************************************************************** * Menu_Render * * Renders everything current sent to GX, and flushes video ***************************************************************************/ void Menu_Render() { GX_DrawDone (); whichfb ^= 1; // flip framebuffer GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(xfb[whichfb],GX_TRUE); VIDEO_SetNextFramebuffer(xfb[whichfb]); VIDEO_Flush(); VIDEO_WaitVSync(); }
static void system_deinit(void *data) { (void)data; #ifndef IS_SALAMANDER // we never init GX/VIDEO subsystems in salamander GX_DrawDone(); GX_AbortFrame(); GX_Flush(); VIDEO_SetBlack(true); VIDEO_Flush(); VIDEO_WaitVSync(); #endif }
/** * Clears all loaded font glyph data. * * This routine clears all members of the font map structure and frees all allocated memory back to the system. */ void FreeTypeGX::unloadFont() { GX_DrawDone(); GX_Flush(); for( std::map<wchar_t, ftgxCharData>::iterator i = this->fontData.begin(); i != this->fontData.end(); i++) { free(i->second.glyphDataTexture); } if(this->ftFace) { FT_Done_Face(this->ftFace); } this->cacheTextWidth.clear(); this->fontData.clear(); }
void WiiEnvironment::endDraw() { // 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(); }
/** * Clears all loaded font glyph data. * * This routine clears all members of the font map structure and frees all allocated memory back to the system. */ void FreeTypeGX::clearGlyphData() { if (this->fontDatas.size() == 0) return; GX_DrawDone(); GX_Flush(); for ( std::map<uint16_t, FTGX_Cache>::iterator i = this->fontDatas.begin(); i != this->fontDatas.end(); i++) { for ( FTGX_Cache::iterator j = i->second.begin(); j != i->second.end(); j++) { free(j->second.glyphDataTexture); } i->second.clear(); } /* for ( std::map<wchar_t, ftgxCharData>::iterator i = this->fontData.begin(); i != this->fontData.end(); i++) { free(i->second.glyphDataTexture); } */ this->fontDatas.clear(); }
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; }
//--------------------------------------------------------------------------------- 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; }
//--------------------------------------------------------------------------------- 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 glFlush(void) { GX_DrawDone(); }
//--------------------------------------------------------------------------------- int main( int argc, char **argv ) {//--------------------------------------------------------------------------------- initialize(); // Initialise the console, required for printf console_init(frameBuffer[fb],20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); while(1) { frame_counter = countUpToSixty(frame_counter); WPAD_ScanPads(); int buttons = WPAD_ButtonsDown(0); if (buttons) { if (buttons & WPAD_BUTTON_HOME) exit(0); //changeColorBasedOnButtons(buttons); } prepairForSeriousDrawing(); //drawAGoofyWhiteTriangle(); //drawAGoofyWhiteRectangle(); // do this stuff after drawing GX_DrawDone(); switch(gameMode){ case 0: // show the title screen menu showTheTitleScreen(); gameMode = 1; break; case 1: // play that basic color game... free play mode changeColorBasedOnJoystick(); break; case 2: // play the "GO TO THE COLOR SPOKEN" game break; case 3: // Play the number game break; default: printf("unknown game mode!!!"); break; } 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[]) { // Setup video VIDEO_Init(); GXRModeObj* pref_vid_mode = VIDEO_GetPreferredMode(NULL); #if USING_AA pref_vid_mode = &TVNtsc480ProgAa; u32 half_height = pref_vid_mode->xfbHeight / 2; u32 bottom_offset = VIDEO_PadFramebufferWidth(pref_vid_mode->fbWidth) * (pref_vid_mode->efbHeight-3) * VI_DISPLAY_PIX_SZ; #endif VIDEO_Configure(pref_vid_mode); xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(pref_vid_mode)); xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(pref_vid_mode)); fbi = 0; VIDEO_SetNextFramebuffer(xfb[0]); // Console console_init(xfb[0],20,20,pref_vid_mode->fbWidth,pref_vid_mode->xfbHeight,pref_vid_mode->fbWidth*VI_DISPLAY_PIX_SZ); // Make display visible VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(pref_vid_mode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); printf("Console active\n"); // Setup GX 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); GXColor background = {0x0,0x0,0x0,0xff}; GX_SetCopyClear(background, 0x00ffffff); f32 yscale; u32 xfbHeight; yscale = GX_GetYScaleFactor(pref_vid_mode->efbHeight,pref_vid_mode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,pref_vid_mode->fbWidth,pref_vid_mode->efbHeight); GX_SetDispCopySrc(0,0,pref_vid_mode->fbWidth,pref_vid_mode->efbHeight); GX_SetDispCopyDst(pref_vid_mode->fbWidth,xfbHeight); GX_SetCopyFilter(pref_vid_mode->aa,pref_vid_mode->sample_pattern,GX_TRUE,pref_vid_mode->vfilter); GX_SetFieldMode(pref_vid_mode->field_rendering,((pref_vid_mode->viHeight==2*pref_vid_mode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (pref_vid_mode->aa) { GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); GX_SetDispCopyYScale(1); GX_SetDither(GX_ENABLE); } else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetDispCopyGamma(GX_GM_1_0); // Setup PSPL const pspl_platform_t* plat; pspl_runtime_init(&plat); const pspl_runtime_package_t* package = NULL; printf("PACKAGE OFF: %p SIZE: %u\n", (void*)&monkey_psplp, monkey_psplp_size); pspl_runtime_load_package_membuf((void*)&monkey_psplp, monkey_psplp_size, &package); pspl_runtime_enumerate_psplcs(package, enumerate_psplc_hook); printf("PSPL package read\n"); // Setup monkey rendering context monkey_ctx = pmdl_new_draw_context(); monkey_ctx->texcoord_mtx[1].m[0][0] = 0.5; monkey_ctx->texcoord_mtx[1].m[1][1] = -0.5; monkey_ctx->texcoord_mtx[1].m[0][3] = 0.5; monkey_ctx->texcoord_mtx[1].m[1][3] = 0.5; monkey_ctx->camera_view.pos.f[0] = 0; monkey_ctx->camera_view.pos.f[1] = 3; monkey_ctx->camera_view.pos.f[2] = 0; monkey_ctx->camera_view.look.f[0] = 0; monkey_ctx->camera_view.look.f[1] = 0; monkey_ctx->camera_view.look.f[2] = 0; monkey_ctx->camera_view.up.f[0] = 0; monkey_ctx->camera_view.up.f[1] = 0; monkey_ctx->camera_view.up.f[2] = 1; monkey_ctx->projection_type = PMDL_PERSPECTIVE; monkey_ctx->projection.perspective.fov = 55; monkey_ctx->projection.perspective.far = 5; monkey_ctx->projection.perspective.near = 1; monkey_ctx->projection.perspective.aspect = 1.777; monkey_ctx->projection.perspective.post_translate_x = 0; monkey_ctx->projection.perspective.post_translate_y = 0; pmdl_update_context(monkey_ctx, PMDL_INVALIDATE_ALL); // Load monkey const pspl_runtime_psplc_t* monkey_obj = pspl_runtime_get_psplc_from_key(package, "Monkey", 1); monkey_ctx->default_shader = monkey_obj; monkey_model = pmdl_lookup(monkey_obj, "monkey"); printf("Monkey loaded\n"); // Setup animation context haha_action_ctx = pmdl_action_init(pmdl_action_lookup(monkey_model, "haha")); haha_action_ctx->loop_flag = 1; rotate_action_ctx = pmdl_action_init(pmdl_action_lookup(monkey_model, "rotate")); rotate_action_ctx->loop_flag = 1; anim_ctx = pmdl_animation_initv(rotate_action_ctx, haha_action_ctx, NULL); printf("Animation Context Setup\n"); //init_time_profile(&profile); // Loop until reset button pressed SYS_SetResetCallback(reset_press_cb); double tex_off = 0; while (!reset_pressed) { //start_time_profile(&profile); // Update action contexts pmdl_action_advance(rotate_action_ctx, 0.1/60.0); pmdl_action_advance(haha_action_ctx, 1/60.0); pmdl_animation_evaluate(anim_ctx); tex_off += 0.005; //stop_time_profile(&profile); //report_time_profile(&profile); #if USING_AA GX_SetViewport(0, 0, pref_vid_mode->fbWidth, pref_vid_mode->xfbHeight, 0, 1); GX_SetScissor(0, 0, pref_vid_mode->fbWidth, half_height); GX_SetScissorBoxOffset(0, 0); #endif // Render top renderfunc(); // Copy to XFB GX_CopyDisp(xfb[fbi], GX_TRUE); #if USING_AA GX_SetViewport(0, 1, pref_vid_mode->fbWidth, pref_vid_mode->xfbHeight, 0, 1); GX_SetScissor(0, half_height, pref_vid_mode->fbWidth, half_height); GX_SetScissorBoxOffset(0, half_height); // Render bottom renderfunc(); // Copy to XFB GX_CopyDisp(xfb[fbi] + bottom_offset, GX_TRUE); #endif GX_DrawDone(); // Swap buffers VIDEO_SetNextFramebuffer(xfb[fbi]); fbi ^= 1; VIDEO_Flush(); ++cur_frame; 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; }
//--------------------------------------------------------------------------------- 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,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 ) } }
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; } }