RsRenderTarget *RsUtil::GetNewRenderTarget()
{
    // Create a new render target
    RsRenderTarget *pRenderTarget = RsImpl::pInstance()->GetNewRenderTarget();

    // Make sure any new render target is set to the default back buffer
    pRenderTarget->SetTexture( BtNull );

    // Return the render target
    return pRenderTarget;
}
void SbPaint::SetupRenderToTexture()
{
	// Make a new render target
	RsRenderTarget *pRenderTarget = RsUtil::GetNewRenderTarget();

	// Set the render target name
	pRenderTarget->SetName( "painting" );

	// Make a new render target
	RsCamera camera( (BtFloat)m_width, (BtFloat)m_height, 0.01f, 10000.0f, RsViewport(0, 0, m_width, m_height) );

	// Update the camera
	camera.Update();

	// Set the texture
    RsTexture *pTexture = m_pRenderTarget->GetTexture(0);
    pRenderTarget->SetTexture( pTexture );

	// Set the camera
	pRenderTarget->SetCamera(camera);

	// Clear the render target
	if( m_isClear )
	{
		m_isClear = BtFalse;
	
		pRenderTarget->SetCleared( BtTrue );
	}
	else
	{
		pRenderTarget->SetCleared( BtFalse );
	}

	// Clear the z buffer
	pRenderTarget->SetZCleared( BtFalse );

	// Clear the screen to black
	pRenderTarget->SetClearColour( RsColour::WhiteColour() );
	
	// Apply this render target
	pRenderTarget->Apply();
}
void RsTextureWinGL::Render( RsTextureRenderable *pRenderable )
{
	// Cache the current render target
	RsRenderTarget *pRenderTarget = pRenderable->m_pRenderTarget;

	// Set the shader
	RsShaderWinGL *pShader = (RsShaderWinGL*)pRenderable->m_pShader;

	RsPrimitiveWinGL* pPrimitives = (RsPrimitiveWinGL*) pRenderable->m_primitive;

	if( pPrimitives->m_primitiveType == 1 )
	{
		int a=0;
		a++;
	}

	// Cache the camera
	const RsCamera &camera = pRenderTarget->GetCamera();

	const MtMatrix4& m4Projection = camera.GetViewProjection();
	const MtMatrix4& m4World      = MtMatrix4::m_identity;
	MtMatrix4 m4WorldViewScreen   = m4World * m4Projection;

	pShader->SetCamera( camera );
	pShader->SetTechnique( "RsShaderT2" );
	pShader->SetMatrix( RsHandles_WorldViewScreen, m4WorldViewScreen );

	for( BtU32 i=0; i<7; i++ )
	{
		glDisableVertexAttribArray( i );
	}

	// Cache the texture
	RsTextureWinGL* pTexture = (RsTextureWinGL*)pRenderable->m_pTexture;

	// Set the texture
	pTexture->SetTexture();

	// Set vertex arrays
	BtU32 stride = sizeof(RsVertex3);

	// Cache the vertex buffer
	BtU32 vertexBuffer = RsImplWinGL::GetVertexBuffer();

	// Get the size
	BtU32 dataSize = pPrimitives->m_numVertex * stride;

	// bind VBO in order to use
	glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer );
	
	GLenum error;
	error = glGetError();
	(void)error;

	// upload data to VBO
	glBufferData(GL_ARRAY_BUFFER, dataSize, pRenderable->m_pVertex, GL_DYNAMIC_DRAW);
	error = glGetError();
	(void)error;

	/*
	struct RsVertex3
	{
	MtVector3		m_v3Position;
	MtVector3		m_v3Normal;
	BtU32			m_colour;
	MtVector2		m_v2UV;
	MtVector2		m_v2UV2;
	};
	*/

	BtU32 offset = 0;
	
	glEnableVertexAttribArray( 0 );
	glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, stride, GL_BUFFER_OFFSET( offset ) );
	offset += sizeof( MtVector3 );

	glEnableVertexAttribArray( 1 );
	glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, stride, GL_BUFFER_OFFSET( offset ) );
	offset += sizeof( MtVector3 );

	glEnableVertexAttribArray( 4 );
	glVertexAttribPointer( 4, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, GL_BUFFER_OFFSET( offset ) );
	offset += sizeof( BtU32 );

	glEnableVertexAttribArray( 5);
	glVertexAttribPointer( 5, 2, GL_FLOAT, GL_FALSE, stride,  GL_BUFFER_OFFSET( offset ) );
	offset += sizeof( MtVector2 );

	// Draw the primitives
	pShader->Draw( pRenderable->m_primitive );
}
void RsTextureWinGL::Render( const MtVector2& v2Position,
							 const MtVector2& v2Dimension,
							 RsColour colour,
							 BtU32 sortOrder )
{
	// Cache the impl
	RsImplWinGL *pImpl = (RsImplWinGL*)RsImpl::pInstance();

	// Cache the render target
	RsRenderTarget *pRenderTarget = RsRenderTarget::GetCurrent();

	// Cache the camera
	RsCamera camera = pRenderTarget->GetCamera();

	// Cache the display width and height
	BtFloat Width  = (BtFloat)camera.GetViewport().m_width;
	BtFloat Height = (BtFloat)camera.GetViewport().m_height;

	// Cache the display width and height
	BtFloat fScaleWidth  = 1.0f / Width;
	BtFloat fScaleHeight = 1.0f / Height;

	// Allocate vertex
	RsVertex3 *pStartVertex = pImpl->StartVertex();

	// Set the start vertex
	RsVertex3 *pVertex = pStartVertex;

	// Cache the texture width and height
	BtFloat fTextureWidth  = m_pMipmaps[0].m_nWidth;
	BtFloat fTextureHeight = m_pMipmaps[0].m_nHeight;

	// Calculate the texture scalars
	BtFloat fScalarX = 1.0f / fTextureWidth;
	BtFloat fScalarY = 1.0f / fTextureHeight;

	BtFloat minU = fScalarX / 2;
	BtFloat minV = fScalarY / 2;

	BtFloat maxU = ( m_pMipmaps[0].m_originalWidth * fScalarX )  - minU;
	BtFloat maxV = ( m_pMipmaps[0].m_originalHeight * fScalarY ) - minV;

	// Calculate the positions
	BtFloat xmin = v2Position.x;
	BtFloat xmax = v2Position.x + v2Dimension.x;
	BtFloat ymin = v2Position.y;
	BtFloat ymax = v2Position.y + v2Dimension.y;

	RsVertex3 *pQuad = pVertex;

	// Copy these into vertex
	pVertex->m_v3Position = MtVector3(xmin, ymin, 0.1f );
	pVertex->m_v2UV = MtVector2( minU, minV );
	++pVertex;

	pVertex->m_v3Position = MtVector3(xmin, ymax, 0.1f );
	pVertex->m_v2UV = MtVector2( minU, maxV );
	++pVertex;

	pVertex->m_v3Position = MtVector3(xmax, ymin, 0.1f );
	pVertex->m_v2UV = MtVector2( maxU, minV );
	++pVertex;

	pVertex->m_v3Position = MtVector3(xmax, ymax, 0.1f );
	pVertex->m_v2UV = MtVector2( maxU, maxV );
	++pVertex;

	// Scale the position to local screen space -1 to 1
	for( BtU32 i=0; i<4; i++ )
	{
		// Set the colour
		pQuad[ i ].m_colour = colour.asARGB();

		// Flip the y
		pQuad[ i ].m_v3Position.y = Height - pQuad[ i ].m_v3Position.y;

		// Scale from 0..width to 0..1
		pQuad[ i ].m_v3Position.x *= fScaleWidth;
		pQuad[ i ].m_v3Position.y *= fScaleHeight;

		// Scale from 0..1 to 0..2
		pQuad[ i ].m_v3Position.x *= 2.0f;
		pQuad[ i ].m_v3Position.y *= 2.0f;

		// Translate from 0..2 to -1..1
		pQuad[ i ].m_v3Position.x -= 1.0f;
		pQuad[ i ].m_v3Position.y -= 1.0f;
	}

	// Setup the primitive
	RsPrimitiveWinGL *pPrimitive = pImpl->AddPrimitive();
	pPrimitive->m_primitiveType = GL_TRIANGLE_STRIP;
	pPrimitive->m_numVertex	    = 4;
	pPrimitive->m_nStartVertex  = pImpl->GetCurrentVertex();

	// End the current vertex
	pImpl->EndVertex( 4 );

	// Make a new font renderable
	RsTextureRenderable *pTextureRenderable = pImpl->AddTexture();
	pTextureRenderable->m_pTexture  = this;
	pTextureRenderable->m_pVertex   = pStartVertex;
	pTextureRenderable->m_primitive = pPrimitive;

	// Validate the shader
	BtAssert( pTextureRenderable->m_pShader != BtNull );

	// Add the font to the renderable list
	RsRenderTargetWinGL *pCurrentRenderTarget = (RsRenderTargetWinGL*)RsRenderTarget::GetCurrent();
	pCurrentRenderTarget->Add( sortOrder, pTextureRenderable );
}
Beispiel #5
0
void SgMeshWinGL::Render( SgMeshRenderable *pRenderable )
{
	RsSceneWinGL* pScene = (RsSceneWinGL*)m_pNode->m_pFileData->m_pScene;

	// Cache each material block
	BaMaterialBlockFileData* pMaterialBlock = pRenderable->m_pMaterialBlock;

	// Cache the material
	RsMaterialWinGL* pMaterial = (RsMaterialWinGL*) pMaterialBlock->m_pMaterial;

	// Set the vertex buffer
	pScene->pVertexBuffer( pMaterial->GetVertexType() )->SetStream();

	// Set the index stream
	pScene->pIndexBuffer()->SetIndices();

	// Cache the effect
	RsShaderWinGL* pShader = (RsShaderWinGL*)pRenderable->m_pShader;

	// Render the blend shape
	if( m_pNode->pBlendShape() != BtNull )
	{
		SgBlendShapeImpl* pBlendShape = (SgBlendShapeImpl*)  m_pNode->pBlendShape();
		(void)pBlendShape;
	}

	// Cache the current render target
	RsRenderTarget* pRenderTarget = pRenderable->m_pRenderTarget;

	// Cache the camera
	const RsCamera &camera = pRenderTarget->GetCamera();

	const MtMatrix4 &m4ViewScreen = pRenderTarget->GetCamera().GetViewProjection();
	const MtMatrix4 &m4World      = m_pNode->m_pFileData->m_m4World;
	const MtMatrix4 &m4View	      = camera.GetView();
	MtMatrix4 m4WorldViewScreen   = m4World * m4ViewScreen;
	MtMatrix4 m4WorldView		  = m4World * m4View;

	// Cache the technique
	const BtChar* pTechnique = pMaterial->GetTechniqueName();

	if(strstr(pTechnique, "Projected"))
	{
		int a = 0;
		a++;
	}
	if( strstr( pTechnique, "RsShaderZLT" ) )
	{
		int a=0;
		a++;
	}

	// Set the technique
	pShader->SetTechnique( pTechnique );
	pShader->SetMatrix( RsHandles_WorldViewScreen, m4WorldViewScreen );
	pShader->SetMatrix( RsHandles_WorldViewInverseTranspose, m4WorldView.GetInverse().GetTranspose() );
	pShader->SetMatrix( RsHandles_ViewInverseTranspose, m4View.GetInverse().GetTranspose() );
	pShader->SetMatrix( RsHandles_World, m4World );
	pShader->SetMaterial(pMaterial);
	
	// Ensure we have a material
	BtAssert( pMaterial != BtNull );

	// Loop through the materials
	for( BtU32 nRenderBlock=pMaterialBlock->m_nStartRenderBlock; nRenderBlock<pMaterialBlock->m_nEndRenderBlock; nRenderBlock++ )
	{
		// Cache each render block
		BaRenderBlockFileData* pRenderBlock = pScene->pRenderBlock( nRenderBlock );

		// Loop through the materials
		for( BtU32 nPrimitiveBlock=pRenderBlock->m_nStartPrimitiveBlock; nPrimitiveBlock<pRenderBlock->m_nEndPrimitiveBlock; nPrimitiveBlock++ )
		{
			// Cache each primitive block
			RsIndexedPrimitiveWinGL* pPrimitiveBlock = pScene->pPrimitiveBlock( nPrimitiveBlock );

			// Draw the primitives using the effect
			pShader->Draw( pPrimitiveBlock );
		}
	}
}
Beispiel #6
0
// virtual
MtVector2 RsFontWin32GL::Render( const MtVector2& v2StartPosition,
							     const MtVector2& v2Scale,
							     const RsColour &colour,
							     const BtChar* szText,
							     BtU32 sortOrder )
{
	const BtU32 MaxFontLength = 256;

	MtVector2 v2LastPosition = MtVector2( 0, 0 );

	// Cache the impl
	RsImplWinGL *pImpl = (RsImplWinGL*)RsImpl::pInstance();

	// Cache the render target
	RsRenderTarget *pRenderTarget = RsRenderTarget::GetCurrent();

	// Cache the camera
	RsCamera camera = pRenderTarget->GetCamera();

	// Cache the display width and height
	BtFloat Width  = (BtFloat)camera.GetViewport().m_width;
	BtFloat Height = (BtFloat)camera.GetViewport().m_height;

	// Cache the display width and height
	BtFloat fScaleWidth  = 1.0f / Width;
	BtFloat fScaleHeight = 1.0f / Height;

	// Allocate vertex
	RsVertex3 *pStartVertex = pImpl->StartVertex();

	// Set the start vertex
	RsVertex3 *pVertex = pStartVertex;

	// Cache the texture
	RsTextureWinGL* pTexture = (RsTextureWinGL*) m_pTextures[ 0 ];

	// Set the start position
	MtVector2 v2Position = v2StartPosition;

	// Cache the string length
	BtU32 length = strlen(szText);

	// Cache the texture width and height
	BtFloat TextureWidth  = 1.0f / (BtFloat) pTexture->GetWidth();
	BtFloat TextureHeight = 1.0f / (BtFloat) pTexture->GetHeight();

	BtU32 currentVertex = 0;

	// Loop through the string
	for( BtU32 nCharacterIndex=0; nCharacterIndex<length; nCharacterIndex++ )
	{
		// Cache each character
		BtUChar Character = szText[nCharacterIndex];

		if( Character == '\n' )
		{
			// Cache the font character
			LBaFontChar& fontChar = m_pFileData->m_characters['A'];	
			v2Position.x = v2StartPosition.x;
			v2Position.y += fontChar.m_fHeight * 1.50f * v2Scale.y;
			continue;
		}

		// Cache the font character
		LBaFontChar& fontChar = m_pFileData->m_characters[Character];

		// Set the dimension from the width and height of the texture
		MtVector2 v2Dimension = MtVector2( fontChar.m_fWidth, fontChar.m_fHeight );

		// Calculate the positions
		BtFloat fX0 = v2Position.x;
		BtFloat fX1 = fX0 + ( v2Dimension.x * v2Scale.x );
		BtFloat fY0 = v2Position.y + ( fontChar.m_nYOffset * v2Scale.y );
		BtFloat fY1 = fY0 + ( v2Dimension.y * v2Scale.y );

		RsVertex3 *pQuad = pVertex;

		// Copy these into vertex
		pVertex->m_v3Position = MtVector3(fX0, fY0, 0.1f );
		pVertex->m_v2UV = MtVector2( fontChar.m_U0 , fontChar.m_V0 );
		++pVertex;

		pVertex->m_v3Position = MtVector3(fX0, fY1, 0.1f );
		pVertex->m_v2UV = MtVector2( fontChar.m_U0, fontChar.m_V1 + 1 );
		++pVertex;

		pVertex->m_v3Position = MtVector3(fX1, fY0, 0.1f );
		pVertex->m_v2UV = MtVector2( fontChar.m_U1 + 1, fontChar.m_V0  );
		++pVertex;

		pVertex->m_v3Position = MtVector3(fX0, fY1, 0.1f );
		pVertex->m_v2UV = MtVector2( fontChar.m_U0 , fontChar.m_V1 + 1 );
		++pVertex;

		pVertex->m_v3Position = MtVector3(fX1, fY1, 0.1f );
		pVertex->m_v2UV = MtVector2( fontChar.m_U1 + 1, fontChar.m_V1 + 1 );
		++pVertex;

		pVertex->m_v3Position = MtVector3(fX1, fY0, 0.1f );
		pVertex->m_v2UV = MtVector2( fontChar.m_U1 + 1, fontChar.m_V0 );
		++pVertex;

		// Scale the position to local screen space -1 to 1
		for( BtU32 i=0; i<6; i++ )
		{
			// Set the colour
			pQuad[ i ].m_colour = colour.asWord();

			// Scale the uvs
			pQuad[ i ].m_v2UV.x *= TextureWidth;
			pQuad[ i ].m_v2UV.y *= TextureHeight;

			// Flip the y
			pQuad[ i ].m_v3Position.y = Height - pQuad[ i ].m_v3Position.y;

			pQuad[ i ].m_v3Position.x -= 0.5f;
			pQuad[ i ].m_v3Position.y -= 0.5f;

			// Scale from 0..width to 0..1
			pQuad[ i ].m_v3Position.x *= fScaleWidth;
			pQuad[ i ].m_v3Position.y *= fScaleHeight;

			// Scale from 0..1 to 0..2
			pQuad[ i ].m_v3Position.x *= 2.0f;
			pQuad[ i ].m_v3Position.y *= 2.0f;

			// Translate from 0..2 to -1..1
			pQuad[ i ].m_v3Position.x -= 1.0f;
			pQuad[ i ].m_v3Position.y -= 1.0f;
		}

		// Render the 6 new vertex

		// Increment the last position
		v2LastPosition.x = MtMax( v2LastPosition.x, v2Position.x + v2Dimension.x );
		v2LastPosition.y = MtMax( v2LastPosition.y, v2Position.y + v2Dimension.y );

		// Increment the position
		v2Position.x += ( fontChar.m_nXAdvance * v2Scale.x );

		currentVertex += 6;
	}

	// Setup the primitive
	RsPrimitiveWinGL *pPrimitive = pImpl->AddPrimitive();
	pPrimitive->m_primitiveType = GL_TRIANGLES;
	pPrimitive->m_numVertex	    = currentVertex;
	pPrimitive->m_nStartVertex  = pImpl->GetCurrentVertex();

	// End the current vertex
	pImpl->EndVertex( currentVertex );

	// Make a new font renderable
	RsFontRenderable *pFontRenderable = pImpl->AddFont();
	pFontRenderable->m_pFont = this;
	pFontRenderable->m_pVertex = pStartVertex;
	pFontRenderable->m_primitive = pPrimitive;

	// Validate the shader
	BtAssert( pFontRenderable->m_pShader != BtNull );

	// Add the font to the renderable list
	RsRenderTargetWinGL *pCurrentRenderTarget = (RsRenderTargetWinGL*)RsRenderTarget::GetCurrent();
	pCurrentRenderTarget->Add( sortOrder, pFontRenderable );

	// Calculate the dimension
	MtVector2 v2Dimension = v2LastPosition - v2StartPosition;

	// Return the dimension
	return v2Dimension;
}
// virtual
void RsFlashWinGL::Render( const MtVector2& v2StartPosition, BtU32 sortOrder )
{
	MtVector2 v2Dimension( 0, 0 );

	RsTexture *pTexture = BtNull;

	cJSON *pFames = cJSON_GetObjectItem( m_pJSON, "frames" );

	cJSON *pCommands = cJSON_GetArrayItem( pFames, m_currentFrame );

	if( pCommands == BtNull )
	{
		m_currentFrameTime = 0;
		
		m_currentFrame = 0;

		pCommands = cJSON_GetArrayItem( pFames, m_currentFrame );
	}

	RsColour colour( 1.0f, 1.0f, 1.0f, 1.0f );

	BtU32 numCommands = cJSON_GetArraySize( pCommands );

	for( BtU32 command=0; command<numCommands; command=command + 2 )
	{
		// Cache the command
		cJSON *pCommand = cJSON_GetArrayItem( pCommands, command );
		BtChar *pCommandString = pCommand->valuestring;

		// Cache the object
		cJSON *pObject = cJSON_GetArrayItem( pCommands, command + 1 );

		if( BtStrCompare( pCommandString, "frameInfo" ) )
		{
			cJSON *pFrameIndex = cJSON_GetObjectItem( pObject, "frameIndex" );

			BtU32 frameIndex = pFrameIndex->valueint;
			(void)frameIndex;

			int a=0;
			a++;
		}
		else if( BtStrCompare( pCommandString, "texture" ) )
		{
			cJSON *pTextureIndex = cJSON_GetObjectItem( pObject, "textureIndex" );

			// Get the texture index
			BtU32 textureIndex = pTextureIndex->valueint - 1;

			pTexture = m_pFileData->m_pTextures[textureIndex];

			colour = RsColour( 1.0f, 1.0f, 1.0f, 1.0f );
		}
		else if( BtStrCompare( pCommandString, "colour" ) )
		{
			// Get the colour object
			cJSON *pColour = cJSON_GetObjectItem( pObject, "colourArray" );

			cJSON *pR = cJSON_GetArrayItem( pColour, 0 );
			BtFloat r = (BtFloat)pR->valuedouble;

			cJSON *pG = cJSON_GetArrayItem( pColour, 1 );
			BtFloat g = (BtFloat)pG->valuedouble;

			cJSON *pB = cJSON_GetArrayItem( pColour, 2 );
			BtFloat b = (BtFloat) pB->valuedouble;

			colour = RsColour( r, g, b, 1.0f );
		}
		else if( BtStrCompare( pCommandString, "vertex" ) )
		{
			// Get the vertex object
			cJSON *pVertex = cJSON_GetObjectItem( pObject, "vertex" );

			// Cache the number of vertex
			BtU32 numVertex = cJSON_GetArraySize( pVertex );

			// Extract the vertex
			MtVector2 coords[4];

			for( BtU32 vertexIndex=0; vertexIndex<numVertex; vertexIndex++ )
			{
				// Cache each set of coordinates
				cJSON *pCoordinates = cJSON_GetArrayItem( pVertex, vertexIndex );

				cJSON *pX = cJSON_GetObjectItem( pCoordinates, "positionx" );
				cJSON *pY = cJSON_GetObjectItem( pCoordinates, "positiony" );

				coords[vertexIndex].x = (BtFloat)pX->valueint / 20;
				coords[vertexIndex].y = (BtFloat)pY->valueint / 20;
			}

			{
				// Cache the impl
				RsImplWinGL *pImpl = (RsImplWinGL*)RsImpl::pInstance();

				// Cache the render target
				RsRenderTarget *pRenderTarget = RsRenderTarget::GetCurrent();

				// Cache the camera
				RsCamera camera = pRenderTarget->GetCamera();

				// Cache the display width and height
				BtFloat Width  = (BtFloat)camera.GetViewport().m_width;
				BtFloat Height = (BtFloat)camera.GetViewport().m_height;

				// Cache the display width and height
				BtFloat textureWidth  = (BtFloat)pTexture->GetWidth();
				BtFloat textureHeight = (BtFloat)pTexture->GetHeight();

				// Cache the display width and height
				BtFloat fScaleWidth  = 1.0f / Width;
				BtFloat fScaleHeight = 1.0f / Height;

				// Allocate vertex
				RsVertex3 *pStartVertex = pImpl->StartVertex();

				// Set the start vertex
				RsVertex3 *pVertex = pStartVertex;

				RsVertex3 *pQuad = pVertex;

				BtFloat minU = 1.0f / textureWidth;
				BtFloat minV = 1.0f / textureHeight;
				BtFloat maxU = 1.0f - minU;
				BtFloat maxV = 1.0f - minV;

				/*
				coords[0].y = Height - coords[0].y;
				coords[1].y = Height - coords[1].y;
				coords[2].y = Height - coords[2].y;
				coords[3].y = Height - coords[3].y;
				*/

				// Copy these into vertex
				pVertex->m_v3Position = MtVector3(coords[0].x, coords[0].y, 0.1f );
				pVertex->m_v2UV = MtVector2( minU, minV );
				++pVertex;

				pVertex->m_v3Position = MtVector3(coords[1].x, coords[1].y, 0.1f );
				pVertex->m_v2UV = MtVector2( maxU, minV );
				++pVertex;

				pVertex->m_v3Position = MtVector3(coords[2].x, coords[2].y, 0.1f );
				pVertex->m_v2UV = MtVector2( minU, maxV );
				++pVertex;

				pVertex->m_v3Position = MtVector3(coords[3].x, coords[3].y, 0.1f );
				pVertex->m_v2UV = MtVector2( maxU, maxV );
				++pVertex;

				v2Dimension.x = MtMax( v2Dimension.x, coords[1].x - coords[0].x );
				v2Dimension.y = MtMax( v2Dimension.y, coords[2].y - coords[0].y );

				// Scale the position to local screen space -1 to 1
				for( BtU32 i=0; i<4; i++ )
				{
					// Set the colour
					pQuad[ i ].m_colour = colour.asARGB();

					// Use the start position
					pQuad[ i ].m_v3Position.x += v2StartPosition.x;
					pQuad[ i ].m_v3Position.y += v2StartPosition.y;

					// Flip the y
					pQuad[ i ].m_v3Position.y = Height - pQuad[ i ].m_v3Position.y;

					pQuad[ i ].m_v3Position.x -= 0.5f;
					pQuad[ i ].m_v3Position.y -= 0.5f;

					// Scale from 0..width to 0..1
					pQuad[ i ].m_v3Position.x *= fScaleWidth;
					pQuad[ i ].m_v3Position.y *= fScaleHeight;

					// Scale from 0..1 to 0..2
					pQuad[ i ].m_v3Position.x *= 2.0f;
					pQuad[ i ].m_v3Position.y *= 2.0f;

					// Translate from 0..2 to -1..1
					pQuad[ i ].m_v3Position.x -= 1.0f;
					pQuad[ i ].m_v3Position.y -= 1.0f;
				}

				// Setup the primitive
				RsPrimitiveWinGL *primitive = pImpl->AddPrimitive();
				primitive->m_primitiveType = GL_TRIANGLE_STRIP;
				primitive->m_numVertex     = 4;
				primitive->m_nStartVertex  = pImpl->GetCurrentVertex();

				// End the current vertex
				pImpl->EndVertex( 4 );

				// Make a new font renderable
				RsTextureRenderable *pTextureRenderable = pImpl->AddTexture();
				pTextureRenderable->m_pTexture  = (RsTextureWinGL*)pTexture;
				pTextureRenderable->m_pVertex   = pStartVertex;
				pTextureRenderable->m_primitive = primitive;

				// Validate the shader
				BtAssert( pTextureRenderable->m_pShader != BtNull );

				// Add the font to the renderable list
				RsRenderTargetWinGL *pCurrentRenderTarget = (RsRenderTargetWinGL*)RsRenderTarget::GetCurrent();
				pCurrentRenderTarget->Add( sortOrder, pTextureRenderable );
			}
		}
	}	

	(void)v2Dimension;
	int a=0;
	a++;
}
void RsMaterialWinGL::Render( RsPrimitiveType primitiveType, RsVertex2 *pVertex, BtU32 vertexCount, BtU32 sortOrder )
{
	// Cache the impl
	RsImplWinGL *pImpl = (RsImplWinGL*)RsImpl::pInstance();

	// Setup the primitive
	RsPrimitiveWinGL *primitive = pImpl->AddPrimitive();

	primitive->m_numVertex = vertexCount;
	primitive->m_nStartVertex = pImpl->GetCurrentVertex();

	if (primitiveType == RsPT_TriangleStrip)
	{
		primitive->m_primitiveType = GL_TRIANGLE_STRIP;
	}
	else if (primitiveType == RsPT_TriangleList)
	{
		primitive->m_primitiveType = GL_TRIANGLES;
	}
	else if (primitiveType == RsPT_TriangleFan)
	{
		primitive->m_primitiveType = GL_TRIANGLE_FAN;
	}
    else if (primitiveType == RsPT_LineList)
	{
		primitive->m_primitiveType = GL_LINES;
	}
    
	// Cache the render target
	RsRenderTarget *pRenderTarget = RsRenderTarget::GetCurrent();

	// Cache the camera
	RsCamera camera = pRenderTarget->GetCamera();

	// Cache the display width and height
	BtFloat width = (BtFloat)camera.GetViewport().m_width;
	BtFloat height = (BtFloat)camera.GetViewport().m_height;

	// Cache the display width and height
	BtFloat scaleWidth = 1.0f / width;
	BtFloat scaleHeight = 1.0f / height;

	// Start the vertex
	RsVertex3 *pEngineVertex = pImpl->StartVertex();

	// Copy the vertex
	for (BtU32 i = 0; i < vertexCount; i++)
	{
		pEngineVertex[i].m_colour = pVertex[i].m_colour;

		pEngineVertex[i].m_v3Position.x = pVertex[i].m_v2Position.x;
		pEngineVertex[i].m_v3Position.y = height - pVertex[i].m_v2Position.y;
		pEngineVertex[i].m_v3Position.z = 0.1f;

		pEngineVertex[i].m_v2UV = pVertex[i].m_v2UV;

		// Scale from 0..width to 0..1
		pEngineVertex[i].m_v3Position.x *= scaleWidth;
		pEngineVertex[i].m_v3Position.y *= scaleHeight;

		// Scale from 0..1 to 0..2
		pEngineVertex[i].m_v3Position.x *= 2.0f;
		pEngineVertex[i].m_v3Position.y *= 2.0f;

		// Translate from 0..2 to -1..1
		pEngineVertex[i].m_v3Position.x -= 1.0f;
		pEngineVertex[i].m_v3Position.y -= 1.0f;
	}

	// End the vertx
	pImpl->EndVertex(vertexCount);

	// Make a new material renderable
	RsMaterialRenderable *pMaterialRenderable = pImpl->AddMaterial();
	pMaterialRenderable->m_pMaterial = this;
	pMaterialRenderable->m_pVertex = pEngineVertex;
	pMaterialRenderable->m_primitive = primitive;

	// Validate the shader
	BtAssert(pMaterialRenderable->m_pShader != BtNull);

	// Add the font to the renderable list
	RsRenderTargetWinGL *pCurrentRenderTarget = (RsRenderTargetWinGL*)RsRenderTarget::GetCurrent();
	pCurrentRenderTarget->Add(sortOrder, pMaterialRenderable);
}