示例#1
0
文件: D3DSprite.cpp 项目: nutti/MAPIL
MapilVoid D3DSprite::DrawTexture(	SharedPointer < Texture > pTexture,
                                    const Matrix4x4 < MapilFloat32 >& mat,
                                    MapilUInt32 color )
{
Assert(	m_IsUsed, CURRENT_POSITION, TSTR( "The sprite isn't created yet." ), -1 );

D3DXMATRIXA16 matWorld;
for( MapilInt32 i = 0; i < 4; ++i ) {
    for( MapilInt32 j = 0; j < 4; ++j ) {
        matWorld.m[ i ][ j ] = mat.m_Elm[ i ][ j ];
    }
}

//World coordinate transformation
m_pD3DSprite->SetTransform( &matWorld );


//Set range of drawing
RECT rc;
rc.top		= 0;
rc.bottom	= pTexture->GetSize().m_Y;
rc.left		= 0;
rc.right	= pTexture->GetSize().m_X;

//Draw
if( FAILED( m_pD3DSprite->Draw(	reinterpret_cast < LPDIRECT3DTEXTURE9 > ( pTexture.GetPointer()->Get() ),
                                &rc,
                                NULL,
                                NULL,
                                color ) ) ) {
    throw MapilException( CURRENT_POSITION, TSTR( "Failed to draw." ), -1 );
}
}
示例#2
0
文件: GLSprite.cpp 项目: nutti/MAPIL
	MapilVoid GLSprite::DrawTexture( SharedPointer < Texture > pTexture )
	{
		GLfloat texCoord[ 8 ] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f };
		GLfloat vertexCoord[ 8 ] = {	0.0f,
										0.0f,
										0.0f,
										static_cast < MapilFloat32 > ( pTexture->GetSize().m_Y ),
										static_cast < MapilFloat32 > ( pTexture->GetSize().m_X ),
										static_cast < MapilFloat32 > ( pTexture->GetSize().m_Y ),
										static_cast < MapilFloat32 > ( pTexture->GetSize().m_X ),
										0.0f };

		glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );

		// When the different texture is set, calls glBindTexture.
		MapilBool isNewTexture = (	!( m_pPrevTexture.GetPointer() ) ||
									m_pPrevTexture->Get() != pTexture->Get() );
		if( isNewTexture ){
			glBindTexture( GL_TEXTURE_2D, 0 );
			m_pPrevTexture = pTexture;
			glBindTexture( GL_TEXTURE_2D, pTexture->Get() );
		}

		glVertexPointer( 2, GL_FLOAT, 0, vertexCoord );
		glTexCoordPointer( 2, GL_FLOAT, 0, texCoord );
		glDrawArrays( GL_QUADS, 0, 4 );
	}
示例#3
0
文件: D3DSprite.cpp 项目: nutti/MAPIL
MapilVoid D3DSprite::DrawScaledTexture(	SharedPointer < Texture > pTexture,
                                        MapilFloat32 x, MapilFloat32 y, MapilFloat32 sx, MapilFloat32 sy,
                                        MapilBool centerize, MapilUInt32 color )
{
Assert(	m_IsUsed, CURRENT_POSITION, TSTR( "The sprite isn't created yet." ), -1 );

D3DXMATRIXA16 matWorld;
::D3DXMatrixIdentity( &matWorld );

//World coordinate transformation
if( centerize ) {
    //matWorld._11 = sx;
    //matWorld._11 =
    matWorld._41 = x - pTexture->GetSize().m_X / 2.0f;
    matWorld._42 = y - pTexture->GetSize().m_Y / 2.0f;
}
else {
    matWorld._41 = x;
    matWorld._42 = y;
}
m_pD3DSprite->SetTransform( &matWorld );

// Set range of drawing.
RECT rc;
rc.top		= 0;
rc.bottom	= pTexture->GetSize().m_Y;
rc.left		= 0;
rc.right	= pTexture->GetSize().m_X;

// Draw
if( FAILED( m_pD3DSprite->Draw(	reinterpret_cast < LPDIRECT3DTEXTURE9 > ( pTexture.GetPointer()->Get() ),
                                &rc,
                                NULL,
                                NULL,
                                color ) ) ) {
    throw MapilException( CURRENT_POSITION, TSTR( "Failed to draw." ), -1 );
}
}
示例#4
0
文件: D3DSprite.cpp 项目: nutti/MAPIL
// Draw texture.
MapilVoid D3DSprite::DrawTexture(	SharedPointer < Texture > pTexture,
                                    ImageTransformationMethod method,
                                    const Vector2 < MapilFloat32 >& v )
{
Assert(	m_IsUsed, CURRENT_POSITION, TSTR( "The sprite isn't created yet." ), -1 );

D3DXMATRIXA16 matWorld;

switch( method ) {
case IMAGE_TRANSFORMATION_METHOD_MOVE:				//Move
    D3DXMatrixTranslation( &matWorld, v.m_X, v.m_Y, 0.0f );
    break;
case IMAGE_TRANSFORMATION_METHOD_SCALE:			//Scale
    D3DXMatrixScaling( &matWorld, v.m_X, v.m_Y, 0.0f );
    break;
case IMAGE_TRANSFORMATION_METHOD_CENTER_MOVE:		// Center - Move
{
    D3DXMATRIXA16 matCenter;
    D3DXMatrixTranslation( &matCenter, - pTexture->GetSize().m_X / 2.0f, - pTexture->GetSize().m_Y / 2.0f, 0.0f );
    D3DXMatrixTranslation( &matWorld, v.m_X, v.m_Y, 0.0f );
    D3DXMatrixMultiply( &matWorld, &matWorld, &matCenter );
    matWorld *= matCenter;
    break;
}
case IMAGE_TRANSFORMATION_METHOD_CENTER_SCALE:		// Center - Scale
{
    D3DXMATRIXA16 matCenter;
    D3DXMatrixTranslation( &matCenter, - pTexture->GetSize().m_X / 2.0f, - pTexture->GetSize().m_Y / 2.0f, 0.0f );
    D3DXMatrixScaling( &matWorld, v.m_X, v.m_Y, 0.0f );
    D3DXMatrixMultiply( &matWorld, &matWorld, &matCenter );
    matWorld *= matCenter;
    break;
}
default:
    break;
}

//World coordinate transformation
m_pD3DSprite->SetTransform( &matWorld );

// Set range of drawing.
RECT rc;
rc.top		= 0;
rc.bottom	= pTexture->GetSize().m_Y;
rc.left		= 0;
rc.right	= pTexture->GetSize().m_X;

// Draw
if( FAILED( m_pD3DSprite->Draw(	reinterpret_cast < LPDIRECT3DTEXTURE9 > ( pTexture.GetPointer()->Get() ),
                                &rc,
                                NULL,
                                NULL,
                                D3DCOLOR_ARGB( 255, 255, 255, 255 ) ) ) ) {
    throw MapilException( CURRENT_POSITION, TSTR( "Failed to draw." ), -1 );
}
}