# What exactly does SDL_RenderSetClipRect do?

I assumed that this function would move the area which is clipped out of conceptual space and copied onto the renderer (and subsequently drawn to the window) - i.e. change the origin of rendering - but it doesn't seem to do this. Anybody know how it works?

From the source code (available via the website):

int
SDL_RenderSetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
{
CHECK_RENDERER_MAGIC(renderer, -1)

if (rect) {
renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
} else {
SDL_zero(renderer->clip_rect);
}
return renderer->UpdateClipRect(renderer);
}


A little more digging reveals that UpdateClipRect is dispatched based on the underlying rendering API (D3D or OpenGL), and all it does is used the computed rectangle above to set the scissor test rectangle.

It does not do anything related to transforming coordinate systems; it just means that anything rendered to the window that falls within that rectangle will be rendered, and anything outside of that rectangle will be discarded. That's generally the meaning of "clip" in graphics terms.

• shoot, in that case, what's the difference between this function and SDL_RenderSetViewport()? – detectivecalcite Jan 5 '14 at 4:33
• That function is used to set the viewport (within the render target) that rendering occurs within. It calls glViewport. – user1430 Jan 5 '14 at 6:17
• so is there a function that sets the source rectangle (i.e. changes the origin for texture positions) for an SDL viewport? – detectivecalcite Jan 5 '14 at 23:28
• You could do that with a texture transform matrix; but you are beginning to stray from the topic of the question, if you have follow-up questions you should ask them as separate questions. Comments are not for extended discussion. – user1430 Jan 6 '14 at 0:07

Assuming that function works similarly to the glScissor test, all it does is test if the pixel falls within the defined rectangle. If it falls outside that rectangle, it's discarded.