SDL_FillRect();

What is the second argument for in SDL_FillRect();
for example
1
2
  SDL_FillRect(screen,NULL, color);
  SDL_FillRect(screen, &screen->clip_rect, color);

Both function does the same job of filling the screen with the specified color .
In the second line what does &screen->clip_rect mean
I understand for it to work we need to make SDL_Rect rect; and give it rect values
What IDE and SDL are you using?
Myself, when I don't know some SDL function, I either press on this function name I just entered with right mouse button and press on "Find definition of $funct" - this is provided to me by my IDE(Code::Blocks), but I believe Visual Studio should have something similar.
There is a brief explanation in there, where function is defined, and if you read it, it is generally sufficient. If not - look online.

Back to the question. YOu have function explained here:
http://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlfillrect.html

Answer to your question is in the very first sentence after function declaration.

&screen->clip_rect is accessing your screen's clip_rect data(it a rectangle containing x,y,w and h of image).
Basically, in lazyfoo's tutorials, screen is of SDL_Surface* type, and you use & and -> to get the type you want:
1
2
3
4
SDL_Surface* screen; // It's how it's defined in your code, I assume.

auto first = screen->clip_rect; // This will be of type SDL_Rect
auto first = &screen->clip_rect; // This will be of type SDL_Rect* . The type that is needed as parameter in your function ;)) 


Cheers!
Last edited on
What IDE and SDL are you using?

Visual c++ 2010 express , SDL 1.2.5
Visual Studio should have something similar.

Visual studio has go to definition but it goes to it's header file of that particular function when clicked
Thanks mate now it's clearer
Wait i tried it and i am confused right now &screen->clip_rect whats the use of that when we write NULL instead of that the whole screen turns into that color and if we write &screen->clip
&screen->clip_rect is accessing your screen's clip_rect data(it a rectangle containing x,y,w and h of image)
Which data what are the values of x,y,wand h , is it of that values when we
blit images on screen
SDL 1.2.5
Drop that immediately and get the latest 2.0 release. It's much more modern and has better performance.
The second argument to SDL_FillRect is the rectangle that will be filled with the colour of the third argument. The two function calls in your first post do exactly the same, they draw to the clip_rect area of screen, which is usually the whole screen surface.

When you draw to a surface only the area inside clip_rect will be drawn to. By default clip_rect covers the whole surface so it's easy to forget that it exists. See the documentation for the SDL_SetClipRect function for more information about clip_rect.
Last edited on
To answer OP:
It just gets the rectangle that represents the screen (fills the whole screen with that color.) It is unnecessary however, if you just pass NULL instead it does the same thing.
Thanks Peter
Avilius 2 or three days ago tutorial for sdl 2.0 wasn't available on lazyfoo.net +(youtube videos will take quite a time for new tutorial videos) so i thought i should download sdl 1.2.5 but than why is there really a significant change cause i have to start over adding libraries which is so tedious and is there any syntax change in both versions ?
No not really. I've used both and I can say that it's much nicer to use the second.

I'd say go and learn 1.x, and once you feel comfortable with it move on to 2.0. They've only changed what was required.

Don't go on and create any sort of huge project with 1.x, because you're eventually going to have to end up and port your code in the end.
Thanks Avilius :D and okay helps alot man :)
No problem. I'm always here if you need questions.
Topic archived. No new replies allowed.