Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How does allegro draw primitives?

This thread is locked; no one can reply to it. rss feed Print
How does allegro draw primitives?
Markobar
Member #16,921
December 2018

Hi all,

This is my first post here, just tell me if I am breaking any forum rules.

My question is about how allegro deals with the primitives. Have a look to the picture attached. This example is based 99.9% on this code:

https://wiki.allegro.cc/index.php?title=Tilemap_Example

I just added a couple of lines for testing purposes:
1) I added a white-filled rectangle on top of the black rectangles (they are drawn 10 pixels left and 10 pixels up with respect to the back ones).
2) I added some red splines with 0 thickness.

When doing zoom and rotate, triangles, circles, splines lose resolution, while rectangles do not. Is it because allegro rasterises the first ones before drawing them? Why this does not happen with rectangles?

Another question is about the edges between the white and black rectangles. If you look closer, the left and top edges look sharper than the other two, which look more blended or anti aliased.

I did another test where I drew a 3d pyramid by using the "al_draw_indexed_prim" function, and even if this object contains triangles, the object does not lose resolution when zooming or rotating.

Which is the explanation for this different behaviour? Is there a way to write the same tile map without losing resolution? If I am not wrong, the allegro primitives are vector graphics, isn't it?

EDIT: I just realised that the bottom of the triangles look straight, even if one zooms or rotates. So maybe allegro rasterises everything, but since rectangles are purely vertical and horizontal lines, one cannot see what happens with diagonal or curved lines. I am right?

Thank you in advance and regards!
Marcos.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You've got to keep in mind, allegro is not drawing primitives in this example, it's drawing a scaled bitmap with primitives drawn on it at a smaller resolution. That's why they don't scale well, even with ALLEGRO_MAG_LINEAR (which looks blurry, imo) or ALLEGRO_MIN_LINEAR (which scales down great).

If you were to draw the primitives instead of the tiles, they would look much sharper.

EDIT
Welcome, by the way. ;)

Markobar
Member #16,921
December 2018

Thank you for your fast response, Edgar. That explains everything.

And thanks again for the welcome!

Regards,
Marcos.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You can get even better looking primitives when enabling multi sampling, and you can get scaled down versions of bitmaps for free when you enable ALLEGRO_MIPMAP. Up to 8x or 16x multisampling looks best in my opinion. 2 and 4 are okay, but 8 is great. Super smooth.

Markobar
Member #16,921
December 2018

I will definitely try that!

I presume that you can do the same thing with fonts. Loading them 8x or 16x and then scale them down. Allegro is wonderful :)

Best!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Ah, a caveat. Actually with fonts, no. They are not rendered as primitives, sadly, they are rendered as pre-sized glyphs. That could change, but not likely without a big font overhaul.

EDIT
Well, now I'm thinking about it I'm not sure. I would have to test it out and see if multisampling indeed affects font loading. It certainly doesn't affect font drawing though, that I am certain of.

Go to: