Patrick’s development blog

Drawing rectangles SDL

Posted in SDL / OpenGL by Patrick on June 24, 2009

Drawing rectangles can become such a pain in the ass after drawing them a couple of times. I made a helper function that makes this easier.

void FillRect(int x, int y, int w, int h, int color) {
SDL_Rect rect = {x,y,w,h};
SDL_FillRect(screen, &rect, color);

I want to add a 100×150 rectangle at the position (25,25) with the color white.


Great, no more headache and code memorizing.


5 Responses

Subscribe to comments with RSS.

  1. Pete said, on June 29, 2009 at 1:24 pm

    This is what I was looking for, I assume this uses SDL and OpenGL hehe would explain why it wouldent work with no OpenGL-dev libs installed.

    Thanks for this ^_^

  2. Patrick said, on July 2, 2009 at 7:42 pm

    This code is only SDL and no OpenGL : )

  3. bunyk said, on July 27, 2009 at 8:46 am

    It was helpful. But code will look more nice if you put it into sourcecoude tags, rather than blockquote.

    Here is wordpress manual page:

  4. Patrick said, on July 28, 2009 at 2:29 pm

    Thanks for the FYI. I’ll use the source tag from now on : )

  5. Johannes Schmitz said, on May 5, 2010 at 12:13 pm

    Thank you, I will use this for my Pong project 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: