I create a 200x20 texture full of white pixel and write a simple demo to draw this texture. If I use SDL_RenderCopyExF
and specify the rotation angle, the renderer seems to be using nearest neighbor interpolation to render the texture, results in jagged edges. Neither setting the hint SDL_HINT_RENDER_SCALE_QUALITY
to 'linear'
nor setting the texture’s scale mode to SDL_ScaleModeLinear
helps. Is this made by design? Or is this a bug? What should I do if I want the rotated texture being rendered smoothly?
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#include <SDL2/SDL_main.h>
#include <SDL2/SDL_image.h>
#include <Windows.h>
int main()
{
SetProcessDPIAware();
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window_ptr;
SDL_Renderer* renderer_ptr;
SDL_CreateWindowAndRenderer(800, 600, 0, &window_ptr, &renderer_ptr);
SDL_Texture* rectange_ptr = IMG_LoadTexture(renderer_ptr, "rect.bmp");
SDL_SetTextureScaleMode(rectange_ptr, SDL_ScaleModeLinear);
SDL_Rect src = { 0,0,0,0 };
SDL_QueryTexture(rectange_ptr, nullptr, nullptr, &src.w, &src.h);
SDL_FRect dst = { 400 - src.w / 2.0f, 300 - src.h / 2.0f, src.w, src.h };
while (true)
{
SDL_PumpEvents();
SDL_SetRenderDrawColor(renderer_ptr, 0, 0, 0, 255);
SDL_RenderClear(renderer_ptr);
SDL_RenderCopyExF(renderer_ptr, rectange_ptr,
&src, &dst, 30, nullptr, SDL_FLIP_NONE);
SDL_RenderPresent(renderer_ptr);
}
SDL_Quit();
}