Jump to content
  • Advertisement
Sign in to follow this  
sander242

drawing rectangles

This topic is 3045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!