示例#1
0
void ScreenInit(void)
{
	// init the graphics engine
	GX_Init();

	// turn off the display engine output
	GX_DispOff();
	GXS_DispOff();

	// setup the display memory
	GX_SetBankForLCDC( GX_VRAM_LCDC_ALL );
	MI_CpuClearFast( (void*)HW_LCDC_VRAM , HW_LCDC_VRAM_SIZE );
	GX_DisableBankForLCDC();
	MI_CpuFillFast( (void*)HW_OAM,192 , HW_OAM_SIZE );
	MI_CpuClearFast( (void*)HW_PLTT , HW_PLTT_SIZE );
	MI_CpuFillFast( (void*)HW_DB_OAM , 192,HW_DB_OAM_SIZE );
	MI_CpuClearFast( (void*)HW_DB_PLTT , HW_DB_PLTT_SIZE );

	// clear the screens
	ClearScreens();

	// 2D display setup for displaying character string
	//g2
	GX_SetBankForBG( GX_VRAM_BG_128_A );
	G2_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256 ,
	                GX_BG_COLORMODE_16 ,
	                GX_BG_SCRBASE_0xf800 ,      // SCR base block 31
	                GX_BG_CHARBASE_0x00000 ,    // CHR base block 0
	                GX_BG_EXTPLTT_01 );
	G2_SetBG0Priority( 0 );
	G2_BG0Mosaic( FALSE );
	GX_SetGraphicsMode( GX_DISPMODE_GRAPHICS , GX_BGMODE_0,GX_BG0_AS_2D );
	GX_SetVisiblePlane( GX_PLANEMASK_BG0 );
	GX_LoadBG0Char( d_CharData , 0 , sizeof( d_CharData ) );
	GX_LoadBGPltt( d_PaletteData , 0 , sizeof( d_PaletteData ) );
	GX_LoadBG0Scr( gTopScreen , 0 , sizeof( gTopScreen ) );
	//g2s
	GX_SetBankForSubBG( GX_VRAM_SUB_BG_128_C );
	G2S_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256 ,
	                GX_BG_COLORMODE_16 ,
	                GX_BG_SCRBASE_0xf800 ,      // SCR base block 31
	                GX_BG_CHARBASE_0x00000 ,    // CHR base block 0
	                GX_BG_EXTPLTT_01 );
	G2S_SetBG0Priority( 0 );
	G2S_BG0Mosaic( FALSE );
	GXS_SetGraphicsMode( GX_BGMODE_0 );
	GXS_SetVisiblePlane( GX_PLANEMASK_BG0 );
	GXS_LoadBG0Char( d_CharData , 0 , sizeof( d_CharData ) );
	GXS_LoadBGPltt( d_PaletteData , 0 , sizeof( d_PaletteData ) );
	GXS_LoadBG0Scr( gBottomScreen , 0 , sizeof( gBottomScreen ) );

	// Interrupt setup
	OS_SetIrqFunction( OS_IE_V_BLANK , VBlankIntr );
	OS_EnableIrqMask( OS_IE_V_BLANK );
	GX_VBlankIntr( TRUE );

	// Start LCD display
	GX_DispOn();
	GXS_DispOn();
}
示例#2
0
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 :)
}
示例#3
0
文件: video.c 项目: MANICX100/wiimc
/****************************************************************************
 * 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);
}
示例#4
0
文件: main.c 项目: thejew/psxdev
int main(void)
{
	GX_Init(GX_HRES_320, GX_VRES_240);
	
	GX_SetClearColor(GX_GRAY);
	
	GX_GetResolution(&res_w, &res_h);
	
	texture = GX_LoadTIM(kid_tim);
	GX_GetTextureDims(texture, &tex_w, &tex_h);
	
	for (int i = 0; i < 32; ++i)
		sprites[i].occupied = 0;

	InitSprite(50, 50, 0, 0, -1, 1);
	InitSprite(60, 30, 0, 0, 1, 1);
	InitSprite(120, 20, 0, 0, -1, -1);
	InitSprite(100, 80, 0, 0, 1, -1);
	
	while (1)
	{
		GX_Clear();
		
		GX_SelectTexture(texture);
		
		for (int i = 0; i < 32; ++i)
		{
			sprite_t *spr = &sprites[i];
			if (spr->occupied)
			{
				UpdateSprite(&sprites[i]);
				GX_DrawRectangleTextured(
					spr->x,
					spr->y,
					spr->w,
					spr->h,
					spr->tx,
					spr->ty
					);
			}
		}
		
		GX_Sync();
    }
	
    return 0;
}
示例#5
0
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;
}
示例#6
0
文件: main.c 项目: KirovAir/swiss-gc
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
}
示例#7
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;
}
示例#8
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;
}
/**
 * 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);

}
示例#10
0
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;
	}
}
示例#11
0
文件: test_wii.c 项目: jackoalan/PSPL
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;

	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;
}
示例#13
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;
}
示例#14
0
文件: main.cpp 项目: notnotme/nwancat
// 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;
}
示例#15
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;
}
示例#16
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 )
    }
}
示例#17
0
void REV_init()
{
	//Local variables
	f32 yscale;
	u32 xfbHeight;
	//Load the right IOS, so keyboard works fin
	u32 iosVersion = IOS_GetVersion();
	if(iosVersion != 36)
	{
		IOS_ReloadIOS(36);
	}
	////
	VIDEO_Init();//Video Library Init
	PAD_Init();//Gamecube Pad Library Init
	WPAD_Init();//Wiimote Library Init
	rMode = VIDEO_GetPreferredMode(NULL);//Set render mode
	// allocate 2 framebuffers for double buffering
	frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rMode));
	frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rMode));
	//Configure Video System
	VIDEO_Configure(rMode);
	VIDEO_SetNextFramebuffer(frameBuffer[fb]);//Initial Framebuffer
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rMode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
	fb ^= 1;//Set next index
	//Set up the FIFO
	void *gp_fifo = memalign(32,DEFAULT_FIFO_SIZE);//Allocate
	memset(gp_fifo,0,DEFAULT_FIFO_SIZE);//and Clear
	//Init GX hardware
	GX_Init(gp_fifo,DEFAULT_FIFO_SIZE);
	// clears the bg to color and clears the z buffer
	GX_SetCopyClear(DEF_BG_COLOR , 0x00ffffff);
	//More initialization
	w = rMode->viWidth;
    h = rMode->viHeight;
	
	yscale = GX_GetYScaleFactor(rMode->efbHeight,rMode->xfbHeight);
	xfbHeight = GX_SetDispCopyYScale(yscale);
	GX_SetDispCopySrc(0,0,rMode->fbWidth,rMode->efbHeight);
	GX_SetDispCopyDst(rMode->fbWidth,xfbHeight);
	GX_SetFieldMode(rMode->field_rendering,((h==2*rMode->xfbHeight)?GX_ENABLE:GX_DISABLE));
	
	if (rMode->aa)
        GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR);
    else
        GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
	
	GX_CopyDisp(frameBuffer[fb],GX_TRUE);
	GX_SetDispCopyGamma(GX_GM_1_0);
	
	for(u8 i = 0; i < 4; i++)
	WPAD_SetVRes(i,w,h);
	
	//Hardware Initialized, now engine initialization
	//Init filesystem
	fatInitDefault();
	//First create a Root
	mainRoot = new ROOT;
	mainRoot->init((f32)w,(f32)h);
	GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
	GX_SetColorUpdate(GX_ENABLE);
	GX_SetAlphaUpdate(GX_ENABLE);
	GX_SetZCompLoc(GX_TRUE);
	GX_SetZMode (GX_TRUE, GX_LEQUAL, GX_TRUE);
	init3dConfig();
	init2dConfig();
	init2D(w, h);
	transQueue = NULL;
	solidQueue = NULL;
	zQueue = NULL;
	REV_fontsInit();
	KEYBOARD_Init(NULL);
	keyboardInit();
}