mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-22 08:49:46 +01:00
Ax ScaleSurfaceSlow() in favor of ScaleSurface()
ScaleSurfaceSlow() uses DrawPixel() instead of SDL_FillRect() to scale a given surface, which is slow and inefficient, and makes it less likely that the game could be moved to SDL_Render. Unfortunately, it has this weird -1,-1 offset, but that will be fixed in the next commit.
This commit is contained in:
parent
57dca99a4e
commit
5f776faba7
3 changed files with 2 additions and 35 deletions
|
@ -424,7 +424,7 @@ void Graphics::bigprint( int _x, int _y, std::string _s, int r, int g, int b, b
|
||||||
idx = font_idx(curr);
|
idx = font_idx(curr);
|
||||||
if (INBOUNDS(idx, font))
|
if (INBOUNDS(idx, font))
|
||||||
{
|
{
|
||||||
SDL_Surface* tempPrint = ScaleSurfaceSlow(font[idx], font[idx]->w *sc,font[idx]->h *sc);
|
SDL_Surface* tempPrint = ScaleSurface(font[idx], font[idx]->w *sc,font[idx]->h *sc);
|
||||||
SDL_Rect printrect = { static_cast<Sint16>((_x) + bfontpos), static_cast<Sint16>(_y) , static_cast<Sint16>((bfont_rect.w*sc)+1), static_cast<Sint16>((bfont_rect.h * sc)+1)};
|
SDL_Rect printrect = { static_cast<Sint16>((_x) + bfontpos), static_cast<Sint16>(_y) , static_cast<Sint16>((bfont_rect.w*sc)+1), static_cast<Sint16>((bfont_rect.h * sc)+1)};
|
||||||
BlitSurfaceColoured(tempPrint, NULL, backBuffer, &printrect, ct);
|
BlitSurfaceColoured(tempPrint, NULL, backBuffer, &printrect, ct);
|
||||||
SDL_FreeSurface(tempPrint);
|
SDL_FreeSurface(tempPrint);
|
||||||
|
@ -3023,7 +3023,7 @@ void Graphics::bigrprint(int x, int y, std::string& t, int r, int g, int b, bool
|
||||||
idx = font_idx(cur);
|
idx = font_idx(cur);
|
||||||
if (INBOUNDS(idx, font))
|
if (INBOUNDS(idx, font))
|
||||||
{
|
{
|
||||||
SDL_Surface* tempPrint = ScaleSurfaceSlow(font[idx], font[idx]->w *sc,font[idx]->h *sc);
|
SDL_Surface* tempPrint = ScaleSurface(font[idx], font[idx]->w *sc,font[idx]->h *sc);
|
||||||
SDL_Rect printrect = { Sint16((x) + bfontpos), Sint16(y) , Sint16(bfont_rect.w*sc), Sint16(bfont_rect.h * sc)};
|
SDL_Rect printrect = { Sint16((x) + bfontpos), Sint16(y) , Sint16(bfont_rect.w*sc), Sint16(bfont_rect.h * sc)};
|
||||||
BlitSurfaceColoured(tempPrint, NULL, backBuffer, &printrect, ct);
|
BlitSurfaceColoured(tempPrint, NULL, backBuffer, &printrect, ct);
|
||||||
SDL_FreeSurface(tempPrint);
|
SDL_FreeSurface(tempPrint);
|
||||||
|
|
|
@ -171,38 +171,6 @@ SDL_Surface * ScaleSurface( SDL_Surface *_surface, int Width, int Height, SDL_Su
|
||||||
return _ret;
|
return _ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface * ScaleSurfaceSlow( SDL_Surface *_surface, int Width, int Height)
|
|
||||||
{
|
|
||||||
if(!_surface || !Width || !Height)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
SDL_Surface *_ret;
|
|
||||||
|
|
||||||
_ret = SDL_CreateRGBSurface(_surface->flags, Width, Height, _surface->format->BitsPerPixel,
|
|
||||||
_surface->format->Rmask, _surface->format->Gmask, _surface->format->Bmask, _surface->format->Amask);
|
|
||||||
if(_ret == NULL)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float _stretch_factor_x = (static_cast<double>(Width) / static_cast<double>(_surface->w)), _stretch_factor_y = (static_cast<double>(Height) / static_cast<double>(_surface->h));
|
|
||||||
|
|
||||||
|
|
||||||
for(Sint32 y = 0; y < _surface->h; y++)
|
|
||||||
for(Sint32 x = 0; x < _surface->w; x++)
|
|
||||||
for(Sint32 o_y = 0; o_y < _stretch_factor_y; ++o_y)
|
|
||||||
for(Sint32 o_x = 0; o_x < _stretch_factor_x; ++o_x)
|
|
||||||
DrawPixel(_ret, static_cast<Sint32>(_stretch_factor_x * x) + o_x,
|
|
||||||
static_cast<Sint32>(_stretch_factor_y * y) + o_y, ReadPixel(_surface, x, y));
|
|
||||||
|
|
||||||
// DrawPixel(_ret, static_cast<Sint32>(_stretch_factor_x * x) + o_x,
|
|
||||||
//static_cast<Sint32>(_stretch_factor_y * y) + o_y, ReadPixel(_surface, x, y));
|
|
||||||
|
|
||||||
return _ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Surface * FlipSurfaceHorizontal(SDL_Surface* _src)
|
SDL_Surface * FlipSurfaceHorizontal(SDL_Surface* _src)
|
||||||
{
|
{
|
||||||
SDL_Surface * ret = SDL_CreateRGBSurface(_src->flags, _src->w, _src->h, _src->format->BitsPerPixel,
|
SDL_Surface * ret = SDL_CreateRGBSurface(_src->flags, _src->w, _src->h, _src->format->BitsPerPixel,
|
||||||
|
|
|
@ -43,7 +43,6 @@ void ScrollSurface(SDL_Surface* _src, int pX, int py);
|
||||||
|
|
||||||
SDL_Surface * FlipSurfaceHorizontal(SDL_Surface* _src);
|
SDL_Surface * FlipSurfaceHorizontal(SDL_Surface* _src);
|
||||||
SDL_Surface * FlipSurfaceVerticle(SDL_Surface* _src);
|
SDL_Surface * FlipSurfaceVerticle(SDL_Surface* _src);
|
||||||
SDL_Surface * ScaleSurfaceSlow( SDL_Surface *_surface, int Width, int Height );
|
|
||||||
void UpdateFilter();
|
void UpdateFilter();
|
||||||
SDL_Surface* ApplyFilter( SDL_Surface* _src );
|
SDL_Surface* ApplyFilter( SDL_Surface* _src );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue