Drohne/SDK/ARDrone_SDK_2_0_1/ARDrone_SDK_2_0_1/Examples/Win32/sdk_demo/Sources/UI/directx_rendering.cpp
//-----------------------------------------------------------------------------
// Name: InitGeometry()
// Desc: Create the textures and vertex buffers
//-----------------------------------------------------------------------------
InitGeometry()
Desc: Create the textures and vertex buffers
InitGeometry () Desc : Create the textures and vertex buffers
HRESULT InitGeometry()
{
	if( FAILED( D3DXCreateTexture(g_pd3dDevice,
									TEXTURE_WIDTH,TEXTURE_HEIGHT,
									D3DX_DEFAULT,
									D3DUSAGE_DYNAMIC,
									D3DFMT_X8R8G8B8,
									D3DPOOL_DEFAULT,
									&g_pTexture)))
		{
            MessageBox( NULL, L"Could not create texture for video rendering", L"Bad news...", MB_OK );
            return E_FAIL;
        }
    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4 * 2 * sizeof( CUSTOMVERTEX ),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
    {
        return E_FAIL;
    }
    CUSTOMVERTEX* pVertices;
    if( FAILED( g_pVB->Lock( 0, 0, ( void** )&pVertices, 0 ) ) )
        return E_FAIL;
	pVertices[0].position = D3DXVECTOR3( -1.0f , 1.0 , 0.0f );
	pVertices[1].position = D3DXVECTOR3( 1.0f , 1.0 , 0.0f );
	pVertices[2].position = D3DXVECTOR3( -1.0 , -1.0f , 0.0f );
	pVertices[3].position = D3DXVECTOR3( 1.0f , -1.0f , 0.0f );
	for(int i=0;i<4;i++) { pVertices[i].color=0xffffffff; }
	float scaleFactorW = (float)(videoWidth) /(float)(TEXTURE_WIDTH);
	float scaleFactorH = (float)(videoHeight)/(float)(TEXTURE_HEIGHT);
	pVertices[0].tu = 0.0f;            pVertices[0].tv = 0.0f; 
	pVertices[1].tu = scaleFactorW;    pVertices[1].tv = 0.0f; 
	pVertices[2].tu = 0.0f;            pVertices[2].tv = scaleFactorH; 
	pVertices[3].tu = scaleFactorW;    pVertices[3].tv = scaleFactorH;
    g_pVB->Unlock();
    return S_OK;
}
HRESULT InitGeometry ( ) { if ( FAILED ( D3DXCreateTexture ( g_pd3dDevice , TEXTURE_WIDTH , TEXTURE_HEIGHT , D3DX_DEFAULT , D3DUSAGE_DYNAMIC , D3DFMT_X8R8G8B8 , D3DPOOL_DEFAULT , & g_pTexture ) ) ) { MessageBox ( NULL , L" " , L" " , MB_OK ) ; return E_FAIL ; } if ( FAILED ( g_pd3dDevice -> CreateVertexBuffer ( 4 * 2 * sizeof ( CUSTOMVERTEX ) , 0 , D3DFVF_CUSTOMVERTEX , D3DPOOL_DEFAULT , & g_pVB , NULL ) ) ) { return E_FAIL ; } CUSTOMVERTEX * pVertices ; if ( FAILED ( g_pVB -> Lock ( 0 , 0 , ( void * * ) & pVertices , 0 ) ) ) return E_FAIL ; pVertices [ 0 ] . position = D3DXVECTOR3 ( -1.0f , 1.0 , 0.0f ) ; pVertices [ 1 ] . position = D3DXVECTOR3 ( 1.0f , 1.0 , 0.0f ) ; pVertices [ 2 ] . position = D3DXVECTOR3 ( -1.0 , -1.0f , 0.0f ) ; pVertices [ 3 ] . position = D3DXVECTOR3 ( 1.0f , -1.0f , 0.0f ) ; for ( int i = 0 ; i < 4 ; i ++ ) { pVertices [ i ] . color = 0xffffffff ; } float scaleFactorW = ( float ) ( videoWidth ) / ( float ) ( TEXTURE_WIDTH ) ; float scaleFactorH = ( float ) ( videoHeight ) / ( float ) ( TEXTURE_HEIGHT ) ; pVertices [ 0 ] . tu = 0.0f ; pVertices [ 0 ] . tv = 0.0f ; pVertices [ 1 ] . tu = scaleFactorW ; pVertices [ 1 ] . tv = 0.0f ; pVertices [ 2 ] . tu = 0.0f ; pVertices [ 2 ] . tv = scaleFactorH ; pVertices [ 3 ] . tu = scaleFactorW ; pVertices [ 3 ] . tv = scaleFactorH ; g_pVB -> Unlock ( ) ; return S_OK ; }
Name: InitGeometry()
Desc: Create the textures and vertex buffers
Name : InitGeometry () Desc : Create the textures and vertex buffers
// Create the vertex buffer. // Fill the vertex buffer. We are setting the tu and tv texture // coordinates, which range from 0.0 to 1.0 // Create four points coordinates to form a quad