Пример #1
0
void CzPlatformRender::DrawPrimitives(CzRenderPrim3* prims, CzRenderMaterial* materials, int num_prims, bool single_material)
{
	while (num_prims-- > 0)
	{
		CIwMaterial::AlphaMode am = (CIwMaterial::AlphaMode)materials->AlphaMode;	// TODO Add proper method to map Marmalade Alpha mode to Marmalade
		int vc = prims->VertCount;

		// Set up vertex streams
		if (prims->UVs != NULL)
			IwGxSetUVStream((CIwFVec2*)prims->UVs, 0);
		else
			IwGxSetUVStream(NULL);
		if (prims->ModelSpace)
			IwGxSetVertStreamModelSpace((CIwFVec3*)prims->Verts, vc);
		else
			IwGxSetVertStreamViewSpace((CIwFVec3*)prims->Verts, vc);
		IwGxSetColStream((CIwColour*)prims->Colours);
		IwGxSetNormStream((CIwFVec3*)prims->Normals);

		CzTexture texture = materials->Image->getTexture();
		CIwTexture* mt = static_cast<CIwTexture*>(texture);
		bool filter;
		if (materials->Image->isFilterSet())
			filter = mt->GetFiltering();
		else
			filter = materials->Filter;

		// Only create new render material if something important has changed
		if (texture != CurrentTexture || CurrentAlphaMode != materials->AlphaMode || CurrentFilter != filter || CurrentTexture == NULL || CurrentTiled != materials->Tiled)
		{
			CIwMaterial* mat = IW_GX_ALLOC_MATERIAL();
			mat->SetTexture(mt);
			mat->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_DISABLED);
			mat->SetClamping(!materials->Tiled);
			mat->SetFiltering(filter);
			mat->SetAlphaMode(am);
			mat->SetCullMode(CIwMaterial::CULL_BACK);
//			mat->SetCullMode(CIwMaterial::CULL_NONE);
			IwGxSetMaterial(mat);
			CurrentTexture = texture;
			CurrentAlphaMode = materials->AlphaMode;
			CurrentTiled = materials->Tiled;
			CurrentFilter = filter;
		}
		else
		{
			RedundantTextureCalls++;
		}
	
		// Render the primitive
		IwGxDrawPrims(CzToIwGxPrimType[prims->Type], prims->Indices, prims->IndicesCount);

		// Move to next primitive
		prims++;
		if (!single_material)
			materials++;
	}
}
Пример #2
0
void renderImageWorldSpace(CIwFVec2& position, float angle, float scaleFactor,
                        int textureSize, float worldRot, int frameNumber, int numFrames, float z) {
	
	static CIwSVec3 vertices[4];
	static CIwSVec2 UVs[4];
	
	//set up model space vertices
	
	int vertexDist = scaleFactor*textureSize/2;
	
	vertices[0] = CIwSVec3(-1*vertexDist, -1*vertexDist, z);
	vertices[2] = CIwSVec3(vertexDist, -1*vertexDist,    z);
	vertices[3] = CIwSVec3(vertexDist, vertexDist,       z);
	vertices[1] = CIwSVec3(-1*vertexDist, vertexDist,    z);
	
	CIwMat modelTransform = CIwMat::g_Identity;
	modelTransform.SetRotZ(IW_ANGLE_FROM_RADIANS(angle));
	modelTransform.SetTrans(CIwVec3(position.x, -position.y, 0));
	    
	CIwMat rot = CIwMat::g_Identity;
 	rot.SetRotZ(IW_ANGLE_FROM_RADIANS(worldRot));
	modelTransform = modelTransform*rot;
	
	IwGxSetModelMatrix(&modelTransform, false);
	
	float frameRatio = 1.0/numFrames;
	
	//set up sprite UV's
    
    iwfixed cf = IW_FIXED((float)frameNumber  / numFrames);
    iwfixed nf = IW_FIXED((frameNumber + 1.0) / numFrames);
    
	UVs[0] = CIwSVec2(cf, 0);
	UVs[2] = CIwSVec2(nf, 0);
	UVs[3] = CIwSVec2(nf, IW_GEOM_ONE);
	UVs[1] = CIwSVec2(cf, IW_GEOM_ONE);
		
	//render the unit in model space
	IwGxSetUVStream(UVs);
	
	IwGxSetZDepthFixed(8);	
	
	IwGxSetVertStreamModelSpace(vertices, 4);
	IwGxDrawPrims(IW_GX_QUAD_STRIP, NULL, 4);
	
    IwGxFlush();
}