// フレームを画面に描画します。 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()); }
void Sample2DSceneRenderer::Render() { ID2D1DeviceContext* context = m_deviceResources->GetD2DDeviceContext(); // Dash array for dashStyle D2D1_DASH_STYLE_CUSTOM float dashes[] = { 1.0f, 2.0f, 2.0f, 3.0f, 2.0f, 2.0f }; ID2D1StrokeStyle* m_stroke; m_deviceResources->GetD2DFactory()->CreateStrokeStyle( D2D1::StrokeStyleProperties( D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_ROUND, D2D1_LINE_JOIN_MITER, 10.0f, D2D1_DASH_STYLE_CUSTOM, 0.0f), dashes, ARRAYSIZE(dashes), &m_stroke ); context->BeginDraw(); //context->Clear(D2D1::ColorF(D2D1::ColorF::CornflowerBlue)); auto m_bitmapSize = m_pBitmap->GetSize(); context->DrawBitmap( m_pBitmap.Get(), D2D1::RectF(200.0f, padding, m_bitmapSize.width + 200.0f, m_bitmapSize.height + padding) ); context->DrawRectangle( D2D1::RectF(100.0f, 100.0f, 500.0f, 500.0f), m_pBlueBrush.Get(), 4.0f, m_stroke ); context->FillRectangle( D2D1::RectF(600.0f, 400.0f, 900.0f, 700.0f), m_pLinearGradientBrush.Get() ); context->DrawLine( D2D1::Point2F(200, 300), D2D1::Point2F(800, 500), m_pBlueBrush.Get(), 10.0f, m_stroke ); DX::ThrowIfFailed( context->EndDraw() ); }