示例#1
0
文件: gl.c 项目: machinamentum/gl2gx
void glTranslatef( GLfloat x, GLfloat y, GLfloat z ) {
	Mtx temp;

	guMtxIdentity(temp);
	guMtxTrans(temp, x, y, z);	
	guMtxConcat(model,temp,model);
}
示例#2
0
PlayerShot::PlayerShot() : BaseObject(0.0f, 0.0f, 0.0f){
    direction.x = direction.y = 0.0f; direction.z = -1.0f;
    prevPos.x = prevPos.y = prevPos.z = 0.0f;
    ax = ay = az = 0.0f;
    model = 0;
	guMtxIdentity(rotationMtx);
}
示例#3
0
PlayerShot::PlayerShot(Model * model, f32 x, f32 y, f32 z) : BaseObject(x, y, z){
    direction.x = direction.y = 0.0f; direction.z = -1.0f;
    prevPos.x = prevPos.y = prevPos.z = 0.0f;
    ax = ay = az = 0.0f;
    this->model = model;
	guMtxIdentity(rotationMtx);
}
示例#4
0
void DrawScene(Mtx view) {
	Mtx model,modelview; // Various matrices
	guVector axis;                       // Axis to rotate on

	// BUG: Light ignores underlying polygon colors.
	SetLight(view); // Setup the light

	for (yloop = 1; yloop < 6; yloop++) { // Loop through the y plane
		for (xloop = 0; xloop < yloop; xloop++) { // Loop through the x plane
			// Position the cubes on the screen
			guMtxIdentity(model);

			axis.x = 1.0f;
			axis.y = 0;
			axis.z = 0;
			guMtxRotAxisDeg(model,&axis,(45.0f-(2.0f*(float)yloop)+xrot)); // Tilt the cubes up and down

			axis.x = 0;
			axis.y = 1.0f;
			guMtxRotAxisDeg(model,&axis,(45.0f+yrot)); // Spin cubes left and right

			guMtxTransApply(model,model,(1.4f+((float)xloop*2.8f)-((float)yloop*1.4f)),(((6.0f-(float)yloop)*2.2f)-7.0f),-20.0f);

			guMtxConcat(model,view,modelview);
			GX_LoadPosMtxImm(modelview, GX_PNMTX0);

			GX_CallDispList(boxList[yloop-1],boxSize[yloop-1]); // Draw the box
		}
	}
}
示例#5
0
文件: main.cpp 项目: notnotme/nwancat
// rulez nyan scene
int main(int argc, char **argv)
{
	bool nyaning = true;

	// self explain
	nyan();
	MP3Player_PlayBuffer(nyannyannyan_mp3, nyannyannyan_mp3_size, NULL);

	VIDEO_SetBlack(FALSE);
	while(nyaning)
	{
		u64 cticks = ticks_to_millisecs(gettime());
		// Loop the sound if ended
		if(!MP3Player_IsPlaying()) MP3Player_PlayBuffer(nyannyannyan_mp3, nyannyannyan_mp3_size, NULL);
		//Check wiimote input
		WPAD_ScanPads();
		u32 pressed = WPAD_ButtonsDown(0);
		if (pressed & WPAD_BUTTON_HOME) nyaning = false;
		// blackscreen until 3,8s like the youtube video (not extreme precison ;))
		if(cticks < startTime+3900) continue;
		// bkg frame counter (tick each 100ms)
		if(cticks > bkgTimeCounter+100)
		{
			bkgTimeCounter = cticks;
			currentBkgStep = (currentBkgStep+1) % BKG_STEP;
		}
		// nyan frame counter (tick each 60ms)
		if(cticks > nyanTimeCounter+60)
		{
			nyanTimeCounter = cticks;
			currentNyanStep = (currentNyanStep+1) % NYAN_STEP;
		}
		// Set the 2d matrix
		guMtxIdentity(GXmodelView2D);
		GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0);

		// nyan
		f32 move =  delta % BKG_SIZE;
		f32 x = -move;
		while(x < rmode->fbWidth)
		{
			drawBkgSprite(x, currentBkgStep);
			x += BKG_SIZE;
		}

		// nyan nyan
		drawNyan(-5, 240 - ((NYAN_HEIGHT*8)/2), currentNyanStep);

		// Copy & switch fb
		GX_DrawDone();
		GX_CopyDisp(xfb[wichFb], GX_TRUE);
		VIDEO_SetNextFramebuffer(xfb[wichFb]);
		VIDEO_Flush();
		VIDEO_WaitVSync();
		wichFb ^= 1;
		delta += 8;
	}

	return 0;
}
示例#6
0
文件: gl.c 项目: machinamentum/gl2gx
void  glScalef (GLfloat x, GLfloat y, GLfloat z){
	Mtx temp;

	guMtxIdentity(temp);
	guMtxScale(temp, x, y, z);
	guMtxConcat(model,temp,model);
}
void Util3D::Trans(f32 xpos, f32 ypos)
{
	Mtx Matrix, Final;
	guMtxIdentity(Matrix);
	guMtxTrans(Matrix,xpos, ypos, 0 );	// Position
	guMtxConcat(Singleton<WiiManager>::GetInstanceByRef().GetCamera()->GetcameraMatrix(),Matrix,Final);
	GX_LoadPosMtxImm (Final, GX_PNMTX0); 
}
示例#8
0
static void
render_texture (greets_data *gdata, float zpos, float scroll)
{
  world_info *world = gdata->world;
  Mtx mvtmp;
  extern Mtx tube_rotmtx;

  guMtxIdentity (mvtmp);
  guMtxConcat (mvtmp, tube_rotmtx, mvtmp);

  object_set_matrices (&world->scene, &gdata->greets_loc, world->scene.camera,
		       mvtmp, NULL, world->projection, world->projection_type);

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

  GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
  GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);

  GX_SetCullMode (GX_CULL_NONE);

  scroll = scroll * 8.0f;
  scroll = scroll - floorf (scroll);
  scroll = scroll * 1./8;

  GX_Begin (GX_TRIANGLESTRIP, GX_VTXFMT0, 4);

  GX_Position3f32 (-40, 8, 0);
  GX_TexCoord2f32 (scroll, 0);

  GX_Position3f32 (40, 8, 0);
  GX_TexCoord2f32 (4 + scroll, 0);

  GX_Position3f32 (-40, -8, 0);
  GX_TexCoord2f32 (scroll, 0.5);

  GX_Position3f32 (40, -8, 0);
  GX_TexCoord2f32 (4 + scroll, 0.5);

  GX_End ();

  GX_Begin (GX_TRIANGLESTRIP, GX_VTXFMT0, 4);

  GX_Position3f32 (-40, 0, 8);
  GX_TexCoord2f32 (scroll, 0);

  GX_Position3f32 (40, 0, 8);
  GX_TexCoord2f32 (4 + scroll, 0);

  GX_Position3f32 (-40, 0, -8);
  GX_TexCoord2f32 (scroll, 0.5);

  GX_Position3f32 (40, 0, -8);
  GX_TexCoord2f32 (4 + scroll, 0.5);

  GX_End ();
}
示例#9
0
void prepairForSeriousDrawing(){
	// do this before drawing
	GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1);

	guMtxIdentity(model);
	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);
}
示例#10
0
文件: gl.c 项目: machinamentum/gl2gx
void  glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
	Mtx temp;
	guVector axis;

	axis.x = x;
	axis.y = y;
	axis.z = z;
	guMtxIdentity(temp);
	guMtxRotAxisDeg(temp, &axis, angle);
	guMtxConcat(model,temp,model);

}
示例#11
0
void Enemy::Draw(Mtx44 view) {
	Mtx44 model, modelview;
	guMtxIdentity(model);
	guMtxIdentity(modelview);
	guMtxTransApply(model, model, this->x, this->y, this->z);
	guMtxConcat(view, model, modelview);
	GX_LoadPosMtxImm(modelview, GX_PNMTX0);
	GX_LoadTexObj(this->tex, GX_TEXMAP0);
	
	f32 width, height;
	width = this->w / 2.0f;
	height = this->h / 2.0f;
	GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
		GX_Position3f32(-width, height, 0);
		GX_Color4u8(255, 255, 255, 255);
		if( this->velx > 0 )
			GX_TexCoord2f32(1, 0);
		else
			GX_TexCoord2f32(0, 0);
		GX_Position3f32(width, height, 0);
		GX_Color4u8(255, 255, 255, 255);
		if( this->velx > 0 ) 
			GX_TexCoord2f32(0, 0);
		else
			GX_TexCoord2f32(1, 0);
		GX_Position3f32(width, -height, 0);
		GX_Color4u8(255, 255, 255, 255);
		if( this->velx > 0 )
			GX_TexCoord2f32(0, 1);
		else 
			GX_TexCoord2f32(1, 1);
		GX_Position3f32(-width, -height, 0);
		GX_Color4u8(255, 255, 255, 255);
		if( this->velx > 0 )
			GX_TexCoord2f32(1, 1);
		else 
			GX_TexCoord2f32(0, 1);
	GX_End();
}
示例#12
0
/****************************************************************************
 * Menu_DrawImg
 *
 * Draws the specified image on screen using GX
 ***************************************************************************/
