Ok, I understand how to blit stretched images, rotated images, and pieces of images... What is the best way to blit a rotated (and possibly stretched) piece of an image?
I havn't tried this code so there may be some trivial errors (but I think it should work)
- Code:
// Blit a rotated stretched surface on the screen by
// using BlitStretch and BlitRotated (in that order)
void BlitRotatedStretch(DisplayDevice* display, int destx, int desty, float angle, const Surface* source, int stretch_xsize, int stretch_ysize, const Rect* src_rect=0)
{
// Create a new surface to hold our stretched image
Surface* stretch_surface = display->CreateSurface(stretch_xsize, stretch_ysize);
// Change rendering target from screen to our surface
Surface* screen = display->SetRenderTarget(stretch_surface);
// If the source was transparent, we need to make our new surface transparent as well
int color_mask = source->GetColorMask();
if (color_mask > -1)
{
display->Clear(color_mask);
stretch_surface->SetColorMask(color_mask);
}
// Stretch the surface
display->BlitStretch(Rect(0,0,stretch_xsize,stretch_ysize), source, src_rect);
// Change rendering target back to screen
display->SetRenderTarget(screen);
// Blit our stretched surface to screen, rotated.
display->BlitRotated(destx, desty, angle, stretch_surface);
// Don't forget to free memory
delete stretch_surface;
}
There are several reasons why I stretch first and rotate later:
1. It's much simpler this way. I might even say it's almost impossible to do it the other way around, because there is no way of knowing (beforehand) how large the rotated surface will be and therefore no way of defining a (usefull) strech effect.
2. There is no source rect in BlitRotate.
3. The (final) result will be better.
Hope someone finds this helpfull.