Exemplo n.º 1
0
/// <summary>
/// Draws a 32 bit per pixel image of previously specified width, height, and stride to the associated hwnd
/// </summary>
/// <param name="pImage">image data in RGBX format</param>
/// <param name="cbImage">size of image data in bytes</param>
/// <returns>indicates success or failure</returns>
HRESULT ImageRenderer::Draw(BYTE* pImage, unsigned long cbImage)
{
    // incorrectly sized image data passed in
    if (cbImage < ((m_sourceHeight - 1) * m_sourceStride) + (m_sourceWidth * 4))
    {
        return E_INVALIDARG;
    }

    // create the resources for this draw device
    // they will be recreated if previously lost
    HRESULT hr = EnsureResources();

    if (FAILED(hr))
    {
        return hr;
    }
    
    // Copy the image that was passed in into the direct2d bitmap
    hr = m_pBitmap->CopyFromMemory(NULL, pImage, m_sourceStride);

    if (FAILED(hr))
    {
        return hr;
    }
       
    m_pRenderTarget->BeginDraw();
	/*
	bitmapSize = sizeof(&m_pBitmap);
	wss << bitmapSize;
	wss >> wstr;
	result = wstr.c_str();
	OutputDebugString(result);
	OutputDebugString(L"\n");
	*/
    // Draw the bitmap stretched to the size of the window
	
    m_pRenderTarget->DrawBitmap(m_pBitmap);
            
    hr = m_pRenderTarget->EndDraw();

    // Device lost, need to recreate the render target
    // We'll dispose it now and retry drawing
    if (hr == D2DERR_RECREATE_TARGET)
    {
        hr = S_OK;
        DiscardResources();
    }

    return hr;
}
Exemplo n.º 2
0
/// <summary>
/// Draws a 32 bit per pixel image of previously specified width, height, and stride to the associated hwnd
/// </summary>
/// <param name="pImage">image data in RGBX format</param>
/// <param name="cbImage">size of image data in bytes</param>
/// <param name="vBodies">vector of bodies to draw</param>
/// <returns>indicates success or failure</returns>
HRESULT ImageRenderer::Draw(BYTE* pImage, unsigned long cbImage, std::vector<Body> &vBodies)
{
    // incorrectly sized image data passed in
    if (cbImage < ((m_sourceHeight - 1) * m_sourceStride) + (m_sourceWidth * 4))
    {
        return E_INVALIDARG;
    }

    // create the resources for this draw device
    // they will be recreated if previously lost
    HRESULT hr = EnsureResources();

    if (FAILED(hr))
    {
        return hr;
    }
    
    // Copy the image that was passed in into the direct2d bitmap
    hr = m_pBitmap->CopyFromMemory(NULL, pImage, m_sourceStride);

    if (FAILED(hr))
    {
        return hr;
    }
       
    m_pRenderTarget->BeginDraw();

    // Draw the bitmap stretched to the size of the window
    m_pRenderTarget->DrawBitmap(m_pBitmap);
      
	for (unsigned int i = 0; i < vBodies.size(); i++)
	{
		if (vBodies[i].bTracked)
		{
			DrawBody(vBodies[i]);
		}
	}

    hr = m_pRenderTarget->EndDraw();

    // Device lost, need to recreate the render target
    // We'll dispose it now and retry drawing
    if (hr == D2DERR_RECREATE_TARGET)
    {
        hr = S_OK;
        DiscardResources();
    }

    return hr;
}
Exemplo n.º 3
0
HRESULT ImageRenderer::BeginDraw()
{
	HRESULT hr = EnsureResources();

	if (FAILED(hr))
	{
		return hr;
	}

	if (FAILED(hr))
	{
		return hr;
	}

	m_pRenderTarget->BeginDraw();

	return hr;
}
Exemplo n.º 4
0
/// <summary>
/// Draws a 32 bit per pixel image of previously specified width, height, and stride to the associated hwnd
/// </summary>
/// <param name="pImage">image data in RGBX format</param>
/// <param name="cbImage">size of image data in bytes</param>
/// <returns>indicates success or failure</returns>
HRESULT ImageRenderer::Draw(BYTE* pImage, unsigned long cbImage)
{
    // incorrectly sized image data passed in
    if (cbImage < ((m_sourceHeight - 1) * m_sourceStride) + (m_sourceWidth * 4))
    {
        return E_INVALIDARG;
    }

    // create the resources for this draw device
    // they will be recreated if previously lost
    HRESULT hr = EnsureResources();

    if (FAILED(hr))
    {
        return hr;
    }
    
    // Copy the image that was passed in into the direct2d bitmap
    hr = m_pBitmap->CopyFromMemory(NULL, pImage, m_sourceStride);

    if (FAILED(hr))
    {
        return hr;
    }
       
    m_pRenderTarget->BeginDraw();

    // Draw the bitmap stretched to the size of the window
    m_pRenderTarget->DrawBitmap(m_pBitmap);
    
	// ここで、EndDraw()してしまうと、Bodyが描画されないので。
    //hr = m_pRenderTarget->EndDraw();

    //// Device lost, need to recreate the render target
    //// We'll dispose it now and retry drawing
    //if (hr == D2DERR_RECREATE_TARGET)
    //{
    //    hr = S_OK;
    //    DiscardResources();
    //}

    return hr;
}
Exemplo n.º 5
0
/// <summary>
/// Draws audio panel.
/// </summary>
/// <returns>S_OK on success, otherwise failure code.</returns>
HRESULT AudioPanel::Draw()
{
    // create the resources for this draw device. They will be recreated if previously lost.
    HRESULT hr = EnsureResources();

    if ( FAILED(hr) )
    {
        return hr;
    }
    
    m_pRenderTarget->BeginDraw();
    m_pRenderTarget->SetTransform(m_RenderTargetTransform);

    m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

    // Draw energy display
    m_pRenderTarget->DrawBitmap(m_pEnergyDisplay, m_EnergyDisplayPosition);

    // Draw audio beam gauge
    m_pRenderTarget->FillGeometry(m_pBeamGauge, m_pBeamGaugeFill, NULL);
    m_pRenderTarget->SetTransform(m_BeamNeedleTransform * m_RenderTargetTransform);
    m_pRenderTarget->FillGeometry(m_pBeamNeedle, m_pBeamNeedleFill, NULL);
    m_pRenderTarget->SetTransform(m_RenderTargetTransform);

    // Draw sound source gauge
    m_pSourceGaugeFill->SetTransform(m_SourceGaugeTransform);
    m_pRenderTarget->FillGeometry(m_pSourceGauge, m_pSourceGaugeFill, NULL);

    // Draw panel outline
    m_pRenderTarget->DrawGeometry(m_pPanelOutline, m_pPanelOutlineStroke, 0.001f);
            
    hr = m_pRenderTarget->EndDraw();

    // Device lost, need to recreate the render target. We'll dispose it now and retry drawing.
    if (hr == D2DERR_RECREATE_TARGET)
    {
        hr = S_OK;
        DiscardResources();
    }

    return hr;
}
Exemplo n.º 6
0
//-------------------------------------------------------------------
// DrawFrame
//
// Draw the video frame.
//-------------------------------------------------------------------
bool DrawDevice::Draw( BYTE * pBits, unsigned long cbBits )
{
    // incorrectly sized image data passed in
    if ( cbBits < ((m_sourceHeight - 1) * m_stride) + (m_sourceWidth * 4) )
    {
        return false;
    }

    // create the resources for this draw device
    // they will be recreated if previously lost
    HRESULT hr = EnsureResources( );

    if ( FAILED( hr ) )
    {
        return false;
    }
    
    // Copy the image that was passed in into the direct2d bitmap
    hr = m_pBitmap->CopyFromMemory( NULL, pBits, m_stride );

    if ( FAILED( hr ) )
    {
        return false;
    }
       
    m_pRenderTarget->BeginDraw();

    // Draw the bitmap stretched to the size of the window
    m_pRenderTarget->DrawBitmap( m_pBitmap );
            
    hr = m_pRenderTarget->EndDraw();

    // Device lost, need to recreate the render target
    // We'll dispose it now and retry drawing
    if ( hr == D2DERR_RECREATE_TARGET )
    {
        hr = S_OK;
        DiscardResources();
    }

    return SUCCEEDED( hr );
}