Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL draws images blurred without scaling

Tags:

c++

image

sdl

sdl-2

I'm working on a project in C++ using SDL (Simple Directmedia Layer) but when I draw a SDL_Texture to the screen it's blurred eventhough it is not scaled.

How the image is loaded:

SDL_Surface* loadedSurface = IMG_Load("image.png");
SDL_Texture* gImage = SDL_CreateTextureFromSurface( gRenderer, loadedSurface);

How the image is drawn to the screen:

SDL_Rect renderQuad = { x, y, width, height };
SDL_RenderCopy(gRenderer, gImage , NULL, &renderQuad );

See image, left is in the program and right is the original:

enter image description here

Is there a parameter a forgot to set? And is it normal that SDL does this?

I'm using SDL 2.0 32-bit on a Windows 8.1 64-bit machine.

like image 344
Oli414 Avatar asked Nov 09 '22 19:11

Oli414


1 Answers

Ahead of your call to SDL_CreateTextureFromSurface try calling:

SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");

According to SDL Wiki this should affect how SDL_CreateTextureFromSurface calls interpolate the surface. "0" should result in nearest neighbour removing the blurring effect you are seeing.

like image 139
stevejpurves Avatar answered Nov 14 '22 22:11

stevejpurves