void Menu_DrawImg(f32 xpos, f32 ypos, f32 zpos, f32 width, f32 height, u8 data[], f32 degrees, f32 scaleX, f32 scaleY,
		u8 alpha, int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4)
{
	if (data == NULL) return;

	GX_LoadProjectionMtx(FSProjection2D, GX_ORTHOGRAPHIC);

	GXTexObj texObj;

	GX_InitTexObj(&texObj, data, width, height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
	GX_LoadTexObj(&texObj, GX_TEXMAP0);
	GX_ClearVtxDesc();
	GX_InvVtxCache();
	GX_InvalidateTexAll();

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

	Mtx m, m1, m2, mv;
	width *= 0.5f;
	height *= 0.5f;
	guMtxIdentity(m1);
	guMtxScaleApply(m1, m1, scaleX, scaleY, 1.0f);
	guVector axis = (guVector) {0 , 0, 1};
	guMtxRotAxisDeg (m2, &axis, degrees);
	guMtxConcat(m1, m2, m);

	guMtxTransApply(m, m, xpos + width + 0.5f, ypos + height + 0.5f, zpos);
	guMtxConcat(FSModelView2D, m, mv);
	GX_LoadPosMtxImm(mv, GX_PNMTX0);

	GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
	GX_Position3f32(-width + XX1, -height + YY1, 0);
	GX_Color4u8(0xFF, 0xFF, 0xFF, alpha);
	GX_TexCoord2f32(0, 0);

	GX_Position3f32(width + XX2, -height + YY2, 0);
	GX_Color4u8(0xFF, 0xFF, 0xFF, alpha);
	GX_TexCoord2f32(1, 0);

	GX_Position3f32(width + XX3, height + YY3, 0);
	GX_Color4u8(0xFF, 0xFF, 0xFF, alpha);
	GX_TexCoord2f32(1, 1);

	GX_Position3f32(-width + XX4, height + YY4, 0);
	GX_Color4u8(0xFF, 0xFF, 0xFF, alpha);
	GX_TexCoord2f32(0, 1);

	GX_End();
}
示例#13
0
文件: video.c 项目: MANICX100/wiimc
/****************************************************************************
 * Menu_DrawImg
 *
 * Draws the specified image on screen using GX
 ***************************************************************************/
void Menu_DrawImg(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[],
	f32 degrees, f32 scaleX, f32 scaleY, u8 alpha)
{
	if(data == NULL)
		return;

	GXTexObj texObj;

	GX_InitTexObj(&texObj, data, width, height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
	GX_LoadTexObj(&texObj, GX_TEXMAP0);
	GX_InvalidateTexAll();

	GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
	GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);

	Mtx m,m1,m2, mv;
	width  >>= 1;
	height >>= 1;

	guMtxIdentity (m1);
	guMtxScaleApply(m1,m1,scaleX,scaleY,1.0);
	guVector axis = (guVector) {0 , 0, 1 };
	guMtxRotAxisDeg (m2, &axis, degrees);
	guMtxConcat(m2,m1,m);

	guMtxTransApply(m,m, xpos+width,ypos+height,0);
	guMtxConcat (GXmodelView2D, m, mv);
	GX_LoadPosMtxImm (mv, GX_PNMTX0);

	GX_Begin(GX_QUADS, GX_VTXFMT0,4);
	GX_Position3f32(-width, -height,  0);
	GX_Color4u8(0xFF,0xFF,0xFF,alpha);
	GX_TexCoord2f32(0, 0);

	GX_Position3f32(width, -height,  0);
	GX_Color4u8(0xFF,0xFF,0xFF,alpha);
	GX_TexCoord2f32(1, 0);

	GX_Position3f32(width, height,  0);
	GX_Color4u8(0xFF,0xFF,0xFF,alpha);
	GX_TexCoord2f32(1, 1);

	GX_Position3f32(-width, height,  0);
	GX_Color4u8(0xFF,0xFF,0xFF,alpha);
	GX_TexCoord2f32(0, 1);
	GX_End();
	GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0);

	GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
	GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
}
示例#14
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);
}
示例#15
0
void draw_sun( f32 x, f32 y, f32 r, f32 ang, u8 *col )
{
	int i;
	Mtx m, mv;

	circle( x, y, r, col, 1, 100, 0.0f );
	
	guMtxIdentity( m );
	guMtxRotAxisRad( m, &rotax, ang );
	guMtxTransApply( m, m, x, y, 0 );
	guMtxConcat( GXmodelView2D, m, mv );
	GX_LoadPosMtxImm( mv, GX_PNMTX0 );

	GX_Begin( GX_QUADS, GX_VTXFMT0, NUMRAYS*4 );
	for( i=0; i<NUMRAYS; i++ )
	{
		GX_Position3f32( sunrays[i*4  ].x     , sunrays[i*4  ].y     , 0.0f );
		GX_Color4u8( col[0], col[1], col[2], 0xff );
		GX_Position3f32( sunrays[i*4+1].x     , sunrays[i*4+1].y     , 0.0f );
		GX_Color4u8( col[0], col[1], col[2], 0xff );
		GX_Position3f32( sunrays[i*4+2].x*0.9f, sunrays[i*4+2].y*0.9f, 0.0f );
		GX_Color4u8( col[0], col[1], col[2], 0xff );
		GX_Position3f32( sunrays[i*4+3].x*0.9f, sunrays[i*4+3].y*0.9f, 0.0f );
		GX_Color4u8( col[0], col[1], col[2], 0xff );
	}
	GX_End();

	for( i=0; i<NUMRAYS; i++ )
	{
		GX_Begin( GX_LINESTRIP, GX_VTXFMT0, 4 );
			GX_Position3f32( sunrays[i*4+3].x, sunrays[i*4+3].y, 0.0f );
			GX_Color4u8( 0, 0, 0, 0xff );
			GX_Position3f32( sunrays[i*4  ].x, sunrays[i*4  ].y, 0.0f );
			GX_Color4u8( 0, 0, 0, 0xff );
			GX_Position3f32( sunrays[i*4+1].x, sunrays[i*4+1].y, 0.0f );
			GX_Color4u8( 0, 0, 0, 0xff );
			GX_Position3f32( sunrays[i*4+2].x, sunrays[i*4+2].y, 0.0f );
			GX_Color4u8( 0, 0, 0, 0xff );
		GX_End();
	}
	

	GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0);

	GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
  	GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
}
示例#16
0
void QuadPane::Draw(const BannerResources& resources, u8 render_alpha, const float ws_scale, Mtx &modelview, u16 material_index, u8 texture_flip) const
{
	if(!header)
		return;

	if (material_index < resources.materials.size())
	{
		bool modulate_color = IsModulateColor(header->vertex_colors, render_alpha);
		resources.materials[material_index]->Apply(resources, render_alpha, modulate_color);
	}

	Mtx m, mv;
	guMtxIdentity (m);

	guMtxTransApply(m,m, -0.5f * GetOriginX(), -0.5f * GetOriginY(), 0.f);
	guMtxScaleApply(m,m, GetWidth(), GetHeight(), 1.f);

	guMtxConcat (modelview, m, mv);

	GX_LoadPosMtxImm (mv, GX_PNMTX0);

	GX_ClearVtxDesc();
	GX_InvVtxCache();
	GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
	for(u32 i = 0; i < header->tex_coord_count; i++)
		GX_SetVtxDesc(GX_VA_TEX0+i, GX_DIRECT);

	GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
	if(texture_flip)
	{
		SetVertex(0, 0.f, 0.f, render_alpha);
		SetVertex(1, 1.f, 0.f, render_alpha);
		SetVertex(3, 1.f, 1.f, render_alpha);
		SetVertex(2, 0.f, 1.f, render_alpha);
	}
	else
	{
		SetVertex(2, 0.f, 0.f, render_alpha);
		SetVertex(3, 1.f, 0.f, render_alpha);
		SetVertex(1, 1.f, 1.f, render_alpha);
		SetVertex(0, 0.f, 1.f, render_alpha);
	}
	GX_End();
}
void BannerWindow::Init(u8 *font1, u8 *font2)
{
	MaxAnimSteps = 30;
	returnVal = -1;
	reducedVol = false;
	ScreenProps.x = 620; //620
	ScreenProps.y = 400; //400
	sysFont1 = font1;
	sysFont2 = font2;
	ShowBanner = true;

	guMtxIdentity(modelview);
	guMtxTransApply(modelview, modelview, (!m_vid.wide() || m_vid.vid_50hz()) ? 0.0f : 2.0f, m_vid.vid_50hz() ? -1.0f : 0.0f, 0.0F);

	AnimPosX = 0.5f * (ScreenProps.x - fIconWidth);
	AnimPosY = 0.5f * (ScreenProps.y - fIconHeight);
	AnimationRunning = false;
	Brightness = 0;

	// this just looks better for banner/icon ratio
	xDiff = 0.5f * (m_vid.wide() ? (m_vid.vid_50hz() ? 616 : 620.0f) : 608.0f);
	yDiff = 0.5f * (m_vid.vid_50hz() ? 448.0f : 470.0f);

	iconWidth = fIconWidth - 20;
	iconHeight = fIconHeight - 20;

	ratioX = xDiff * 2.f / iconWidth;
	ratioY = yDiff * 2.f / iconHeight;

	stepx1 = ((ScreenProps.x * 0.1f - xDiff) - (AnimPosX + 0.5f * fIconWidth - 0.5f * iconWidth)) * ratioX;
	stepx2 = ((ScreenProps.x * 0.1f + xDiff) - (AnimPosX + 0.5f * fIconWidth + 0.5f * iconWidth)) * ratioX;
	stepy1 = ((ScreenProps.y * 0.9f - yDiff) - (AnimPosY + 0.5f * fIconHeight - 0.5f * iconHeight)) * ratioY;
	stepy2 = ((ScreenProps.y * 0.9f + yDiff) - (AnimPosY + 0.5f * fIconHeight + 0.5f * iconHeight)) * ratioY;

	gameBanner.Clear();
	if(!FontLoaded)
	{
		gameBanner.LoadFont(sysFont1, sysFont2);
		FontLoaded = true;
	}
}
示例#18
0
void draw_star( f32 scale, f32 angle, f32 x, f32 y, u8 *col, u8 alpha )
{
	int i, j;
	Mtx m,m1,m2,mv;

	guMtxIdentity(m1);
	guMtxScaleApply( m1, m1, scale, scale, 1.0f );
	guMtxRotAxisRad( m2, &rotax, angle );
	guMtxConcat( m2, m1, m);

	guMtxTransApply( m, m, x, y, 0 );
	guMtxConcat( GXmodelView2D, m, mv );
	GX_LoadPosMtxImm( mv, GX_PNMTX0 );

	GX_Begin( GX_TRIANGLES, GX_VTXFMT0, 3*NUM_STAR_POLYS );
	for( i=0; i<NUM_STAR_POLYS*3; i++ )
	{
		j = star_polys[i]*2;
		GX_Position3f32( star_pts[j], star_pts[j+1], 0.0f );
		GX_Color4u8( col[0], col[1], col[2], alpha );
	}
	GX_End();

	GX_Begin( GX_LINESTRIP, GX_VTXFMT0, NUM_STAR_EDGES );
	for( i=0; i<NUM_STAR_EDGES; i++ )
	{
		j = star_edges[i]*2;
		GX_Position3f32( star_pts[j], star_pts[j+1], 0.0f );
		GX_Color4u8( 0, 0, 0, alpha );
	}
	GX_End();
	

	GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0);

	GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
  	GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
}
示例#19
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();
}
示例#20
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;
}
示例#21
0
void Pane::Render(const Resources& resources, u8 parent_alpha, Mtx &modelview,
				  bool widescreen, bool modify_alpha) const
{
	if (!GetVisible() || GetHide())
		return;

	u8 render_alpha = header->alpha;

    if(RootPane && parent_alpha != 0xFF)
    {
        render_alpha = MultiplyAlpha(header->alpha, parent_alpha);
        modify_alpha = true;
    }
	else if(!RootPane && modify_alpha)
	{
		render_alpha = MultiplyAlpha(header->alpha, parent_alpha);
	}
	else if(GetInfluencedAlpha() && header->alpha != 0xff)
	{
		modify_alpha = true;
		parent_alpha = MultiplyAlpha(header->alpha, parent_alpha);
	}

	float ws_scale = 1.0f;

	if( widescreen && GetWidescren() )
	{
		ws_scale *= 0.82f; // should actually be 0.75?
		widescreen = false;
	}

	Mtx m1,m2,m3,m4;
	guMtxIdentity (m1);

	// Scale
	guMtxScaleApply(m1,m1, header->scale.x * ws_scale, header->scale.y, 1.f);

	// Rotate
	guMtxRotDeg ( m2, 'x', header->rotate.x );
	guMtxRotDeg ( m3, 'y', header->rotate.y );
	guMtxRotDeg ( m4, 'z', header->rotate.z );
	guMtxConcat(m2, m3, m2);
	guMtxConcat(m2, m4, m2);
	guMtxConcat(m1, m2, m1);

	// Translate
	guMtxTransApply(m1,m1, header->translate.x, header->translate.y, header->translate.z);

	guMtxConcat (modelview, m1, pane_view);

	bool scissor = gxScissorForBindedLayouts;
	u32 scissorX = 0;
	u32 scissorY = 0;
	u32 scissorW = 0;
	u32 scissorH = 0;

	// calculate scissors if they will be used
	if( scissor )
	{
		Mtx mv2, mv3;
		guMtxIdentity (mv2);
		guMtxIdentity (mv3);
		guMtxTransApply(mv2,mv2, -0.5f * GetOriginX() * GetWidth(), -0.5f * GetOriginY() * GetHeight(), 0.f);
		guMtxTransApply(mv3,mv3, 0.5f * GetOriginX() * GetWidth(), 0.5f * GetOriginY() * GetHeight(), 0.f);
		guMtxScaleApply(mv2, mv2, 1.0f, -1.0f, 1.0f);
		guMtxScaleApply(mv3, mv3, 1.0f, -1.0f, 1.0f);
		guMtxConcat (pane_view, mv2, mv2);
		guMtxConcat (pane_view, mv3, mv3);

		f32 viewport[6];
		f32 projection[7];

		GX_GetViewportv(viewport);
        GX_GetProjectionv(MainProjection, projection, GX_ORTHOGRAPHIC);

		guVector vecTL;
		guVector vecBR;
		GX_Project(0.0f, 0.0f, 0.0f, mv2, projection, viewport, &vecTL.x, &vecTL.y, &vecTL.z);
		GX_Project(0.0f, 0.0f, 0.0f, mv3, projection, viewport, &vecBR.x, &vecBR.y, &vecBR.z);

        // round up scissor box offset and round down the size
        scissorX = (u32)(0.5f + std::max(vecTL.x, 0.0f));
        scissorY = (u32)(0.5f + std::max(vecTL.y, 0.0f));
        scissorW = (u32)std::max(vecBR.x - vecTL.x, 0.0f);
        scissorH = (u32)std::max(vecBR.y - vecTL.y, 0.0f);

		GX_SetScissor( scissorX, scissorY, scissorW, scissorH );
	}

	// binded layouts dont inheiret the modified widescreen setting
	bool realWS = ( _CONF_GetAspectRatio() == CONF_ASPECT_16_9 );

	// draw binded layouts that appear under this one
	foreach( Layout *l, bindedLayoutsUnder )
	{
		l->RenderWithCurrentMtx( pane_view, realWS );
	}
示例#22
0
文件: gl.c 项目: machinamentum/gl2gx
void glLoadIdentity(void) {
	guMtxIdentity(model);
}
示例#23
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();
}
示例#24
0
/*
 * GX render callback
 */
