TemporaryRef<GradientStops> DrawTargetD2D1::CreateGradientStops(GradientStop *rawStops, uint32_t aNumStops, ExtendMode aExtendMode) const { D2D1_GRADIENT_STOP *stops = new D2D1_GRADIENT_STOP[aNumStops]; for (uint32_t i = 0; i < aNumStops; i++) { stops[i].position = rawStops[i].offset; stops[i].color = D2DColor(rawStops[i].color); } RefPtr<ID2D1GradientStopCollection> stopCollection; HRESULT hr = mDC->CreateGradientStopCollection(stops, aNumStops, D2D1_GAMMA_2_2, D2DExtend(aExtendMode), byRef(stopCollection)); delete [] stops; if (FAILED(hr)) { gfxWarning() << *this << ": Failed to create GradientStopCollection. Code: " << hr; return nullptr; } return new GradientStopsD2D(stopCollection); }
void Game::Render(void) { pRT->BeginDraw(); pRT->Clear(D2DColor(CornflowerBlue)); switch (currState) { case Playing: { // Rendering Floor Textures pRT->DrawBitmap(floor1, floor1pos); pRT->DrawBitmap(floor2, floor2pos); pRT->DrawBitmap(floor3, floor3pos); // Render Black Ninja D2D1_RECT_F sourceRect; sourceRect.top = 0; sourceRect.bottom = 74; sourceRect.left = 88.0f * black.frame + 10; sourceRect.right = sourceRect.left + 74; pRT->DrawBitmap(black.sprite, black.position, 1.0F, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, sourceRect); // Render Grey Ninja sourceRect.left = 88.0f * grey.frame + 10; sourceRect.right = sourceRect.left + 74; pRT->DrawBitmap(grey.sprite, grey.position, 1.0F, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, sourceRect); // Render Rect pBrush->SetColor(D2DColor(Black)); iter = rects.begin(); for (size_t i = 0; iter != rects.end(); iter++) { pRT->FillRectangle(*iter, pBrush); } pBrush->SetColor(D2DColor(Yellow)); obstIter = obstacles.begin(); // Render Obstacles for (; obstIter != obstacles.end(); obstIter++) { pRT->FillRectangle(obstIter->position, pBrush); } // Rendering health bar blackhealth = D2D1::RectF(healthbar2.left, healthbar2.top, healthbar2.left + 4 * black.health, healthbar2.bottom); greyhealth = D2D1::RectF(healthbar1.left, healthbar1.top, healthbar1.left + 4 * grey.health, healthbar1.bottom); pBrush->SetColor(D2DColor(Red)); pRT->FillRectangle(blackhealth, pBrush); pRT->FillRectangle(greyhealth, pBrush); pBrush->SetColor(D2DColor(Yellow)); pRT->DrawRectangle(healthbar1, pBrush); pRT->DrawRectangle(healthbar2, pBrush); break; } case Menu: { pRT->DrawBitmap(menupanel, D2D1::RectF(700, 300, 1100, 900)); break; } } HRESULT hr = pRT->EndDraw(); if (hr == D2DERR_RECREATE_TARGET) { DestroyGraphics(); CreateGraphics(hWnd); } }