The SDL forums have moved to
This is just a read-only archive of the previous forums, to keep old links working.

SDL Forum Index
Simple Directmedia Layer Forums
Rendering scaled clip?

Joined: 31 Mar 2016
Posts: 4
So, I found SDL_RenderCopyEx to be a lot of help with rendering flipped and rotated sprites, but I can't find anything on scaling. I found SDL_RenderSetScale, but that changes the scale of EVERYTHING, not just what's being drawn, and even affects the coordinates I'm drawing to. How would I go about just drawing a scaled clip?

Joined: 31 Mar 2016
Posts: 4
Also, on the note of scaling, I found how to compensate for the scale of the renderer when drawing to mouse coordinates, except that when the render area has a thinner aspect than the window, it makes a letterbox on the sides, and this letterbox still counts as an area for it to check when getting the mouse coordinates. How do I get the renderer's actual position on the window?

I would have put this in the first post, but the forum isn't letting me edit.

Joined: 03 Jul 2014
Posts: 158
Here's a code example on how to scale a texture, which is also clipped


// Pretend a texture has been successfully created

// The texture will be positioned at 200x200 and it's size will be 256x256
SDL_Rect Quad = {200, 200, 256, 256};

// The texture in my case is 768x128 in size but only 128x128 pixels of it will be rendered
SDL_Rect ClipQuad = {0, 0, 128, 128};

// The size of the texture is chosen by "Quad"'s size (256x256)
SDL_RenderCopyEx(Renderer, MyTexture, &ClipQuad, &Quad, 0.0, NULL, SDL_FLIP_NONE);

Hopefully this will help you understand how it's works. Let me know if you have any more questions.

Joined: 03 Jul 2016
Posts: 7

#include <glm/gtc/matrix_transform.hpp>

glm::mat4 glm::scale(glm::mat4 const & m, glm::vec3 const & factors);