If this is your first visit, be sure to check out the FAQ by clicking the link above. You have to register before you can post.

If you have recently signed up, please make sure you log in so that your activity is registered. This is required for automatic promotions to work and to ensure your account is not deleted during the registration process.

AthenaOfDelphi

Moderation Process Reminder

Since this appears to be a problem, please be aware that some areas of the site are moderated. When you post to these areas, you will be told that your post is awaiting moderation.

You will not be able to see posts that you have made that are waiting to be moderated.

Do not think that because your post has not appeared that an error has occurred. If this happens an error message will be displayed (you should note this and report it in the 'Site News/Feedback' forum.

SDL, sloped pixel lines

SDL provides 2D accelerated rendering including pixel points, rectangles and lines. Furthermore you can set device independent resolution and nearest pixel sampling. So you can use the resolution of the C64 (320 x 200) on a big window (1280 x 800) for example. The pixels are scaled accordingly.

But not always. If you draw a line then it's pixels are only scaled if that line ist either a horizontal or a vertical one. Sloped lines are rendered without pixel scaling.
That's because lines are rendered as rectangles internally:

Did you notice that FIXME? -- I wrote an additional procedure in order to draw sloped pixel lines. It makes use of that good old Bresenham algorithm. Also each line is devided into horizontal or vertical segments which can be rendered quite fast by SDL:

But not always. If you draw a line then it's pixels are only scaled if that line ist either a horizontal or a vertical one. Sloped lines are rendered without pixel scaling.
That's because lines are rendered as rectangles internally:

Would you mind explaining of what you mean by "Sloped lines are rendered without pixel scaling"?
Perhaps by posting two example images. One showing sloped line with pixel scaling and one without.

Would you mind explaining of what you mean by "Sloped lines are rendered without pixel scaling"?
Perhaps by posting two example images. One showing sloped line with pixel scaling and one without.

This is a screenshot from a window with the physical size of 960 x 540.
The logical size was set to 320 x 180, so each rendered pixel has internally to be scaled up (3 x).
But the thin lines are rendered by SDL's own line renderer and unfortunately the pixels are not scaled up.
The thick lines are rendered with the new procedure.

OK! Now I see what are you talking about. Couldn't really figure that out because me and C-like syntax don't get along pretty well

Any way looking at your code I'm wondering a few things.

When calculating dx and dy values why don't you simply use:

Code:

dx := ABS(x2-x1);
dy := ABS(y2-y1);

Also looking at you code it seems as if you are using a for loop to determine the width of line rectangles. Isn't that very slow?
Wouldn't it be easier to calculate the width of horizontal lines (line segments) that will represent your diagonal line by simply dividing the dx with dy?

Also looking at you code it seems as if you are using a for loop to determine the width of line rectangles. Isn't that very slow?
Wouldn't it be easier to calculate the width of horizontal lines (line segments) that will represent your diagonal line by simply dividing the dx with dy?

You're right ...

I adapted a line algorithm intended for drawing single pixels. That code has to iterate over every pixel of the line. But that's unnecessary when drawing horizontal or vertical line segments instead of pixels.
So I followed your hint and rewrote the code: