void D3D9RenderTargetTexture::GetData(Bitmap &B, const Rectangle2i &Source, const Rectangle2i &Dest)
{
    D3DAlwaysValidate(_Device->GetRenderTargetData(_Surface, _SurfacePlain), "GetRenderTargetData");

    if(_SurfaceResizing == NULL)
    {
        D3DAlwaysValidate(_Device->CreateOffscreenPlainSurface(_Width, _Height, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &_SurfaceResizing, NULL), "CreateOffscreenPlainSurface");
    }
    D3DAlwaysValidate(_Device->UpdateSurface(_SurfacePlain, NULL, _SurfaceResizing, NULL), "UpdateSurface");

    RECT SourceRect = Source.ToRect();
    RECT DestRect = Rectangle2i(Vec2i::Origin, Dest.Dimensions()).ToRect();
    D3DAlwaysValidate(_Device->StretchRect(_SurfaceResizing, &SourceRect, _Surface, &DestRect, D3DTEXF_LINEAR), "StretchRect");

    D3DAlwaysValidate(_Device->GetRenderTargetData(_Surface, _SurfacePlain), "GetRenderTargetData");

    D3DLOCKED_RECT LockedRect;
    D3DAlwaysValidate(_SurfacePlain->LockRect(&LockedRect, NULL, 0), "LockRect");

    Assert(int(B.Width()) >= Dest.Max.x && int(B.Height()) >= Dest.Max.y, "Bitmap too small");

    RGBColor *SurfData = (RGBColor*)LockedRect.pBits;
    for(int y = Dest.Min.y; y < Dest.Max.y; y++)
    {
        //memcpy(B[_Height - 1 - y], &SurfData[y * LockedRect.Pitch / 4], _Width * 4);
        memcpy(B[y] + Dest.Min.x, &SurfData[(y - Dest.Min.y) * LockedRect.Pitch / 4], Dest.Dimensions().x * 4);
    }

    _SurfacePlain->UnlockRect();
}
Esempio n. 2
0
void D3D9Font::DrawString(const String &Text, const Rectangle2i &Rect, RGBColor Color) const
{
    RECT CurRect = Rect.ToRect();
    HRESULT CoopLevel = _Device->TestCooperativeLevel();
    if(CoopLevel == D3D_OK)
    {
        _Font->DrawText( NULL, Text.CString(), Text.Length(), &CurRect, DT_WORDBREAK | DT_CALCRECT, 0 );
        _Font->DrawText( NULL, Text.CString(), Text.Length(), &CurRect, DT_WORDBREAK | DT_NOCLIP, D3DXCOLOR(Color.r / 255.0f, Color.g / 255.0f, Color.b / 255.0f, 1.0f ));
    }
}