Advertisement

SDL Clipping Question

Started by December 17, 2004 02:52 PM
7 comments, last by Drew_Benton 19 years, 9 months ago
Hey guys/gals - SDL_SetClipRect information from the SDL Docs:
Quote: Name SDL_SetClipRect -- Sets the clipping rectangle for a surface. Synopsis #include "SDL.h" void SDL_SetClipRect(SDL_Surface *surface, SDL_Rect *rect); Description Sets the clipping rectangle for a surface. When this surface is the destination of a blit, only the area within the clip rectangle will be drawn into. The rectangle pointed to by rect will be clipped to the edges of the surface so that the clip rectangle for a surface can never fall outside the edges of the surface. If rect is NULL the clipping rectangle will be set to the full size of the surface.
Now my question is what are the benefits of using this function. In all my SDL programs, I've yet to use this, how would it help me. I understand the whole busiess of not drawing "offscreen" but would it help any? Please post any comments/opinions/ideas. Thanks in advance! - Drew
say you are trying to do a splitscreen game for 2 player.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
Advertisement
Quote: Original post by PnP Bios
say you are trying to do a splitscreen game for 2 player.


Some times you make me smile PnP [lol]. But in regards to that post, do you mean that lets say I have my main screen, in the top half, I set the clip rect, and draw. Then I go to the bottom half, set the clip rect and draw? That makes sense, but in general uses in terms of drawing edges near the screen, are there any speed benefits or anything when clipping the edges? Thanks for the time!

[Edited by - Drew_Benton on May 25, 2005 9:52:42 PM]
heh
No, it offers no speed benifits. basicaly, all it does is the same thing glViewport does.

Just another tool in the box
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
First I wanted to write that "AFAIK it was invented to prevent application crash when fellow programmer writes code that would blit surface 10000 pixels from where it should be drawn, which could easily go out of total video cards memory".
But now I think that was done with more or less performance in sight: software blitting is generally very slow, so few checks (min()/max() to find out appropriate coordinates) won't hurt that much, and in some situations they may drastically improve app speed (ie. blitting huge surface that lies outside screen - sure, it's probably programmer's fault, but you get the idea... :-] )
Quote: Original post by PnP Bios
heh
No, it offers no speed benifits. basicaly, all it does is the same thing glViewport does.

Just another tool in the box


Awww! =( Thanks for the info! Also thank you Koshmaar. That makes perfect sense =).

[Edited by - Drew_Benton on May 25, 2005 9:27:06 PM]
Advertisement
It has nothing to do with performance, or safety as far as I can tell, just asthetics.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
Say, for a moment, that you are writing a game that uses an isometric grid. Now say that you would like to section the screen into a play area (most of the screen), a message area (bottom of the screen), a minimap (top right of screen), and a status panel (below minimap). Now let us say that you would like a nifty border drawn around each of these areas.

When rendering an isometric tile into the play area, you have to be careful not to render outside of the place where your play panel is located. This is a perfect case for using the clip rect.

Get off my lawn!

Quote: Original post by TANSTAAFL
Say, for a moment, that you are writing a game that uses an isometric grid. Now say that you would like to section the screen into a play area (most of the screen), a message area (bottom of the screen), a minimap (top right of screen), and a status panel (below minimap). Now let us say that you would like a nifty border drawn around each of these areas.

When rendering an isometric tile into the play area, you have to be careful not to render outside of the place where your play panel is located. This is a perfect case for using the clip rect.


Ahh!! [inlove] I can't believe I didn't see that. Rating++. In my last project, I was trying to do Iso tiles and such and had to figure out some crazy algorithms to only draw so much on the screen, It worked, but I didn't like how the design was. Now, I'm going to try it with a clip rect and hopefully it will work better. Thanks!

This topic is closed to new replies.

Advertisement