sdl/texture: Set filtering mode when creating from surface
Defaults to nearest-neighbour interpolation.
This commit is contained in:
parent
1b0fdeecad
commit
c466323808
2 changed files with 16 additions and 3 deletions
|
@ -54,7 +54,7 @@ texture::texture(SDL_Texture* txt)
|
|||
}
|
||||
}
|
||||
|
||||
texture::texture(const surface& surf)
|
||||
texture::texture(const surface& surf, bool linear_interpolation)
|
||||
: texture()
|
||||
{
|
||||
if (!surf) {
|
||||
|
@ -70,6 +70,10 @@ texture::texture(const surface& surf)
|
|||
return;
|
||||
}
|
||||
|
||||
// Filtering mode must be set before texture creation.
|
||||
const char* scale_quality = linear_interpolation ? "linear" : "nearest";
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scale_quality);
|
||||
|
||||
texture_.reset(SDL_CreateTextureFromSurface(renderer, surf), &cleanup_texture);
|
||||
if(!texture_) {
|
||||
ERR_SDL << "When creating texture from surface: " << SDL_GetError() << std::endl;
|
||||
|
|
|
@ -36,8 +36,17 @@ public:
|
|||
/** Assigns the given texture to this one. */
|
||||
explicit texture(SDL_Texture* txt);
|
||||
|
||||
/** Construct a texture from a surface. */
|
||||
explicit texture(const surface& surf);
|
||||
/**
|
||||
* Construct a texture from a surface.
|
||||
*
|
||||
* @param surf The surface to copy.
|
||||
* @param linear_interpolation If true this texture will use linear
|
||||
* interpolation when drawing. Otherwise
|
||||
* nearest-neighbour interpolation is used.
|
||||
* This does not affect texture creation,
|
||||
* only later application.
|
||||
*/
|
||||
explicit texture(const surface& surf, bool linear_interpolation = false);
|
||||
|
||||
/** Construct a texture of the specified size and access type. */
|
||||
texture(int w, int h, SDL_TextureAccess access);
|
||||
|
|
Loading…
Add table
Reference in a new issue