1
\$\begingroup\$

Sometimes when I am drawing objects that aren't 'linear' (e.g. rounded edges, circles, ellipses, diagonal lines, etc) I this weird effect of some pixels at certain points not getting drawn.

It's easier to show than explain: This image is created by the code below it. It's a block fading from blue to black. The same effect appears when only using one color. (Though it's otherwise obviously equivalent to just drawing a filled rectangle.)

undrawn lines

float b = 100;
int steps = 100;
int thickness = 1;
int basex = 10;
int basey = 10;
int lenx = 200;
int leny = 200;
for(int idx = 0; idx < steps; idx++) {
    al_draw_rounded_rectangle(
            basex + thickness * (steps - idx), basey + thickness * (steps - idx),
            basex + lenx - thickness * (steps - idx), basey + leny - thickness * (steps - idx),
            RII, RII,
            al_map_rgba(0, 0, b - idx * (b / steps), alpha(0.0)),
            thickness);
}

Is there a term for this phenomenon? How do I prevent it from happening?

\$\endgroup\$
  • \$\begingroup\$ I think I understand. Are you drawing many rounded rectangles, one inside the other in succession? \$\endgroup\$ – AturSams Feb 12 '14 at 20:55
  • \$\begingroup\$ Related: allegro.cc/manual/5/primitives.html describes how primitives are drawn. Essentially you must enclose the midpoint of the pixel you want to draw. Depending on what you are doing, enabling sampling via al_set_new_display_option could help. \$\endgroup\$ – Matthew Feb 13 '14 at 3:21
  • \$\begingroup\$ Using sampling doesn't work. But if I use pixel precise output(see comment above) on one point before and on the other after the value it works. So modifying my drawing statement like following: al_draw_rounded_rectange(x1-0.5, y1-0.5, x2+0.5, x2+0.5, rx, ry, color, thickness) \$\endgroup\$ – RenK Feb 13 '14 at 19:12
0
\$\begingroup\$

The cause of this "effect" is that I believe you are drawing the outline of a rounded rectangle, one rectangle inside the other. Is that correct? If so, what you are seeing is simply how Allegro I presume is handling round corners, specifically, it does not draw a thick pixelated line and leaves some pixels "missing" in the corners. When you draw multiple repetitions like you just have, the missinh pixels become more prominent than they would be if you only drew one outline (which is what I presume the function was intended for) and create the missing lines effect.

To put it in visual form:

This is what it's doing:

enter image description here

This is the behavior you are relying on / expecting:

enter image description here

If you stack many iterations of the former round corner you will/might get (a) missing line(s).

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.