Esempio n. 1
0
// フレームを画面に描画します。
void Direct2DRenderer::Render(INT16* waveBuffer,int length,ID2D1Bitmap1* targetBitmap)
{
	if (!targetBitmap) return;



	ID2D1DeviceContext* context = m_deviceResources->GetD2DDeviceContext();
	context->SetTarget(targetBitmap);
	Windows::Foundation::Size logicalSize = { (float)targetBitmap->GetPixelSize().width, (float)targetBitmap->GetPixelSize().height};//m_deviceResources->GetLogicalSize();

	context->SaveDrawingState(m_stateBlock.Get());
	context->BeginDraw();

	// 右下隅に配置
  D2D1::Matrix3x2F screenTranslation = D2D1::Matrix3x2F::Translation(
    0.0f, logicalSize.Height);
//		logicalSize.Height - m_textMetrics.layoutHeight
	//	);

  //D2D1::Matrix3x2F screenTranslation = D2D1::Matrix3x2F::Translation(0.0f,0.0f);
   screenTranslation._22 = screenTranslation._22 * -1.0f;

	context->SetTransform(screenTranslation * m_deviceResources->GetOrientationTransform2D());

	context->DrawTextLayout(
		D2D1::Point2F(0.f, 0.f),
		m_textLayout.Get(),
		m_whiteBrush.Get()
		);

  // 波形データを表示する
  const float delta = 1323.0f / VIDEO_WIDTH;
  for (float i = 0; i < VIDEO_WIDTH; i += delta){
    int pos = (int) i;
    if (pos >= length) break;
    float left = ((float) waveBuffer[pos]) / 32768.0f * 150.0f + 180.0f;
    float right = ((float) waveBuffer[pos + 1]) / 32768.0f * 150.0f + 540.0f;
    context->DrawLine(D2D1::Point2F(i, 180.0f), D2D1::Point2F(i, left), m_whiteBrush.Get());
    context->DrawLine(D2D1::Point2F(i, 540.0f), D2D1::Point2F(i, right), m_whiteBrush.Get());
  }

	// D2DERR_RECREATE_TARGET をここで無視します。このエラーは、デバイスが失われたことを示します。
	// これは、Present に対する次回の呼び出し中に処理されます。
	HRESULT hr = context->EndDraw();
	if (hr != D2DERR_RECREATE_TARGET)
	{
		DX::ThrowIfFailed(hr);
	}

	context->RestoreDrawingState(m_stateBlock.Get());
}
// Renders a frame to the screen.
void SampleFpsTextRenderer::Render()
{
	ID2D1DeviceContext* context = m_deviceResources->GetD2DDeviceContext();
	RECT windowSize = m_deviceResources->GetWindowSize();

	UINT width = windowSize.right - windowSize.left;
	UINT height = windowSize.bottom - windowSize.top;

	context->SaveDrawingState(m_stateBlock.Get());
	context->BeginDraw();

	// Position on the bottom right corner
	D2D1::Matrix3x2F screenTranslation = D2D1::Matrix3x2F::Translation(
		width - m_textMetrics.layoutWidth,
		height - m_textMetrics.height
		);

	context->SetTransform(screenTranslation);

	DX::ThrowIfFailed(
		m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING)
		);

	context->DrawTextLayout(
		D2D1::Point2F(0.f, 0.f),
		m_textLayout.Get(),
		m_whiteBrush.Get()
		);

	// Ignore D2DERR_RECREATE_TARGET here. This error indicates that the device
	// is lost. It will be handled during the next call to Present.
	HRESULT hr = context->EndDraw();
	if (hr != D2DERR_RECREATE_TARGET)
	{
		DX::ThrowIfFailed(hr);
	}

	context->RestoreDrawingState(m_stateBlock.Get());
}
Esempio n. 3
0
// 将帧呈现到屏幕。
void SampleFpsTextRenderer::Render()
{
	ID2D1DeviceContext* context = m_deviceResources->GetD2DDeviceContext();
	Windows::Foundation::Size logicalSize = m_deviceResources->GetLogicalSize();

	context->SaveDrawingState(m_stateBlock.Get());
	context->BeginDraw();

	// 定位在右下角
	D2D1::Matrix3x2F screenTranslation = D2D1::Matrix3x2F::Translation(
		logicalSize.Width - m_textMetrics.layoutWidth,
		logicalSize.Height - m_textMetrics.height
		);

	context->SetTransform(screenTranslation * m_deviceResources->GetOrientationTransform2D());

	DX::ThrowIfFailed(
		m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING)
		);

	context->DrawTextLayout(
		D2D1::Point2F(0.f, 0.f),
		m_textLayout.Get(),
		m_whiteBrush.Get()
		);

	// 此处忽略 D2DERR_RECREATE_TARGET。此错误指示该设备
	// 丢失。将在下一次调用 Present 时对其进行处理。
	HRESULT hr = context->EndDraw();
	if (hr != D2DERR_RECREATE_TARGET)
	{
		DX::ThrowIfFailed(hr);
	}

	context->RestoreDrawingState(m_stateBlock.Get());
}
// Renders a frame to the screen.
void SampleDebugTextRenderer::Render()
{
    ID2D1DeviceContext* context = m_deviceResources->GetD2DDeviceContext();
    Windows::Foundation::Size logicalSize = m_deviceResources->GetLogicalSize();

    context->SaveDrawingState(m_stateBlock.Get());
    context->BeginDraw();

    // Position the controllers in quadrants.
    for (unsigned int i = 0; i < XINPUT_MAX_CONTROLLERS; i++)
    {
        unsigned int playerAttached = (m_playersAttached & (1 << i));

        if (!playerAttached)
            continue;

        float x = logicalSize.Width;
        float y = logicalSize.Height - 50.f; // size of FPS text

        x -= (i % 2) ? m_textMetrics[i].layoutWidth : (2 * m_textMetrics[i].layoutWidth);
        y -= (i > 1) ? m_inputTextHeight : (2 * m_inputTextHeight);

        // Translate the origin (used to position in different quadrants)
        D2D1::Matrix3x2F screenTranslation = D2D1::Matrix3x2F::Translation(x, y);

        context->SetTransform(screenTranslation * m_deviceResources->GetOrientationTransform2D());

        DX::ThrowIfFailed(
            m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING)
            );

        context->DrawTextLayout(
            D2D1::Point2F(0.f, 0.f),
            m_textLayout[i].Get(),
            m_whiteBrush.Get()
            );

    }

    // Position FPS on the bottom right corner.
    D2D1::Matrix3x2F screenTranslation = D2D1::Matrix3x2F::Translation(
        logicalSize.Width - m_textMetricsFPS.layoutWidth,
        logicalSize.Height - m_textMetricsFPS.height
        );

    context->SetTransform(screenTranslation * m_deviceResources->GetOrientationTransform2D());

    DX::ThrowIfFailed(
        m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING)
        );

    context->DrawTextLayout(
        D2D1::Point2F(0.f, 0.f),
        m_textLayoutFPS.Get(),
        m_whiteBrush.Get()
        );

    // Ignore D2DERR_RECREATE_TARGET here. This error indicates that the device
    // is lost. It will be handled during the next call to Present.
    HRESULT hr = context->EndDraw();
    if (hr != D2DERR_RECREATE_TARGET)
    {
        DX::ThrowIfFailed(hr);
    }

    context->RestoreDrawingState(m_stateBlock.Get());
}