示例#1
0
	void dx11render::renderLine(const point& begin, const point& end, const color& col)
	{
		if( m_device == NULL ) return;

		UINT viewportNumber = 1;

		D3D11_VIEWPORT vp;

		m_deviceContext->RSGetViewports( &viewportNumber, &vp );

		float xx0 = 2.0f * ( begin.getX() - 0.5f ) / vp.Width - 1.0f;
		float yy0 = 1.0f - 2.0f * ( begin.getY() - 0.5f ) / vp.Height;
		float xx1 = 2.0f * ( end.getX() - 0.5f ) / vp.Width - 1.0f;
		float yy1 = 1.0f - 2.0f * ( end.getY() - 0.5f ) / vp.Height;

		COLOR_VERTEX* v = NULL;
		D3D11_MAPPED_SUBRESOURCE mapData;
		if( FAILED( m_deviceContext->Map( m_pVertexBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &mapData ) ) )
			return;

		v = ( COLOR_VERTEX* ) mapData.pData;

		v[0].Position.x = xx0;
		v[0].Position.y = yy0;
		v[0].Position.z = 0;
		v[0].Color = col.toD3DXCOLOR();

		v[1].Position.x = xx1;
		v[1].Position.y = yy1;
		v[1].Position.z = 0;
		v[1].Color = col.toD3DXCOLOR();

		m_deviceContext->Unmap( m_pVertexBuffer, NULL );
		m_deviceContext->IASetInputLayout( m_pInputLayout );

		UINT Stride = sizeof( COLOR_VERTEX );
		UINT Offset = 0;

		m_deviceContext->IASetVertexBuffers( 0, 1, &m_pVertexBuffer, &Stride, &Offset );
		m_deviceContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP );

		D3DX11_TECHNIQUE_DESC techDesc;

		if( FAILED( m_pTechnique->GetDesc( &techDesc ) ) )
		{
			return;
		}

		for( UINT p = 0; p < techDesc.Passes; ++p )
		{
			m_pTechnique->GetPassByIndex( p )->Apply( 0, m_deviceContext );
			m_deviceContext->Draw( 2, 0 );
		}
	}
示例#2
0
	void dx11render::fillGradient(const rect& r, const color& top, const color& bottom)
	{
		drawRect_(top.toD3DXCOLOR(), bottom.toD3DXCOLOR(), r.getX(), r.getY(), r.getX() + r.getW(), r.getY() + r.getH());
	}
示例#3
0
	void dx11render::fillRect(const rect& r, const color& c)
	{
		drawRect_(c.toD3DXCOLOR(), c.toD3DXCOLOR(), r.getX(), r.getY(), r.getX() + r.getW(), r.getY() + r.getH());
	}