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 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 codeSDL_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 screenSDL_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.

Create an account

Register a new account

• Forum Statistics

• Total Topics
627736
• Total Posts
2978868

• 10
• 10
• 21
• 14
• 12