Sign in to follow this  
Chocrates

[SDL] outlineing sdl_rect's

Recommended Posts

In a simple game im trying to make i need to outline some rectangles that im using to represent pieces on the game board, other than drawing four rectangles on top of it to highlight the edges, does anyone have any ideas on how to achieve this? I have done a quick (quick) google on the subject but it didn't turn up much.

Drawing four rectangles won't necessarily be hard, but it seems inefficient.

Share this post


Link to post
Share on other sites
Quote:
Original post by Chocrates
In a simple game im trying to make i need to outline some rectangles that im using to represent pieces on the game board, other than drawing four rectangles on top of it to highlight the edges, does anyone have any ideas on how to achieve this? I have done a quick (quick) google on the subject but it didn't turn up much.

Drawing four rectangles won't necessarily be hard, but it seems inefficient.

Four rectangles may be faster than most other solutions when using SDL. Why would you think it would be inefficient? At this point it isn't really an issue I would worry about either way and I would recommend just moving on with your game and getting it working. Once it is working you can use a profiler to find out where your app is spending its time and fix it with some reasonable certainty this will improve the performance of your game.

Share this post


Link to post
Share on other sites
No idea if this would be faster or even fast, but: set the background of your blank surface to the color you want the outline to be. When you get to the tile you want to be outlined, blit every part of the tile except for a few pixels on each edge. I think the math would be something like:
SDL_Rect source;
source.x = x+outline_pixel_count;
source.y = y+outline_pixel_count;
source.w = width - 2 * outline_pixel_count;
source.h = height - 2 * outline_pixel_count;

dest.x = dest_x+outline_pixel_count;
dest.y = dest_y+outline_pixel_count;
Completely untested of course.

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