void wii_render_callback()
{
  GX_SetVtxDesc( GX_VA_POS, GX_DIRECT );
  GX_SetVtxDesc( GX_VA_CLR0, GX_DIRECT );
  GX_SetVtxDesc( GX_VA_TEX0, GX_NONE );

  Mtx m;    // model matrix.
  Mtx mv;   // modelview matrix.

  guMtxIdentity( m ); 
  guMtxTransApply( m, m, 0, 0, -100 );
  guMtxConcat( gx_view, m, mv );
  GX_LoadPosMtxImm( mv, GX_PNMTX0 ); 

  // Diff switches
  wii_atari_display_diff_switches();

  //
  // Debug
  //

  static int dbg_count = 0;

  if( wii_debug && !wii_testframe )
  {    
    static char text[256] = "";
    static char text2[256] = "";
    dbg_count++;

    if( dbg_count % 60 == 0 )
    {
      /* a: %d, %d, c: 0x%x,0x%x,0x%x*/
      /* wii_sound_length, wii_convert_length, memory_ram[CTLSWB], riot_drb, memory_ram[SWCHB] */
      sprintf( text, 
        "v: %.2f, hs: %d, %d, timer: %d, wsync: %s, %d, stl: %s, mar: %d, cpu: %d, ext: %d, rnd: %d, hb: %d",
        wii_fps_counter, 
        high_score_set,
        hs_sram_write_count, 
        ( riot_timer_count % 1000 ),      
        ( dbg_wsync ? "1" : "0" ),
        dbg_wsync_count,
        ( dbg_cycle_stealing ? "1" : "0" ),            
        dbg_maria_cycles,
        dbg_p6502_cycles,
        dbg_saved_cycles,
        RANDOM,
        cartridge_hblank
      );       
    }

    //sprintf( text, "video: %.2f", wii_fps_counter );
    wii_gx_drawtext( -310, 210, 14, text, ftgxWhite, 0 ); 

    if( lightgun_enabled )
    {      
      //ir_t ir;
      //WPAD_IR(WPAD_CHAN_0, &ir);

      sprintf( text2, 
        "lightgun: %d, %d, %d, %.2f, %d, [%d, %d]", 
        /*"lightgun: %d, %d, %d, %.2f, %d, [%d, %d] %d, %d, %d, %d", */
        cartridge_crosshair_x, cartridge_crosshair_y,
        lightgun_scanline, lightgun_cycle, wii_dbg_scanlines, 
        wii_ir_x, wii_ir_y /*,
        ir.vres[0], ir.vres[1], ir.offset[0], ir.offset[1]*/ );

      wii_gx_drawtext( -310, -210, 14, text2, ftgxWhite, 0 );
    }
  }
}
示例#25
0
void BoxCover::Draw()
{
	u8 BoxAlpha = (int) (alpha+alphaDyn) & 0xFF;

	GX_LoadProjectionMtx(projection, GX_PERSPECTIVE);

	GX_ClearVtxDesc();
	GX_InvVtxCache();
	GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
	GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);

	//! don't draw inside of the box
	GX_SetCullMode(GX_CULL_FRONT);

	Mtx	modelView;
	Mtx	modelView2;
	Mtx	modelView3;

	guVector cubeAxis = {0,0,1};
	guVector cubeAxis2 = {0,1,0};
	guVector cubeAxis3 = {1,0,0};
	guMtxIdentity(modelView);
	guMtxRotAxisDeg(modelView3, &cubeAxis3, RotX-Animation2);
	guMtxRotAxisDeg(modelView2, &cubeAxis2, RotY+Animation2+xoffsetDyn/2.0f);
	guMtxRotAxisDeg(modelView, &cubeAxis, RotZ-Animation);
	guMtxConcat(modelView3, modelView2, modelView2);
	guMtxConcat(modelView2, modelView, modelView);
	if(Settings.widescreen)
		guMtxScaleApply(modelView, modelView, Settings.WSFactor, 1.0f, 1.0f);
	guMtxTransApply(modelView, modelView, PosX+xoffsetDyn/680.0f+movePosX, PosY+yoffsetDyn/680.0f+movePosY, PosZ);
	guMtxConcat(view,modelView,modelView);

	GX_LoadPosMtxImm(modelView,	GX_PNMTX0);

	//! Border quads
	GX_LoadTexObj(&boxBorderTex, GX_TEXMAP0);
	GX_InvalidateTexAll();

	GX_SetArray(GX_VA_POS, (void *) &g_boxMeshQ[0].pos, sizeof(g_boxMeshQ[0]));
	GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshQ[0].texCoord, sizeof(g_boxMeshQ[0]));

	GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxMeshQSize);
	for (u32 j = 0; j < g_boxMeshQSize; ++j)
	{
		GX_Position1x8(j);
		GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
		GX_TexCoord1x8(j);
	}
	GX_End();

	//! Border triangles
	GX_SetArray(GX_VA_POS, (void *) &g_boxMeshT[0].pos, sizeof(g_boxMeshT[0]));
	GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshT[0].texCoord, sizeof(g_boxMeshT[0]));

	GX_Begin(GX_TRIANGLES, GX_VTXFMT0, g_boxMeshTSize);
	for (u32 j = 0; j < g_boxMeshTSize; ++j)
	{
		GX_Position1x8(j);
		GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
		GX_TexCoord1x8(j);
	}
	GX_End();

	//! Back Cover (Might be flat)
	GX_LoadTexObj(flatCover ? &defaultBoxTex : &coverTex, GX_TEXMAP0);
	GX_InvalidateTexAll();

	GX_SetArray(GX_VA_POS, (void *) &g_boxBackCoverMesh[0].pos, sizeof(g_boxBackCoverMesh[0]));
	GX_SetArray(GX_VA_TEX0, (void *) &g_boxBackCoverMesh[0].texCoord, sizeof(g_boxBackCoverMesh[0]));

	GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxBackCoverMeshSize);
	for (u32 j = 0; j < g_boxBackCoverMeshSize; ++j)
	{
		GX_Position1x8(j);
		if(flatCover)
			GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
		else
			GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
		GX_TexCoord1x8(j);
	}
	GX_End();

	if(flatCover)
	{
		//! Front Flat Cover
		GX_LoadTexObj(&coverTex, GX_TEXMAP0);
		GX_InvalidateTexAll();

		GX_SetArray(GX_VA_POS, (void *) &g_flatCoverMesh[0].pos, sizeof(g_flatCoverMesh[0]));
		GX_SetArray(GX_VA_TEX0, (void *) &g_flatCoverMesh[0].texCoord, sizeof(g_flatCoverMesh[0]));

		GX_Begin(GX_QUADS, GX_VTXFMT0, g_flatCoverMeshSize);
		for (u32 j = 0; j < g_flatCoverMeshSize; ++j)
		{
			GX_Position1x8(j);
			GX_Color4u8(0xff, 0xff, 0xff, 0xff);
			GX_TexCoord1x8(j);
		}
		GX_End();
	}
	else
	{
		//! Front Cover
		GX_SetArray(GX_VA_POS, (void *) &g_boxCoverMesh[0].pos, sizeof(g_boxCoverMesh[0]));
		GX_SetArray(GX_VA_TEX0, (void *) &g_boxCoverMesh[0].texCoord, sizeof(g_boxCoverMesh[0]));

		GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxCoverMeshSize);
		for (u32 j = 0; j < g_boxCoverMeshSize; ++j)
		{
			GX_Position1x8(j);
			GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
			GX_TexCoord1x8(j);
		}
		GX_End();
	}

	//! stop cull
	GX_SetCullMode(GX_CULL_NONE);

	UpdateEffects();
}
示例#26
0
文件: video.c 项目: MANICX100/wiimc
/****************************************************************************
 * 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);
}
示例#27
0
void
reduce_cubemap (cubemap_info *cubemap, int subdiv)
{
  int x, y, face;
  const u32 vtxfmt = GX_VTXFMT0;
  Mtx mvtmp;
  Mtx44 ortho;
  object_loc rect_loc;
  scene_info rect_scene;
  int half_subdiv = subdiv / 2;
  float scale_factor = 1.0 / ((float) half_subdiv - 0.5);
  
  /* Using an even number of subdivisions and spreading evenly from -1...1
     ensures we don't try to evaluate the singularity point at the back of the
     sphere.  */
  assert ((subdiv & 1) == 0);
  
  scene_set_pos (&rect_scene, (guVector) { 0, 0, -5 });
  scene_set_lookat (&rect_scene, (guVector) { 0, 0, 0 });
  scene_set_up (&rect_scene, (guVector) { 0, 1, 0 });
  
  scene_update_camera (&rect_scene);
  
  guOrtho (ortho, -1, 1, -1, 1, 1, 15);
  
  object_loc_initialise (&rect_loc, GX_PNMTX0);
  
  guMtxIdentity (mvtmp);
  
  object_set_matrices (&rect_scene, &rect_loc, rect_scene.camera, mvtmp, NULL,
		       ortho, GX_ORTHOGRAPHIC);
  
  GX_ClearVtxDesc ();
  GX_SetVtxDesc (GX_VA_POS, GX_DIRECT);
  GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
  
  GX_SetVtxAttrFmt (vtxfmt, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
  GX_SetVtxAttrFmt (vtxfmt, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
  
  GX_SetCullMode (GX_CULL_BACK);
  
  rendertarget_texture (cubemap->sphsize, cubemap->sphsize, cubemap->sphfmt,
			GX_FALSE, GX_PF_RGB8_Z24, GX_ZC_LINEAR);
  
  for (face = 0; face < 6; face++)
    {
      shader_load (cubemap->face_shader[face]);

      for (x = -half_subdiv; x < half_subdiv - 1; x++)
	{
          float a = ((float) x + 0.5) * scale_factor;
          float a1 = ((float) x + 1.5) * scale_factor;

	  GX_Begin (GX_TRIANGLESTRIP, vtxfmt, subdiv * 2);

	  for (y = -half_subdiv; y < half_subdiv; y++)
	    {
	      float b = ((float) y + 0.5) * scale_factor;
	      guVector tmp;

	      face_to_sphere (&tmp, face, a, b);
	      GX_Position3f32 (tmp.x, tmp.y, tmp.z);
	      GX_TexCoord2f32 ((a + 1.0) / 2.0, (b + 1.0) / 2.0);

	      face_to_sphere (&tmp, face, a1, b);
	      GX_Position3f32 (tmp.x, tmp.y, tmp.z);
	      GX_TexCoord2f32 ((a1 + 1.0) / 2.0, (b + 1.0) / 2.0);
	    }

	  GX_End ();
	}
    }
  
  GX_CopyTex (cubemap->sphtexels, GX_TRUE);
  GX_PixModeSync ();
}
示例#28
0
void MilkdropWaveform::Draw(RenderContext &context)
{
	  WaveformMath(context);
#ifdef _WII_

#else
        glMatrixMode( GL_MODELVIEW );
		//glPushMatrix();
		glLoadIdentity();
#endif
		if(modulateAlphaByVolume) ModulateOpacityByVolume(context);
		else temp_a = a;
		MaximizeColors(context);

#ifndef _WII_
		if(dots==1) glEnable(GL_LINE_STIPPLE);
#else
        u8 format = GX_TO_ZERO;

		if(dots==1) format = GX_TO_ONE; // ??? correct ???
#endif

#ifdef _WII_
		//Thick wave drawing
		if (thick==1)   WII_SetLineWidth( (context.texsize < 512 ) ? 2 : 2*context.texsize/512,format);
		else  WII_SetLineWidth( (context.texsize < 512 ) ? 1 : context.texsize/512,format);

		//Additive wave drawing (vice overwrite)
		if (additive)GX_SetBlendMode(GX_BM_BLEND,GX_BL_SRCALPHA, GX_BL_ONE,GX_LO_CLEAR);
		else GX_SetBlendMode(GX_BM_BLEND,GX_BL_SRCALPHA, GX_BL_INVSRCALPHA,GX_LO_CLEAR);
#else
		//Thick wave drawing
		if (thick==1)  glLineWidth( (context.texsize < 512 ) ? 2 : 2*context.texsize/512);
		else glLineWidth( (context.texsize < 512 ) ? 1 : context.texsize/512);

		//Additive wave drawing (vice overwrite)
		if (additive)glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
#endif

#ifdef _WII_

        guMtxIdentity(modelview);

        guVector cubeAxis = {0, 0, 1};
		guMtxTransApply(modelview, modelview, .5, .5, 0);
		guMtxRotAxisDeg(modelview, &cubeAxis, rot);
		guMtxScaleApply(modelview,modelview,aspectScale, 1.0, 1.0);
		guMtxTransApply(modelview, modelview, -.5, -.5, 0);



		if (loop)
		  WII_VertArrays(GX_LINESTRIP,&wavearray[0][0],0,0,0,samples,2);
		else
		  WII_VertArrays(GX_LINESTRIP,&wavearray[0][0],0,0,0,samples,2);


		if (two_waves)
        {

            if (loop)
                WII_VertArrays(GX_LINESTRIP,&wavearray2[0][0],0,0,0,samples,2);
            else
                WII_VertArrays(GX_LINESTRIP,&wavearray2[0][0],0,0,0,samples,2);
        }

//		glPopMatrix();
#else
		glTranslatef(.5, .5, 0);
		glRotatef(rot, 0, 0, 1);
		glScalef(aspectScale, 1.0, 1.0);
		glTranslatef(-.5, -.5, 0);


		glEnableClientState(GL_VERTEX_ARRAY);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_COLOR_ARRAY);
		glVertexPointer(2,GL_FLOAT,0,wavearray);

		if (loop)
		  glDrawArrays(GL_LINE_LOOP,0,samples);
		else
		  glDrawArrays(GL_LINE_STRIP,0,samples);


		if (two_waves)
		  {
		    glVertexPointer(2,GL_FLOAT,0,wavearray2);
		    if (loop)
		      glDrawArrays(GL_LINE_LOOP,0,samples);
		    else
		      glDrawArrays(GL_LINE_STRIP,0,samples);
		  }


	#ifndef USE_GLES1
		if(dots==1) glDisable(GL_LINE_STIPPLE);
	#endif

		//glPopMatrix();
#endif
}
示例#29
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 )
    }
}
示例#30
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;
}