2
\$\begingroup\$

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?

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ shoot, in that case, what's the difference between this function and SDL_RenderSetViewport()? \$\endgroup\$ – detectivecalcite Jan 5 '14 at 4:33
  • \$\begingroup\$ That function is used to set the viewport (within the render target) that rendering occurs within. It calls glViewport. \$\endgroup\$ – Josh Jan 5 '14 at 6:17
  • \$\begingroup\$ so is there a function that sets the source rectangle (i.e. changes the origin for texture positions) for an SDL viewport? \$\endgroup\$ – detectivecalcite Jan 5 '14 at 23:28
  • \$\begingroup\$ 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. \$\endgroup\$ – Josh Jan 6 '14 at 0:07
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.