Пример #1
0
void HlView::Render()
{
	if( !m_isLoaded )
	{
		return;
	}

//	if( BtStrCompare( m_lastArchiveName, m_archiveName ) == BtFalse )
//	{
//		Unload();
//		Load();
//	}

	if( UiKeyboard::pInstance()->IsPressed( ReloadMenuKey ) )
	{
		Unload();
        Load();
    }

	if( m_isBackground )
    {
		BtAssert( m_pBackgroundMaterial );

		// Render from the top left corner 0, 0 downward
        RsColour colour( RsColour::WhiteColour() );
		MtVector2 v2Position = MtVector2(0, 0);
        m_pBackgroundMaterial->Render( v2Position, m_v2RenderDimension, colour, m_backgroundSortOrder );
    }

	// Render the menu
	RenderMenu();
}
void RsTextureWinGL::WriteMemory( BtU8* pMemory, BtU32 size )
{
	// Cache the mipmap
	LBaMipMapFileData& mipMap = m_pMipmaps[0];

	BtAssert(mipMap.m_nWidth * mipMap.m_nHeight * 4 == size);

	glBindTexture(GL_TEXTURE_2D, m_texture);
	glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

	GLenum err = glGetError();
//	if (err != GL_NO_ERROR)
//		printf( "Error creating texture. glError: 0x%04X", err);

	glTexImage2D( GL_TEXTURE_2D,                    //target : usually GL_TEXTURE_2D
		0,									//level : usually left to zero
		GL_RGBA,							//internal format
		mipMap.m_nWidth,                   //image size
		mipMap.m_nHeight,
		0,									//0 : no border
		GL_BGRA,							//format : usually RGB
		GL_UNSIGNED_BYTE,					//data type : pixels are made of byte
		(GLvoid*)pMemory );                //picture datas

	err = glGetError();
//	if (err != GL_NO_ERROR)
//		printf( "Can't update texture. glError: 0x%04X", err);
}
Пример #3
0
RsMaterialRenderable *RsImplWinGL::AddMaterial()
{
	RsMaterialRenderable *pMaterialRenderable = (RsMaterialRenderable*)AllocateGraphicsMemory( sizeof( RsMaterialRenderable ) );
	pMaterialRenderable->m_pRenderTarget = RsRenderTarget::GetCurrent();
	pMaterialRenderable->m_pShader = RsShader::GetCurrent();

	BtAssert( pMaterialRenderable->m_pShader != BtNull );

	return pMaterialRenderable;
}
Пример #4
0
HlItem *HlDebug::AddNode( HlItem *pParent, BtChar *name )
{
	BtAssert(m_unlocked);
	HlItem item;
	BtStrCopy( item.m_name, 32, name );
	item.m_type = HlDebugNode;
	item.m_pParent = pParent;
	item.m_isReadOnly = BtFalse;
	return AddItem( item );
}
Пример #5
0
void RsCamera::BuildProjectionMatrix()
{
	// BuildProjectionMatrix failed as width was 0
	BtAssert( m_width != 0 );

	// BuildProjectionMatrix failed as height was 0
	BtAssert( m_height != 0 );

	// Build the projection matrix
	if( m_isPerspective == BtTrue )
	{
		// Camera aspect ratio must not be 0
		BtAssert( m_aspect != 0 );

		m_m4Projection.BuildLeftHandedProjectionMatrix( m_nearPlane, m_farPlane, m_aspect, m_fieldOfView );
	}
	else
	{
		m_m4Projection.BuildOrthographicProjectionMatrix( m_width, m_height, m_nearPlane, m_farPlane );
	}
}
void RsMaterialWinGL::Render( RsPrimitiveType primitiveType, RsVertex3 *pVertex, BtU32 vertexCount, BtU32 sortOrder, BtBool isCopy )
{
	// Cache the impl
	RsImplWinGL *pImpl = (RsImplWinGL*)RsImpl::pInstance();

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

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

	if( primitiveType == RsPT_TriangleStrip )
	{
		pPrimitive->m_primitiveType = GL_TRIANGLE_STRIP;
	}
	else if( primitiveType == RsPT_TriangleList )
	{
		pPrimitive->m_primitiveType = GL_TRIANGLES;
	}
	else if( primitiveType == RsPT_LineList )
	{
		pPrimitive->m_primitiveType = GL_LINES;
	}
	else if( primitiveType == RsPT_LineStrip )
	{
		pPrimitive->m_primitiveType = GL_LINE_STRIP;
	}
    
	// Start the vertex
	RsVertex3 *pEngineVertex = pImpl->StartVertex();

	// How much room did our vertex take
	BtU32 memsize = sizeof(RsVertex3) * vertexCount;

	// Copy the vertex
	BtMemory::Copy( pEngineVertex, pVertex, memsize );

	// 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 = pPrimitive;

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

	// Add the font to the renderable list
	RsRenderTargetWinGL *pCurrentRenderTarget = (RsRenderTargetWinGL*)RsRenderTarget::GetCurrent();
	pCurrentRenderTarget->Add( sortOrder, pMaterialRenderable );
}
Пример #7
0
void HlDebug::Reset()
{
	BtAssert( m_unlocked );

	m_items.Empty();

	HlItem item;
	BtStrCopy(item.m_name, 32, "Save" );
	item.m_type = HlDebugSave;
	item.m_pParent = BtNull;
	item.m_isReadOnly = BtFalse;
	m_items.Add(item);
}
Пример #8
0
//static
void DyWorld::Update()
{
	BtBool m_paused = ApConfig::IsPaused();// && DyImpl::IsPaused();

	BtAssert( m_pDynamicsWorld != NULL );

	BtFloat tick = m_tick * m_speed;

	if( m_paused == BtFalse )
	{
		m_pDynamicsWorld->stepSimulation( tick, m_subSteps, tick / (BtFloat) m_subSteps );
	}
	else
	{
		m_pDynamicsWorld->stepSimulation( 0, 2.0f );
	}
}
Пример #9
0
void HlMouse::Setup( BaArchive *pUtilityArchive )
{
	m_pSprite = pUtilityArchive->GetSprite("MousePointers");
	BtAssert( m_pSprite );
}
Пример #10
0
HlItem *HlDebug::AddItem(HlItem &item)
{
	BtAssert(m_unlocked);
	m_items.Add(item);
	return &m_items.GetLast();
}
Пример #11
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 );
		}
	}
}
Пример #12
0
void HlFont::Setup( BaArchive *pArchive, const BtChar *title )
{
	m_pFont = pArchive->GetFont( title );
	BtAssert(m_pFont);
}
Пример #13
0
void HlModel::MeasureSphereRecursively( MtSphere &dimSphere, SgNode* pCurrentNode )
{
	MtMatrix4 m4Translation;

	MtVector3 v3Translation = pCurrentNode->GetWorldTransform().GetTranslation();

	m4Translation.SetTranslation( v3Translation.x, v3Translation.y, v3Translation.z );

	if (pCurrentNode->pSkin() != BtNull)
	{
		
		MtSphere sphere = pCurrentNode->pSkin()->Sphere();

		BtAssert( sphere.GetRadius() );

		sphere.Transform(pCurrentNode->GetWorldTransform());
	
		if (!hasMeasured)
		{
			dimSphere = sphere;

			hasMeasured = BtTrue;
		}
		else
		{
			// Expand by the new sphere
			dimSphere.ExpandBy(sphere);
		}
	}

	if( pCurrentNode->GetMesh() != BtNull )
	{
		if( pCurrentNode->GetMesh()->GetNumMaterials() )
		{
			MtSphere sphere = pCurrentNode->GetMesh()->GetSphere();
			
			sphere.Transform( pCurrentNode->GetWorldTransform() );

			if( !hasMeasured )
			{
				dimSphere = sphere;

				hasMeasured = BtTrue;
			}
			else
			{
				// Expand by the new sphere
				dimSphere.ExpandBy( sphere );
			}
		}
	}

	// Cache the first child
	SgNode* pChild = pCurrentNode->pFirstChild();

	// Loop through the children
	while( pChild != BtNull )
	{
		MeasureSphere( dimSphere, pChild );

		// Move to the next child
		pChild = pChild->pNextSibling();
	}
}
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 );
}
Пример #15
0
// 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++;
}
Пример #16
0
void DyWorld::AddRigidBody( btRigidBody* pRigidBody )
{
	BtAssert( m_pDynamicsWorld != BtNull );

	m_pDynamicsWorld->addRigidBody( pRigidBody );
}
Пример #17
0
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);
}
Пример #18
0
// virtual
BtU32 RsMaterialWinGL::Height()
{
	RsTexture* pTexture = GetTexture(0);
	BtAssert( pTexture != BtNull );
	return pTexture->GetHeight();
}
Пример #19
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;
}
Пример #20
0
void HlView::LoadMenu()
{
	BtChar *pMenu = BtNull;
	BtU32 length = 0;

	// Empty the items
	m_items.Empty();

	m_pCurrentMenuItemSelected = BtNull;
	m_pCurrentMenuItem = BtNull;
	
	// Always load from the userdata 
	BaUserData *userData = m_archive.GetUserData( m_screenName );
	pMenu = (BtChar*)userData->GetData();
    length = userData->GetSize();

	if( ApConfig::IsDebug() )
	{
		if( ApConfig::GetDevice() == ApDevice_WIN )
		{
			// Set the filename
			BtChar filename[256];
			sprintf(filename, "%s..\\gamedata\\%s.archive\\userdata\\%s.txt",
				ApConfig::GetResourcePath(), m_archiveName, m_screenName);

			// Open the file
			FsFile file;
			file.Open(filename, eFsMode_Read);
			if(file.IsOpen())
			{
				BtU32 fileSize = file.GetSize();

				// Read the file into memory
				BtChar contents[1024 * 32];

				BtAssert(fileSize < 1024 * 32);
				length = file.GetSize();
				file.Read((BtU8*)contents, length);
				file.Close();
				*(contents + length) = '\0';
				pMenu = contents;
			}
		}
	}

	// TEST XML PARSER HERE
	tinyxml2::XMLDocument doc;
	tinyxml2::XMLError errorCode = doc.Parse( pMenu, length );

	// http://kokkachiprogramming.wordpress.com/2012/11/23/using-tinyxml2-for-xml-parsing-in-c/
	// attribute= <person sex="female">
	// element= <firstname>Anna</firstname>
	if( errorCode == tinyxml2::XML_NO_ERROR )
	{
       tinyxml2::XMLNode *pNode = doc.FirstChildElement( "MENU" );

		// Is there a child?
		while( pNode )
		{
			tinyxml2::XMLNode *pItem = pNode->FirstChildElement( "ITEM" );
	
			while( pItem )
			{
				HlMenuItems item;

				item.m_alignment = 0;

				BtStrCopy( item.m_id, 64, "unset_id" );

				// Set the default sort order
				item.m_sortOrder = MaxSortOrders-1;

				// Set the default fade
				item.m_fade = 1.0f;

				// We model menu items with a specific resolution in mind. Set this here.
				// Eventually we can pull this from the XML

				item.m_v2OriginalScreenSize = MtVector2( 800.0f, 600.0f );

				// The default for each menu item is that it doesn't matter if it's a joystick or not
				item.m_joystick = HlMenuJoystick_Any;

				item.m_joystickButtonID = JoystickButton_MAX;

				// Find the fade
				tinyxml2::XMLElement *pFade = pItem->FirstChildElement( "FADE" );
				if( pFade )
				{
					const BtChar *pFadeString = pFade->GetText();
					item.m_fade = atof( pFadeString );
				}

				// Get the joystick
				tinyxml2::XMLElement *pJoystickButton = pItem->FirstChildElement( "JOYSTICKBUTTON" );
				if( pJoystickButton )
				{
					const BtChar *pJoystickButtonString = pJoystickButton->GetText();
					if( BtStrCompareNoCase( pJoystickButtonString, "PAUSE" ) )
					{
						item.m_joystickButtonID = JoystickButton_Pause;
					}
					if( BtStrCompareNoCase( pJoystickButtonString, "A" ) )
					{
						item.m_joystickButtonID = JoystickButton_A;
					}
					else if( BtStrCompareNoCase( pJoystickButtonString, "B" ) )
					{
						item.m_joystickButtonID = JoystickButton_B;
					}
					else if( BtStrCompareNoCase( pJoystickButtonString, "Y" ) )
					{
						item.m_joystickButtonID = JoystickButton_Y;
					}
					else if( BtStrCompareNoCase( pJoystickButtonString, "X" ) )
					{
						item.m_joystickButtonID = JoystickButton_X;
					}
                    else if( BtStrCompareNoCase( pJoystickButtonString, "LEFTSHOULDER" ) )
					{
						item.m_joystickButtonID = JoystickButton_LeftShoulder;
					}
                    else if( BtStrCompareNoCase( pJoystickButtonString, "RIGHTSHOULDER" ) )
					{
						item.m_joystickButtonID = JoystickButton_RightShoulder;
					}
                    else if( BtStrCompareNoCase( pJoystickButtonString, "DPADLEFT" ) )
					{
						item.m_joystickButtonID = JoystickButton_Left;
					}
                    else if( BtStrCompareNoCase( pJoystickButtonString, "DPADRIGHT" ) )
					{
						item.m_joystickButtonID = JoystickButton_Right;
					}
				}

				// Get the screen width
				tinyxml2::XMLElement *pScreenWidth = pItem->FirstChildElement( "SCREENWIDTH" );
				if( pScreenWidth )
				{
					const BtChar *pScreenWidthString = pScreenWidth->GetText();
					item.m_v2OriginalScreenSize.x = atoi( pScreenWidthString );
				}
		
				// Get the screen height
				tinyxml2::XMLElement *pScreenHeight = pItem->FirstChildElement( "SCREENHEIGHT" );
				if( pScreenHeight )
				{
					const BtChar *pScreenWidthString = pScreenHeight->GetText();
					item.m_v2OriginalScreenSize.y = atoi( pScreenWidthString );
				}

				// Get the sprite name
				const BtChar *pSpriteName = pItem->FirstChildElement( "SPRITE" )->GetText();
				item.m_pSprite = m_archive.GetSprite( pSpriteName );

				// Get the index
                tinyxml2::XMLElement *pElement = pItem->FirstChildElement( "SORTORDER" );
                if( pElement )
                {
                    const BtChar *sortOrder = pElement->GetText();
                    if( sortOrder )
                    {
                        item.m_sortOrder = atoi(sortOrder);
                    }
                }

				// Get the index 
				const BtChar *index = pItem->FirstChildElement( "INDEX" )->GetText();
				item.m_index = atoi(index);

				// Find the sprite dimension
				item.m_v2OriginalDimension = item.m_pSprite->GetDimension( item.m_index );
							
				// Get the width
                pElement = pItem->FirstChildElement( "WIDTH" );
                if( pElement )
                {
                    const BtChar *widthstring = pElement->GetText();

                    if( widthstring )
                    {
                        item.m_v2OriginalDimension.x = atoi( widthstring );
                    }
                }
				
				// Get the height
                pElement = pItem->FirstChildElement( "HEIGHT" );
                if( pElement )
                {
                    const BtChar *heightstring = pItem->FirstChildElement( "HEIGHT" )->GetText();

                    if( heightstring )
                    {
                        item.m_v2OriginalDimension.y = atoi( heightstring );
                    }
                }
				
				// Get the x 
				const BtChar *xstring = pItem->FirstChildElement( "X" )->GetText();

				// Get the y 
				const BtChar *ystring = pItem->FirstChildElement( "Y" )->GetText();

				BtFloat x, y;

				if( atof( xstring ) == 0 )
				{
					if( BtStrCompareNoCase( xstring, "c" ) )
					{
						item.m_alignment |= HlMenuItemAlignment_HorizontalCentre;
						x = (item.m_v2OriginalScreenSize.x * 0.5f) - (item.m_v2OriginalDimension.x * 0.5f);
					}
					else if( BtStrCompareNoCase( xstring, "l" ) )
					{
						x = 0;
						item.m_alignment |= HlMenuItemAlignment_Left;
					}
					else if( BtStrCompareNoCase( xstring, "r" ) )
					{
						item.m_alignment |= HlMenuItemAlignment_Right;
						x = item.m_v2OriginalScreenSize.x - item.m_v2OriginalDimension.x;
					}
                    else
                    {
                        x = 0;
                    }
				}
				else
				{
					x = atof(xstring);
				}
		
				if (atof(ystring) == 0)
				{
                	if( BtStrCompareNoCase( ystring, "c" ) )
					{
						item.m_alignment |= HlMenuItemAlignment_VerticalCentre;
						y = (item.m_v2OriginalScreenSize.y * 0.5f) - (item.m_v2OriginalDimension.y * 0.5f);
					}
					else if ( BtStrCompareNoCase( ystring, "t") )
					{
						y = 0;
						item.m_alignment |= HlMenuItemAlignment_Top;
					}
					else if ( BtStrCompareNoCase( ystring, "b") )
					{
						y = item.m_v2OriginalScreenSize.y - item.m_v2OriginalDimension.y;
						item.m_alignment |= HlMenuItemAlignment_Bottom;
					}
                    else
                    {
                        y = 0;
                    }
				}
				else
				{
					y = atof(ystring);
				}

				// Set the final position
				item.m_v2OriginalPosition = MtVector2( x, y );

				// Refactor the position
				item.m_v2Position  = HlScreenSize::Refactor( item.m_v2OriginalScreenSize, item.m_v2OriginalPosition );

				// Refactor the size
				item.m_v2Dimension = HlScreenSize::Refactor( item.m_v2OriginalScreenSize, item.m_v2OriginalDimension );

				// Get the ID
				const BtChar *pID = pItem->FirstChildElement( "ID" )->GetText();
				BtStrCopy( item.m_id, 64, pID );

				item.m_isVisible = BtTrue;
				tinyxml2::XMLElement *pIsVisible = pItem->FirstChildElement( "VISIBLE" );
				if( pIsVisible )
				{
					const BtChar *pIsVisibleText = pIsVisible->GetText();

					if( BtStrCompareNoCase( pIsVisibleText, "TRUE" ) )
					{
						item.m_isVisible = BtTrue;
					}
					else if( BtStrCompareNoCase( pIsVisibleText, "FALSE" ) )
					{
						item.m_isVisible = BtFalse;
					}
				}

				// Get the fade when selected
				tinyxml2::XMLElement *pFadeWhenSelected = pItem->FirstChildElement( "FADEWHENSELECTED" );
				if( pFadeWhenSelected )
				{
					const BtChar *pFadeWhenSelectedString = pFadeWhenSelected->GetText();
					item.m_fadeWhenSelected = atof( pFadeWhenSelectedString );
				}
				else
				{
					item.m_fadeWhenSelected = 0.5f;
				}

				// Is this menu item selectable
				item.m_isSelectable = BtFalse;
				tinyxml2::XMLElement *pIsSlectable = pItem->FirstChildElement( "SELECTABLE" );
				if( pIsSlectable )
				{
					const BtChar *pIsSlectableText = pIsSlectable->GetText();

					if( BtStrCompareNoCase( pIsSlectableText, "TRUE" ) )
					{
						item.m_isSelectable = BtTrue;
					}
				}

				// Get whether this is joystick only
				tinyxml2::XMLElement *pJoystickOnly = pItem->FirstChildElement( "JOYSTICK" );
				if( pJoystickOnly )
				{
					const BtChar *pJoystickOnlyText = pJoystickOnly->GetText();

					if( BtStrCompareNoCase( pJoystickOnlyText, "TRUE" ) )
					{
						item.m_joystick = HlMenuJoystick_Yes;
					}
					else
					{
						item.m_joystick = HlMenuJoystick_No;
					}
				}

				// Add each item
				m_items.Add( item );

				// Move to the next child
				pItem = pItem->NextSiblingElement();
			}

			// Move to the next child
			pNode = pNode->NextSiblingElement();
		}
	}
	
	int a=0;
	a++;
}