Exemplo n.º 1
0
void glDisable(GLenum type){
		switch(type)
		{
			case GL_DEPTH_TEST: depthtestenabled = GX_FALSE; break;
			case GL_LIGHTING:
				GX_SetNumChans(1); //keep this at one all time?
				GX_SetNumTevStages(1);
				if (tex2denabled){
				  GX_SetNumTexGens(1); //multitexturing so set to 1 for now
				  GX_SetTevOp(GX_TEVSTAGE0,GX_REPLACE);
				  GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);                
                }
                else
                {
				 GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
				 GX_SetChanCtrl(GX_COLOR0A0,GX_DISABLE,GX_SRC_REG,GX_SRC_VTX,GX_LIGHTNULL,GX_DF_NONE,GX_AF_NONE);
                }
				break;
			case GL_TEXTURE_2D:
				tex2denabled = false;
				GX_SetNumTexGens(0); //texturing is of so no textures
				GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);			
				GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
				break;
			case GL_LIGHT0: gxlightenabled[0]=false; break;
			case GL_LIGHT1: gxlightenabled[1]=false; break;
			case GL_LIGHT2: gxlightenabled[2]=false; break;
			case GL_LIGHT3: gxlightenabled[3]=false; break;
			case GL_LIGHT4: gxlightenabled[4]=false; break;
			case GL_LIGHT5: gxlightenabled[5]=false; break;
			case GL_LIGHT6: gxlightenabled[6]=false; break;
			case GL_LIGHT7: gxlightenabled[7]=false; break;
			case GL_CULL_FACE: gxcullfaceanabled=false; break;
		};
}
Exemplo n.º 2
0
/****************************************************************************
 * Restore GX to 2D mode drawing
 ***************************************************************************/
void ReSetup_GX(void)
{
	// channel control
	GX_SetNumChans(1);
	GX_SetChanCtrl(GX_COLOR0A0,GX_DISABLE,GX_SRC_REG,GX_SRC_VTX,GX_LIGHTNULL,GX_DF_NONE,GX_AF_NONE);

	// texture gen.
	GX_SetNumTexGens(1);
	GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
	// texture environment
	GX_SetNumTevStages(1);
	GX_SetNumIndStages(0);
	GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
	GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
	GX_SetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP0);
	GX_SetTevKColorSel(GX_TEVSTAGE0, GX_TEV_KCSEL_1_4);
	GX_SetTevKAlphaSel(GX_TEVSTAGE0, GX_TEV_KASEL_1);
	GX_SetTevDirect(GX_TEVSTAGE0);
	// swap table
	GX_SetTevSwapModeTable(GX_TEV_SWAP0, GX_CH_RED, GX_CH_GREEN, GX_CH_BLUE, GX_CH_ALPHA);
	GX_SetTevSwapModeTable(GX_TEV_SWAP1, GX_CH_RED, GX_CH_RED, GX_CH_RED, GX_CH_ALPHA);
	GX_SetTevSwapModeTable(GX_TEV_SWAP2, GX_CH_GREEN, GX_CH_GREEN, GX_CH_GREEN, GX_CH_ALPHA);
	GX_SetTevSwapModeTable(GX_TEV_SWAP3, GX_CH_BLUE, GX_CH_BLUE, GX_CH_BLUE, GX_CH_ALPHA);
	// alpha compare and blend mode
	GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
	GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET);
}
Exemplo n.º 3
0
void drawInit()
{
	Mtx44 GXprojection2D;
	Mtx GXmodelView2D;

	// Reset various parameters from gfx plugin
	GX_SetCoPlanar(GX_DISABLE);
	GX_SetClipMode(GX_CLIP_ENABLE);
//	GX_SetScissor(0,0,vmode->fbWidth,vmode->efbHeight);
	GX_SetAlphaCompare(GX_ALWAYS,0,GX_AOP_AND,GX_ALWAYS,0);

	guMtxIdentity(GXmodelView2D);
	GX_LoadTexMtxImm(GXmodelView2D,GX_TEXMTX0,GX_MTX2x4);
	GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0);
	guOrtho(GXprojection2D, 0, 479, 0, 639, 0, 700);
	GX_LoadProjectionMtx(GXprojection2D, GX_ORTHOGRAPHIC);
//	GX_SetViewport (0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1);

	GX_SetZMode(GX_DISABLE,GX_ALWAYS,GX_TRUE);

	GX_ClearVtxDesc();
	GX_SetVtxDesc(GX_VA_PTNMTXIDX, GX_PNMTX0);
	GX_SetVtxDesc(GX_VA_TEX0MTXIDX, GX_TEXMTX0);
	GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
	//set vertex attribute formats here
	GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
	GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
	GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
	GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);

	//enable textures
	GX_SetNumChans (1);
	GX_SetNumTexGens (1);
	GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);

	GX_SetNumTevStages (1);
	GX_SetTevOrder (GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
	GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);

	//set blend mode
	GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); //Fix src alpha
	GX_SetColorUpdate(GX_ENABLE);
