Skip to content

Commit

Permalink
Put back software prescaling, ugh
Browse files Browse the repository at this point in the history
  • Loading branch information
isage committed Apr 8, 2019
1 parent cba9735 commit 6ac1673
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 20 deletions.
26 changes: 13 additions & 13 deletions src/graphics/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,18 @@ void Renderer::drawSurface(Surface *src, int dstx, int dsty, int srcx, int srcy,

SDL_Rect srcrect, dstrect;

srcrect.x = srcx;
srcrect.y = srcy;
srcrect.w = wd;
srcrect.h = ht;
srcrect.x = srcx * scale;
srcrect.y = srcy * scale;
srcrect.w = wd * scale;
srcrect.h = ht * scale;

dstrect.x = dstx * scale;
dstrect.y = dsty * scale;
dstrect.w = srcrect.w * scale;
dstrect.h = srcrect.h * scale;
dstrect.w = srcrect.w;
dstrect.h = srcrect.h;

if (_need_clip)
clip(srcrect, dstrect);
clipScaled(srcrect, dstrect);

SDL_SetTextureAlphaMod(src->texture(), src->alpha);
if (SDL_RenderCopy(_renderer, src->texture(), &srcrect, &dstrect))
Expand All @@ -310,12 +310,12 @@ void Renderer::blitPatternAcross(Surface *sfc, int x_dst, int y_dst, int y_src,
SDL_Rect srcrect, dstrect;

srcrect.x = 0;
srcrect.w = sfc->width();
srcrect.y = (y_src);
srcrect.h = (height);
srcrect.w = sfc->width() * scale;
srcrect.y = (y_src * scale);
srcrect.h = (height * scale);

dstrect.w = srcrect.w * scale;
dstrect.h = srcrect.h * scale;
dstrect.w = srcrect.w;
dstrect.h = srcrect.h;

int x = (x_dst * scale);
int y = (y_dst * scale);
Expand All @@ -328,7 +328,7 @@ void Renderer::blitPatternAcross(Surface *sfc, int x_dst, int y_dst, int y_src,
dstrect.x = x;
dstrect.y = y;
SDL_RenderCopy(_renderer, sfc->texture(), &srcrect, &dstrect);
x += sfc->width() * scale;
x += sfc->width() * scale;
} while (x < destwd);
}

Expand Down
18 changes: 11 additions & 7 deletions src/graphics/Surface.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Surface.h"
#include "Renderer.h"
#include "../common/stat.h"
#include "zoom.h"

namespace NXE
{
Expand Down Expand Up @@ -31,17 +32,20 @@ bool Surface::loadImage(const std::string &pbm_name, bool use_colorkey)
return false;
}

_width = image->w;
_height = image->h;
_width = image->w * Renderer::getInstance()->scale;
_height = image->h * Renderer::getInstance()->scale;

SDL_Surface *image_scaled = SDL_ZoomSurface(image, Renderer::getInstance()->scale);
SDL_FreeSurface(image);

if (use_colorkey)
{
SDL_SetColorKey(image, SDL_TRUE, SDL_MapRGB(image->format, 0, 0, 0));
SDL_SetColorKey(image_scaled, SDL_TRUE, SDL_MapRGB(image_scaled->format, 0, 0, 0));
}

_texture = SDL_CreateTextureFromSurface(Renderer::getInstance()->renderer(), image);
_texture = SDL_CreateTextureFromSurface(Renderer::getInstance()->renderer(), image_scaled);

SDL_FreeSurface(image);
SDL_FreeSurface(image_scaled);

if (!_texture)
{
Expand All @@ -66,12 +70,12 @@ Surface *Surface::fromFile(const std::string &pbm_name, bool use_colorkey)

int Surface::width()
{
return _width;
return _width / Renderer::getInstance()->scale;
}

int Surface::height()
{
return _height;
return _height / Renderer::getInstance()->scale;
}

SDL_Texture* Surface::texture()
Expand Down
Loading

0 comments on commit 6ac1673

Please sign in to comment.