Sign in to follow this  
sander242

drawing rectangles

Recommended Posts

Hi, I'm using SDL and i have a question. I need to draw a rectangle with a fixed x(width) -variable, but a changing y(height) -variable. I thought of using SDL_FillRect somehow but that would fill the entire screen or any other surface i would choose. I believe it is easy to do what i need i just haven't learned it yet, so maybe you can help. thx in advance :D

Share this post


Link to post
Share on other sites
You could just define a SDL_Rect with your specified width and height, and then change the height whenever there is an event. The SDL_FillRect() function takes the SDL_Rect as the second argument, so you could just keep updating and calling it.


//Somewhere in your code
SDL_Rect rect;
rect.x = 20;
rect.y = 20;
rect.w = 50;
rect.h = 10;

//Elsewhere in an event loop or some other place to update the screen
SDL_FillRect(destination_surface, &rect, color_variable);

rect.h++;
//SDL_BlitSurface() destination_surface to the screen, update rect height




Something like that should work out for you. Use SDL_FillRect to put a rectangle onto a surface of your choosing, and then whenever you want, just update the SDL_Rect that you were using and repeat as necessary. Finally, blit the new result to the screen. The values I used were just arbitrary, so they can be whatever you need them to be.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this