//	GX_SetAlphaUpdate(GX_ENABLE);
//	GX_SetDstAlpha(GX_DISABLE, 0xFF);
	//set cull mode
	GX_SetCullMode (GX_CULL_NONE);
}
Exemplo n.º 4
0
static void init_vtx(GXRModeObj *mode)
{
   GX_SetViewport(0, 0, mode->fbWidth, mode->efbHeight, 0, 1);
   GX_SetDispCopyYScale(GX_GetYScaleFactor(mode->efbHeight, mode->xfbHeight));
   GX_SetScissor(0, 0, mode->fbWidth, mode->efbHeight);
   GX_SetDispCopySrc(0, 0, mode->fbWidth, mode->efbHeight);
   GX_SetDispCopyDst(mode->fbWidth, mode->xfbHeight);
   GX_SetCopyFilter(mode->aa, mode->sample_pattern, (mode->xfbMode == VI_XFBMODE_SF) ? GX_FALSE : GX_TRUE,
         mode->vfilter);
   GX_SetCopyClear((GXColor) { 0, 0, 0, 0xff }, GX_MAX_Z24);
   GX_SetFieldMode(mode->field_rendering, (mode->viHeight == 2 * mode->xfbHeight) ? GX_ENABLE : GX_DISABLE);

   GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
   GX_SetZMode(GX_ENABLE, GX_ALWAYS, GX_ENABLE);
   GX_SetColorUpdate(GX_TRUE);
   GX_SetAlphaUpdate(GX_FALSE);

   Mtx44 m;
   guOrtho(m, 1, -1, -1, 1, 0.4, 0.6);
   GX_LoadProjectionMtx(m, GX_ORTHOGRAPHIC);

   GX_ClearVtxDesc();
   GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
   GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);

   GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
   GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
   GX_SetArray(GX_VA_POS, verts, 3 * sizeof(float));
   GX_SetArray(GX_VA_TEX0, tex_coords, 2 * sizeof(float));

   GX_SetNumTexGens(1);
   GX_SetNumChans(0);
   GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
   GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLORNULL);
   GX_InvVtxCache();

   GX_Flush();
}
Exemplo n.º 5
0
void glEnable(GLenum type){

	u8 gxlightmask = 0x00000000;
	u8 gxlightmaskspec = 0x00000000;
	int lightcounter = 0;
	int countlights =0;

		switch(type)
		{
			case GL_DEPTH_TEST: depthtestenabled = GX_TRUE; break;
			case GL_LIGHTING:

				//getting opengl lights to work on gx
				//
				//xg has only one light color (a diffuse one)
				//opengl lights have the following colors: diffuse, ambient and specular
				//also opengl has a global ambient color independend of a individual light
				//gx has 2 material colors: diffuse (mat) and ambient (can also be considered part of light?) 
				//opengl material have the followning colors: diffuse, ambient, specular and emission
				//so we (may) have problem (or call it a challenge)

				//now how does opengl calculate light with all these colors
				//vertex color	= material emission 
				//				+ global ambient scaled by material ambient
				//				+ ambient, diffuse, specular contributions from light(s), properly attinuated
				//
				//let us take these apart.
				//
				//material emission is like a constant color. So we can just add this in a tev stage. The only problem is how to add a color to a specific stage?)
				//
				//global ambient scaled by material ambient
				//this is global ambient * material ambient so we can feed that result to an tev stage.
				//
				//Now comes the hard part as each color is used in the light calulation. And we only have once color in gx.
				//Maybe we are lucky as each colors term is added to each other and only then used in light calculation
				//So we might get away with just adding the 3 colors upfront and feed that as color to the light source
				//But first let see how these terms are calculated.
				//
				//Ambient Term = light ambient * material ambient					= GXChanAmbColor ?							
				//Diffuse Term = surface * (light diffuse * material diffuse)		light diffues = light color	| material diffuse = GXChanMatColor	(let gx handle this)	
				//Specular Term = normal.shininess * (light specular * material specular)	(let gx handle this, but add lspec*mspec to GXChanMatColor)
				//
				//now we could use 3 light to emulate 1 opengl light but that would not be helpfull
				//so maybe there is an other way also gx material misses color components
				//
				//gx has max to channels
				//each can be setup differently so we can have on chanel for normal diffuse
				//and the other for specular. But we only have on light color so unless the specular color equals light color this it not usefull)
				//maybe some experiments with GXChanMatColor help with that? So light color to none and all color CHANMatColor?
				//
				//also we have multiple tev stages.
				//as we have used 2 channels we have to use 3 stages
				//stage 1 = emissive + global ambient scaled by material as constant color (maybe 2 stages?)
				//stage 2 = ambient + diffuse
				//stage 3 = specular
				//
				//So this might do the trick in theory. Now on to practice...

				//<h0lyRS> did you try setting specular to channel GX_COLOR1A1, and diffuse to GX_COLOR0A0, so you can blend them anyway you want?
				//this could add an extra color?
				//one way is adding the specular light, other way is multiplying


				//Setup lightmask with enabled lights (thanks h0lyRS)
				for (lightcounter =0; lightcounter < 4; lightcounter++){
					if(gxlightenabled[lightcounter]){ //when light is enabled
						gxlightmask |= (GX_LIGHT0 << lightcounter);
						gxlightmaskspec |= (GX_LIGHT0 << (lightcounter+4) );
						//countlights++;
					}
				};

//                gxlightmask |= (GX_LIGHT0 << 0);
//                gxlightmaskspec |= (GX_LIGHT0 << 1);


                //Setup light system/channels
				GX_SetNumChans(2); //dependend on if there is a specular color/effect needed

				//channel 1 (ambient + diffuse)                          
				GX_SetChanCtrl(GX_COLOR0A0,GX_TRUE,GX_SRC_REG,GX_SRC_REG,gxlightmask,GX_DF_CLAMP,GX_AF_SPOT);
				
				//channel 2 (specular)
				GX_SetChanCtrl(GX_COLOR1A1,GX_ENABLE,GX_SRC_REG,GX_SRC_REG,gxlightmaskspec,GX_DF_CLAMP,GX_AF_SPEC);
				
				
				//Setup TEV-shader
				
				//Setup the number of tev stages needed
				int numtevstages = 0;
				if (tex2denabled){ 
                  numtevstages = 5;
                } else {
                  numtevstages = 4;
                }
				GX_SetNumTevStages(numtevstages); //each extra color takes another stage?
				
				
				//stage 1 (global ambient light)
				
				//color
				GX_SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0); //shagkur method
				GX_SetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//alpha
				GX_SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_A0); //shagkur method
				GX_SetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//tevorder
				GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); //only use color

				//end stage 1


				//stage 2 (global ambient light)
				
				//color
				GX_SetTevColorIn(GX_TEVSTAGE1, GX_CC_CPREV, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C1); //shagkur method
				GX_SetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//alpha
				GX_SetTevAlphaIn(GX_TEVSTAGE1, GX_CA_APREV, GX_CA_ZERO, GX_CA_ZERO, GX_CA_A1); //shagkur method
				GX_SetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//tevorder
				GX_SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); //only use color

				//end stage 2
				
				
				//stage 3 (ambient and diffuse light from material and lights)

				//color
				GX_SetTevColorIn(GX_TEVSTAGE2, GX_CC_CPREV, GX_CC_ZERO, GX_CC_ZERO, GX_CC_RASC);
				GX_SetTevColorOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//alpha
				GX_SetTevAlphaIn(GX_TEVSTAGE2, GX_CA_APREV, GX_CA_ZERO, GX_CA_ZERO, GX_CC_RASA); 
				GX_SetTevAlphaOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//tevorder
				GX_SetTevOrder(GX_TEVSTAGE2, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); //only use color
				
				// end stage 3
				
				//stage 4 (specular light)
				

		// color - blend
		


		GX_SetTevColorOp(GX_TEVSTAGE3, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
		//GX_SetTevColorIn(GX_TEVSTAGE3, GX_CC_CPREV, GX_CC_ZERO, GX_CC_ZERO, GX_CC_RASC);
       // GX_SetTevColorIn(GX_TEVSTAGE3,GX_CC_ZERO,GX_CC_RASC,GX_CC_CPREV,GX_CC_ZERO);
GX_SetTevColorIn(GX_TEVSTAGE3,GX_CC_ZERO,GX_CC_RASC,GX_CC_ONE,GX_CC_CPREV);

		
		// alpha - nop
		GX_SetTevAlphaOp(GX_TEVSTAGE3, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
		//GX_SetTevAlphaIn(GX_TEVSTAGE3, GX_CA_APREV, GX_CA_ZERO, GX_CA_ZERO, GX_CA_RASA); //shagkur method
        GX_SetTevAlphaIn(GX_TEVSTAGE3,GX_CA_ZERO,GX_CA_RASA,GX_CA_APREV,GX_CA_ZERO);

		GX_SetTevOrder(GX_TEVSTAGE3, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR1A1);
		
			
				// end stage 4
				
				if (tex2denabled){ 
                                   
                    // stage 5 (textures)
				
				    GX_SetTevOrder(GX_TEVSTAGE4, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); //use texture
				    GX_SetTevOp(GX_TEVSTAGE4, GX_MODULATE); //blend with previous stage

                    // end stage 5

                }   

				break;
			case GL_TEXTURE_2D:
				tex2denabled = true;
				GX_SetNumTexGens(1); //multitexturing so set to 1 for now
				GX_SetTevOp(GX_TEVSTAGE0,GX_REPLACE);
				GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
				break;
			case GL_LIGHT0: gxlightenabled[0]=true; break;
			case GL_LIGHT1: gxlightenabled[1]=true; break;
			case GL_LIGHT2: gxlightenabled[2]=true; break;
			case GL_LIGHT3: gxlightenabled[3]=true; break;
			case GL_LIGHT4: gxlightenabled[4]=true; break;
			case GL_LIGHT5: gxlightenabled[5]=true; break;
			case GL_LIGHT6: gxlightenabled[6]=true; break;
			case GL_LIGHT7: gxlightenabled[7]=true; break;
			case GL_CULL_FACE: gxcullfaceanabled=true; break;
		};
}
Exemplo n.º 6
0
void Textbox::SetupGX(const BannerResources& resources) const
{
	GX_ClearVtxDesc();
	GX_InvVtxCache();

	GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);

	// channel control
	GX_SetNumChans(1);
	GX_SetChanCtrl(GX_COLOR0A0,GX_DISABLE,GX_SRC_REG,GX_SRC_VTX,GX_LIGHTNULL,GX_DF_NONE,GX_AF_NONE);

	// texture gen.
	GX_SetNumTexGens(1);
	GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
	// texture environment
	GX_SetNumTevStages(1);
	GX_SetNumIndStages(0);
	GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
	GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
	GX_SetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP0);
	GX_SetTevKColorSel(GX_TEVSTAGE0, GX_TEV_KCSEL_1_4);
	GX_SetTevKAlphaSel(GX_TEVSTAGE0, GX_TEV_KASEL_1);
	GX_SetTevDirect(GX_TEVSTAGE0);
	// swap table
	GX_SetTevSwapModeTable(GX_TEV_SWAP0, GX_CH_RED, GX_CH_GREEN, GX_CH_BLUE, GX_CH_ALPHA);
	GX_SetTevSwapModeTable(GX_TEV_SWAP1, GX_CH_RED, GX_CH_RED, GX_CH_RED, GX_CH_ALPHA);
	GX_SetTevSwapModeTable(GX_TEV_SWAP2, GX_CH_GREEN, GX_CH_GREEN, GX_CH_GREEN, GX_CH_ALPHA);
	GX_SetTevSwapModeTable(GX_TEV_SWAP3, GX_CH_BLUE, GX_CH_BLUE, GX_CH_BLUE, GX_CH_ALPHA);
	// alpha compare and blend mode
	GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
	GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET);

	if(header->material_index < resources.materials.size())
	{
		const Material::Header *matHead = resources.materials[header->material_index]->GetHeader();
		if(!matHead)
			return;

		//GX_SetFog(0, 0.0f, 0.0f, 0.0f, 0.0f, (GXColor){0xff, 0xff, 0xff, 0xff});
		GX_SetTevSwapModeTable(0, 0, 1, 2, 3);
		//GX_SetZTexture(0, 0x11, 0);
		GX_SetNumChans(1 );
		GX_SetChanCtrl(4, 0, 0, 1, 0, 0, 2);
		GX_SetChanCtrl(5, 0, 0, 0, 0, 0, 2);
		GX_SetNumTexGens(1);
		GX_SetTexCoordGen2(0, 1, 4, 0x3c, 0, 0x7D);
		GX_SetNumIndStages(0);
		GX_SetBlendMode(1, 4, 5, 0xf);
		GX_SetNumTevStages(2);
		GX_SetTevDirect(0);
		GX_SetTevDirect(1);
		GX_SetTevSwapMode(0, 0, 0);
		GX_SetTevSwapMode(1, 0, 0);
		GX_SetTevOrder(0, 0, 0, 0xff);

		for( int i = 0; i < 2; i++ )
		{
			// Devkitppc_r27 internal compiler error
			//GX_SetTevColor(i + 1, (GXColor){ LIMIT(matHead->color_regs[i].r, 0, 0xFF),
			//								 LIMIT(matHead->color_regs[i].g, 0, 0xFF),
			//								 LIMIT(matHead->color_regs[i].b, 0, 0xFF),
			//								 LIMIT(matHead->color_regs[i].a, 0, 0xFF) });
											 
			u8 r = (u8) LIMIT(matHead->color_regs[i].r, 0, 0xFF);
			u8 g = (u8) LIMIT(matHead->color_regs[i].g, 0, 0xFF);
			u8 b = (u8) LIMIT(matHead->color_regs[i].b, 0, 0xFF);
			u8 a = (u8) LIMIT(matHead->color_regs[i].a, 0, 0xFF);
			GX_SetTevColor((u8) (i + 1), (GXColor){r,g,b,a});
		}

		GX_SetTevColorIn(0, 2, 4, 8, 0xf);
		GX_SetTevAlphaIn(0, 1, 2, 4, 7);
		GX_SetTevColorOp(0, 0, 0, 0, 1, 0);
		GX_SetTevAlphaOp(0, 0, 0, 0, 1, 0);
		GX_SetTevOrder(1, 0xff, 0xff, 4);
		GX_SetTevColorIn(1, 0xf, 0, 0xa, 0xf);
		GX_SetTevAlphaIn(1, 7, 0,  5, 7);
		GX_SetTevColorOp(1, 0, 0, 0, 1, 0);
		GX_SetTevAlphaOp(1, 0, 0, 0, 1, 0);
	}
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
0
void DrawOBB(Mtx M_view, OBB& box, u32 color, bool drawAxes) {
	//for (int i = 0; i < 3; i++)
		//SYS_LOG(L"u%i={%.3f, %.3f, %.3f}", i, box.u[i].x, box.u[i].y, box.u[i].z);
	//SYS_LOG(L"color=%x", color);
	GX_ClearVtxDesc();

	GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
    GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);

    GX_SetVtxAttrFmt(GX_VTXFMT5, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
    GX_SetVtxAttrFmt(GX_VTXFMT5, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);

	// build and load model-view matrix
	Mtx M_modelView;
	guMtxIdentity(M_modelView);
	
	// rotation
	M_modelView[0][0] = box.u[0].x;		M_modelView[0][1] = box.u[0].y;		M_modelView[0][2] = box.u[0].z;
	M_modelView[1][0] = box.u[1].x;		M_modelView[1][1] = box.u[1].y;		M_modelView[1][2] = box.u[1].z;
	M_modelView[2][0] = box.u[2].x;		M_modelView[2][1] = box.u[2].y;		M_modelView[2][2] = box.u[2].z;
	
	// translation
	M_modelView[0][3] = box.c.x;		M_modelView[1][3] = box.c.y;		M_modelView[2][3] = box.c.z;

	guMtxConcat(M_view, M_modelView, M_modelView);
	GX_LoadPosMtxImm(M_modelView, GX_PNMTX0);

	GX_SetNumChans(1); // default, color = vertex color
	//GX_SetNumTexGens(0);

    GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
    GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);

	u8 indices[8] = {0, 1, 0, 2, 1, 3, 2, 3};
	f32* e = box.e;

	guVector v_bottom[4];
	v_bottom[0] = _vec(-e[0], -e[1], +e[2]);
	v_bottom[1] = _vec(+e[0], -e[1], +e[2]);
	v_bottom[2] = _vec(-e[0], -e[1], -e[2]);
	v_bottom[3] = _vec(+e[0], -e[1], -e[2]);

	guVector v_top[4];
	for (int i = 0; i < 4; i++)
		v_top[i] = _vec(v_bottom[i].x, e[1], v_bottom[i].z);

	GX_Begin(GX_LINES, GX_VTXFMT5, 24);
		// draw bottom
		for (u8 i = 0; i < 8; i += 2) {
			guVector& v0 = v_bottom[indices[i]];
			guVector& v1 = v_bottom[indices[i+1]];

			SendVertex(v0, color);
			SendVertex(v1, color);
		}

		// draw top
		for (u8 i = 0; i < 8; i += 2) {
			guVector& v0 = v_top[indices[i]];
			guVector& v1 = v_top[indices[i+1]];

			SendVertex(v0, color);
			SendVertex(v1, color);
		}

		// connect bottom vertices with the top ones
		for (u8 i = 0; i < 4; i++) {
			guVector& v0 = v_bottom[i];
			guVector& v1 = v_top[i];

			SendVertex(v0, color);
			SendVertex(v1, color);
		}
	GX_End();

	if (!drawAxes)
		return;

	// axes
	const f32 len = 150;
	GX_Begin(GX_LINES, GX_VTXFMT5, 6);
		guVector zero	= {0, 0, 0};
		guVector x_unit = {len, 0, 0};
		guVector y_unit = {0, len, 0};
		guVector z_unit = {0, 0, len};

		color = 0xFF0000FF;
		SendVertex(zero, color);
		SendVertex(x_unit, color);

		color = 0x00FF00FF;
		SendVertex(zero, color);
		SendVertex(y_unit, color);

		color = 0x0000FFFF;
		SendVertex(zero, color);
		SendVertex(z_unit, color);
	GX_End();
}
Exemplo n.º 9
0
/****************************************************************************
 * ResetVideo_Menu
 *
 * Reset the video/rendering mode for the menu
****************************************************************************/
void
ResetVideo_Menu()
{
	Mtx44 p;
	f32 yscale;
	u32 xfbHeight;

	VIDEO_Configure (vmode);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if (vmode->viTVMode & VI_NON_INTERLACE)
		VIDEO_WaitVSync();
	else
		while (VIDEO_GetNextField())
			VIDEO_WaitVSync();

	// clears the bg to color and clears the z buffer
	GXColor background = {0, 0, 0, 255};
	GX_SetCopyClear (background, 0x00ffffff);

	yscale = GX_GetYScaleFactor(vmode->efbHeight,vmode->xfbHeight);
	xfbHeight = GX_SetDispCopyYScale(yscale);
	GX_SetScissor(0,0,vmode->fbWidth,vmode->efbHeight);
	GX_SetDispCopySrc(0,0,vmode->fbWidth,vmode->efbHeight);
	GX_SetDispCopyDst(vmode->fbWidth,xfbHeight);
	GX_SetCopyFilter(vmode->aa,vmode->sample_pattern,GX_TRUE,vmode->vfilter);
	GX_SetFieldMode(vmode->field_rendering,((vmode->viHeight==2*vmode->xfbHeight)?GX_ENABLE:GX_DISABLE));

	if (vmode->aa)
		GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR);
	else
		GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);

	// setup the vertex descriptor
	// tells the flipper to expect direct data
	GX_ClearVtxDesc();
	GX_InvVtxCache ();
	GX_InvalidateTexAll();

	GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
	GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
	GX_SetVtxDesc (GX_VA_CLR0, GX_DIRECT);

	GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
	GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
	GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
	GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_TRUE);

	GX_SetNumChans(1);
	GX_SetNumTexGens(1);
	GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
	GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
	GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);

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

	guOrtho(p,0,479,0,639,0,300);
	GX_LoadProjectionMtx(p, GX_ORTHOGRAPHIC);

	GX_SetViewport(0,0,vmode->fbWidth,vmode->efbHeight,0,1);
	GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
	GX_SetAlphaUpdate(GX_TRUE);
}
Exemplo n.º 10
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);

}
Exemplo n.º 11
0
int BuildLists(GXTexObj texture) {
	// Make the new display list
	// For display lists, each command has an associated "cost" in bytes.
	// Add all these up to calculate the size of your display list before rounding up.
	// eke-eke says GX_Begin() costs 3 bytes (u8 + u16)
	// According to my research:
	// GX_Position3f32() is 12 bytes (f32*3)
	// GX_Normal3f32() is 12 bytes (f32*3)
	// GX_Color3f32() is actually 3 bytes ((f32 -> u8) * 3)
	// GX_TexCoord2f32() is 8 bytes (f32*2)
	// GX_End() seems to cost zero (there's no actual code in it)
	// Size -must- be multiple of 32, so (12*24) + (12*24) + (3*24) + (8*24) + 3 = 843
	// Rounded up to the nearest 32 is 864.
	// NOTE: Actual size may be up to 63 bytes -larger- than you calculate it to be due to padding and cache alignment.
	for (int i=0; i<5;i++) {
		boxList[i] = memalign(32,896);
		memset(boxList[i],0,896);
		DCInvalidateRange(boxList[i],896);
		GX_BeginDispList(boxList[i],896);
		GX_Begin(GX_QUADS,GX_VTXFMT0,24); // Start drawing
			// Bottom face
			GX_Position3f32(-1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top right
			GX_Position3f32( 1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Top left
			GX_Position3f32( 1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom left
			GX_Position3f32(-1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Bottom right
			// Front face
			GX_Position3f32(-1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom left
			GX_Position3f32( 1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Bottom right
			GX_Position3f32( 1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top right
			GX_Position3f32(-1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Top left
			// Back face
			GX_Position3f32(-1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Bottom right
			GX_Position3f32(-1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top right
			GX_Position3f32( 1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Top left
			GX_Position3f32( 1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom left
			// Right face
			GX_Position3f32( 1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Bottom right
			GX_Position3f32( 1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top right
			GX_Position3f32( 1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Top left
			GX_Position3f32( 1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom left
			// Left face
			GX_Position3f32(-1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom right
			GX_Position3f32(-1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Top right
			GX_Position3f32(-1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top left
			GX_Position3f32(-1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Bottom left
			// Top face
			GX_Position3f32(-1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(TopColors[i][0],TopColors[i][1],TopColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Top left
			GX_Position3f32(-1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(TopColors[i][0],TopColors[i][1],TopColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom left
			GX_Position3f32( 1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(TopColors[i][0],TopColors[i][1],TopColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Bottom rught
			GX_Position3f32( 1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1);
			GX_Color3f32(TopColors[i][0],TopColors[i][1],TopColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top right
		GX_End();         // Done drawing quads
		// GX_EndDispList() returns the size of the display list, so store that value and use it with GX_CallDispList().
		boxSize[i] = GX_EndDispList(); // Done building the box list
		if (boxSize[i] == 0) return 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);

	// Set up TEV to paint the textures properly.
	GX_SetTevOp(GX_TEVSTAGE0,GX_MODULATE);
	GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);

	// Load up the textures (just one this time).
	GX_LoadTexObj(&texture, GX_TEXMAP0);

	return 0;
}
Exemplo n.º 12
0
void Particle_Render(Mtx M_view, ParticleSystem* psystem, Camera* camera) {
	// setup TEV
	GX_ClearVtxDesc();
	
	GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
    GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);

	GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
    GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
	GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);

	// load model-view matrix
	Mtx M_modelView;
	guMtxIdentity(M_modelView);
	GX_LoadPosMtxImm(M_modelView, GX_PNMTX0);

	// setup tev
	GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
	GX_SetAlphaUpdate(GX_TRUE);

	GX_SetNumChans(1);

	GX_SetTevColorIn( 
		GX_TEVSTAGE0, 
		GX_CC_TEXC,  // a
		GX_CC_RASC,  // b
		GX_CC_TEXA,  // c 
		GX_CC_ZERO); // d

	GX_SetTevColorOp(
		GX_TEVSTAGE0,	// stage
		GX_TEV_ADD,		// op
		GX_TB_ZERO,		// bias
		GX_CS_SCALE_2,	// scale
		GX_ENABLE,		// clamp 0-255
		GX_TEVPREV);	// output reg


	GX_SetTevAlphaIn(
		GX_TEVSTAGE0, 
		GX_CA_ZERO,  // a
		GX_CA_TEXA,  // b
		GX_CA_RASA,  // c 
		GX_CA_ZERO); // d

	GX_SetTevAlphaOp(
		GX_TEVSTAGE0,	// stage
		GX_TEV_ADD,		// op
		GX_TB_ZERO,		// bias
		GX_CS_SCALE_1,	// scale
		GX_ENABLE,		// clamp 0-255
		GX_TEVPREV);	// output reg



	GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);

	GX_SetNumTexGens(1);
	GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);

	GX_LoadTexObj(&psystem->texture, GX_TEXMAP0);

	int n = psystem->n_particles;

	f32 texCoords[] = {
		0, 0,
		0, 1,
		1, 1,
		1, 0
	};

	GX_InvVtxCache();
	Vec3 camPos = camera->position();

	Mtx axisMtx;
	
	System::LogClear();
	
	Particle_Sort(M_view, psystem);

	GX_Begin(GX_QUADS, GX_VTXFMT6, n*4);
		for (int k = 0; k < n; k++) {
			int i = psystem->binsAllocations[k].particleIdx;
			//System::Log(L"p%d", i);
			Vec3& p  = psystem->positions[i];
			f32 lifetime = psystem->lifetimes[i];
			f32 age = psystem->ages[i];

			f32 ratio = age/lifetime;

			Vec3 forward = Math3D::normalized(camPos - p);

			Vec3 worldUp = Vec3(0, 1, 0);
			Vec3 right = Math3D::normalized(Math3D::cross(worldUp, forward));

			Vec3 up = Math3D::cross(forward, right);

			Mtx pm;

			guMtxCopy(M_view, pm);
			guMtxTranspose(pm, pm);
			pm[0][3] = p.x;		pm[1][3] = p.y;		pm[2][3] = p.z;

			guMtxConcat(M_view, pm, pm);
			
			f32 rotation = psystem->rotations[i];
			if (psystem->rotationInterpolator)
				rotation = psystem->rotationInterpolator->getValue(rotation, ratio);

			f32 size = psystem->sizes[i];
			if (psystem->sizeInterpolator)
				size = psystem->sizeInterpolator->getValue(size, ratio);

			if (psystem->colorInterpolator)
				psystem->colors[i] = psystem->colorInterpolator->getValue(ratio);

			Matrix34 M_rot = Math3D::matrixRotationZ(rotation);
			f32 hs = size*0.5f;
			Vec3 p0(-hs, +hs, 0);
			Vec3 p1(-hs, -hs, 0);
			Vec3 p2(+hs, -hs, 0);
			Vec3 p3(+hs, +hs, 0);

			Vec3 vs[4] = {p0, p1, p2, p3};

			for (int i = 0; i < 4; i++) {
				vs[i] = M_rot * vs[i];
				vs[i] = Math3D::matrixVecMul(pm, vs[i]);
			}
			
			for (int i = 0; i < 4; i++) {
				f32* coords = &texCoords[2*i];
				SendVertex(vs[i], psystem->colors[i], coords[0], coords[1]);
			}
		}
	GX_End();


	return;
}
Exemplo n.º 13
0
inline void Material::ApplyTevStages(bool modulate_colors) const
{
	u32 tev_stages_cnt = 0;

	if(flags->tev_stages)
	{
		// tev stages
		for(u32 i = 0; i < flags->tev_stages; ++i)
		{
			const TevStage &ts = tev_stages[i];

			GX_SetTevOrder(i, ts.texcoord, ts.tex_map | (ts.lowBit << 8), ts.color );
			GX_SetTevSwapMode(i, ts.ras_sel, ts.tex_sel);

			GX_SetTevColorIn(i, ts.color_in.a, ts.color_in.b, ts.color_in.c, ts.color_in.d);
			GX_SetTevColorOp(i, ts.color_in.tevop, ts.color_in.tevbias, ts.color_in.tevscale, ts.color_in.clamp, ts.color_in.tevregid );
			GX_SetTevKColorSel(i, ts.color_in.sel );

			GX_SetTevAlphaIn(i, ts.alpha_in.a, ts.alpha_in.b, ts.alpha_in.c, ts.alpha_in.d);
			GX_SetTevAlphaOp(i, ts.alpha_in.tevop, ts.alpha_in.tevbias, ts.alpha_in.tevscale, ts.alpha_in.clamp, ts.alpha_in.tevregid );
			GX_SetTevKAlphaSel(i, ts.alpha_in.sel );

			GX_SetTevIndirect(i, ts.ind.indtexid, ts.ind.format, ts.ind.bias, ts.ind.mtxid,
				ts.ind.wrap_s, ts.ind.wrap_t, ts.ind.addprev, ts.ind.utclod, ts.ind.a);

			tev_stages_cnt++;
		}
	}
	else
	{
		if(flags->texture_map == 0)
		{
			// 1st stage
			GX_SetTevOrder(GX_TEVSTAGE0, 0xFF, 0xFF, 4);
			GX_SetTevColorIn(GX_TEVSTAGE0, 0xF, 4, 0xA, 0xF);
			GX_SetTevAlphaIn(GX_TEVSTAGE0, 0x7, 2, 0x5, 0x7);
			tev_stages_cnt++;
		}
		else if(flags->texture_map == 1)
		{
			// 1st stage
			GX_SetTevOrder(GX_TEVSTAGE0, 0, 0, 0xFF);
			GX_SetTevColorIn(GX_TEVSTAGE0, 2, 4, 8, 0xF);
			GX_SetTevAlphaIn(GX_TEVSTAGE0, 1, 2, 4, 7);
			tev_stages_cnt++;

			// 2nd stage
			if(modulate_colors)
			{
				GX_SetTevOrder(GX_TEVSTAGE0 + tev_stages_cnt, 0xFF, 0xFF, 4);
				GX_SetTevColorIn(GX_TEVSTAGE0 + tev_stages_cnt, 0xF, 0, 0xA, 0xF);
				GX_SetTevAlphaIn(GX_TEVSTAGE0 + tev_stages_cnt, 7, 0, 5, 7);
				tev_stages_cnt++;
			}
		}
		else if(flags->texture_map == 2)
		{
			// 1st stage
			GX_SetTevOrder(GX_TEVSTAGE0, 0, 0, 0xFF);
			GX_SetTevColorIn(GX_TEVSTAGE0, 0xF, 0xF, 0xF, 8);
			GX_SetTevAlphaIn(GX_TEVSTAGE0, 7, 7, 7, 4);
			tev_stages_cnt++;

			// 2nd stage
			GX_SetTevOrder(GX_TEVSTAGE0 + tev_stages_cnt, 1, 1, 0xFF);
			GX_SetTevColorIn(GX_TEVSTAGE0 + tev_stages_cnt, 8, 0, 0xE, 0xF);
			GX_SetTevAlphaIn(GX_TEVSTAGE0 + tev_stages_cnt, 4, 0, 6, 7);
			GX_SetTevKColorSel(GX_TEVSTAGE0 + tev_stages_cnt, 0x1f);
			GX_SetTevKAlphaSel(GX_TEVSTAGE0 + tev_stages_cnt, 0x1f);
			tev_stages_cnt++;

			// 3rd stage
			if(modulate_colors)
			{
				GX_SetTevOrder(GX_TEVSTAGE0 + tev_stages_cnt, 0xFF, 0xFF, 4);
				GX_SetTevColorIn(GX_TEVSTAGE0 + tev_stages_cnt, 0xF, 0, 0xA, 0xF);
				GX_SetTevAlphaIn(GX_TEVSTAGE0 + tev_stages_cnt, 7, 0, 5, 7);
				tev_stages_cnt++;
			}
		}
		else
		{
			u32 TevKDefault[] = { 0x1F, 0x1B, 0x17, 0x13, 0x1E, 0x1A, 0x16, 0x12 };

			for(int i = 0; i < flags->texture_map; i++)
			{
				GX_SetTevOrder(i, i, i, 0xff );

				GX_SetTevColorIn(i, 0xf, 8, 0xe, i ? 0xf : 0 );
				GX_SetTevAlphaIn(i, 7, 4, 6, i ? 7 : 0 );
				GX_SetTevKColorSel(i, TevKDefault[i] );
				GX_SetTevKAlphaSel(i, TevKDefault[i] );
				tev_stages_cnt++;
			}

			GX_SetTevOrder(GX_TEVSTAGE0 + tev_stages_cnt, 0xff, 0xff, 0xff );
			GX_SetTevColorIn(GX_TEVSTAGE0 + tev_stages_cnt, 2, 4, 0, 0xf );
			GX_SetTevAlphaIn(GX_TEVSTAGE0 + tev_stages_cnt, 1, 2, 0, 7 );
			tev_stages_cnt++;

			if(modulate_colors)
			{
				GX_SetTevOrder(GX_TEVSTAGE0 + tev_stages_cnt, 0xFF, 0xFF, 4);
				GX_SetTevColorIn(GX_TEVSTAGE0 + tev_stages_cnt, 0xF, 0, 0xA, 0xF);
				GX_SetTevAlphaIn(GX_TEVSTAGE0 + tev_stages_cnt, 7, 0, 5, 7);
				tev_stages_cnt++;
			}
		}

		for(u32 i = 0; i < tev_stages_cnt; i++)
		{
			GX_SetTevColorOp(GX_TEVSTAGE0 + i, 0, 0, 0, 1, 0);
			GX_SetTevAlphaOp(GX_TEVSTAGE0 + i, 0, 0, 0, 1, 0);
			GX_SetTevDirect(GX_TEVSTAGE0 + i);
			GX_SetTevSwapMode(GX_TEVSTAGE0 + i, 0, 0);
		}
	}

	// enable correct number of tev stages
	GX_SetNumTevStages(tev_stages_cnt);
}
Exemplo n.º 14
0
// Perform the actual scene drawing.
void DrawScene(Mtx v, GXTexObj texture) {
	// Draw things
	// FIXME: Need to clear first?
	// FIXME: Check datatype sizes
	f32 x_m,y_m,z_m,u_m,v_m;       // Float types for temp x, y, z, u and v vertices
	f32 xtrans = -xpos;            // Used for player translation on the x axis
	f32 ztrans = -zpos;            // Used for player translation on the z axis
	f32 ytrans = -walkbias-0.25f;  // Used for bouncing motion up and down
	f32 sceneroty = 360.0f - yrot; // 360 degree angle for player direction
	int numtriangles;              // Integer to hold the number of triangles
	Mtx m; // Model matrix
	Mtx mt; // Model rotated matrix
	Mtx mv; // Modelview matrix
	guVector axis;                 // Vector for axis we're rotating on

	SetLight(v,LightColors[0],LightColors[1],LightColors[2]);

	// Set up TEV to paint the textures properly.
	GX_SetTevOp(GX_TEVSTAGE0,GX_MODULATE);
	GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);

	// Load up the textures (just one this time).
	GX_LoadTexObj(&texture, GX_TEXMAP0);

	//glRotatef(lookupdown,1.0f,0,0);
	axis.x = 1.0f;
	axis.y = 0;
	axis.z = 0;
	guMtxIdentity(m);
	guMtxRotAxisDeg(m, &axis, lookupdown);
	guMtxConcat(m,v,mv);

	//glrotatef(sceneroty,0,1.0f,0);
	axis.x = 0;
	axis.y = 1.0f;
	axis.z = 0;
	guMtxIdentity(m);
	guMtxRotAxisDeg(m, &axis, sceneroty);
	guMtxConcat(mv,m,mv);

	// Translate the camera view
	guMtxApplyTrans(mv,mt,xtrans,ytrans,ztrans);

	//glTranslatef(xtrans,ytrans,ztrans);
	//guMtxIdentity(m);
	//guMtxTrans(m, xtrans, ytrans, ztrans);	
	//guMtxConcat(v,m,v);

	// load the modelview matrix into matrix memory
	GX_LoadPosMtxImm(mt, GX_PNMTX0);

	numtriangles = sector1.numtriangles;

	// HACK: v tex coord is inverted so textures are rightside up.
	for (int loop_m = 0; loop_m < numtriangles; loop_m++) {
		GX_Begin(GX_TRIANGLES,GX_VTXFMT0,3);
			x_m = sector1.triangle[loop_m].vertex[0].x;
			y_m = sector1.triangle[loop_m].vertex[0].y;
			z_m = sector1.triangle[loop_m].vertex[0].z;
			u_m = sector1.triangle[loop_m].vertex[0].u;
			v_m = sector1.triangle[loop_m].vertex[0].v;
			GX_Position3f32(x_m,y_m,z_m);
			GX_Normal3f32((f32)0,(f32)0,(f32)1);
			//GX_Color3f32(0.7f,0.7f,0.7f);
			GX_TexCoord2f32(u_m,-v_m);

			x_m = sector1.triangle[loop_m].vertex[1].x;
			y_m = sector1.triangle[loop_m].vertex[1].y;
			z_m = sector1.triangle[loop_m].vertex[1].z;
			u_m = sector1.triangle[loop_m].vertex[1].u;
			v_m = sector1.triangle[loop_m].vertex[1].v;
			GX_Position3f32(x_m,y_m,z_m);
			GX_Normal3f32((f32)0,(f32)0,(f32)1);
			//GX_Color3f32(0.7f,0.7f,0.7f);
			GX_TexCoord2f32(u_m,-v_m);

			x_m = sector1.triangle[loop_m].vertex[2].x;
			y_m = sector1.triangle[loop_m].vertex[2].y;
			z_m = sector1.triangle[loop_m].vertex[2].z;
			u_m = sector1.triangle[loop_m].vertex[2].u;
			v_m = sector1.triangle[loop_m].vertex[2].v;
			GX_Position3f32(x_m,y_m,z_m);
			GX_Normal3f32((f32)0,(f32)0,(f32)1);
			//GX_Color3f32(0.7f,0.7f,0.7f);
			GX_TexCoord2f32(u_m,-v_m);
		GX_End();
	}

	return;
}
Exemplo n.º 15
0
// 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;
}
Exemplo n.º 16
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;
}
Exemplo n.º 17
0
void DrawAABB(MtxP M_model, Mtx M_view, AABB& box, u32 color) {
	GX_ClearVtxDesc();

	GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
    GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);

    GX_SetVtxAttrFmt(GX_VTXFMT5, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
    GX_SetVtxAttrFmt(GX_VTXFMT5, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);

	// build and load model-view matrix
	Mtx M_modelView;
	guMtxIdentity(M_modelView);
	guMtxConcat(M_view, M_model, M_modelView);
	GX_LoadPosMtxImm(M_modelView, GX_PNMTX0);

	GX_SetNumChans(1); // default, color = vertex color
	//GX_SetNumTexGens(0);

    GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
    GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);

	u8 indices[8] = {0, 1, 0, 2, 1, 3, 2, 3};
	guVector& m = box.min;
	f32* d = box.d;

	guVector v_bottom[4];
	v_bottom[0] = _vec(m.x,			m.y,	m.z);	
	v_bottom[1] = _vec(m.x + d[0],	m.y,	m.z);
	v_bottom[2] = _vec(m.x,			m.y,	m.z + d[2]);
	v_bottom[3] = _vec(m.x + d[0],	m.y,	m.z + d[2]);

	guVector v_top[4];
	for (int i = 0; i < 4; i++)
		v_top[i] = _vec(v_bottom[i].x, v_bottom[i].y + d[1], v_bottom[i].z);

	GX_Begin(GX_LINES, GX_VTXFMT5, 24);
		// draw bottom
		for (u8 i = 0; i < 8; i += 2) {
			guVector& v0 = v_bottom[indices[i]];
			guVector& v1 = v_bottom[indices[i+1]];

			SendVertex(v0, color);
			SendVertex(v1, color);
		}

		// draw top
		for (u8 i = 0; i < 8; i += 2) {
			guVector& v0 = v_top[indices[i]];
			guVector& v1 = v_top[indices[i+1]];

			SendVertex(v0, color);
			SendVertex(v1, color);
		}

		// connect bottom vertices with the top ones
		for (u8 i = 0; i < 4; i++) {
			guVector& v0 = v_bottom[i];
			guVector& v1 = v_top[i];

			SendVertex(v0, color);
			SendVertex(v1, color);
		}
	GX_End();
}
Exemplo n.º 18
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 )
    }
}
Exemplo n.º 19
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;
}