Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Anti-aliasing is not working

This thread is locked; no one can reply to it. rss feed Print
Anti-aliasing is not working
Doctor Cop
Member #16,833
April 2018
avatar

I am trying Anti-aliasing in my code but it's not working.

please help me.

al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);
al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);

the code above which I copied from GitHub's Wiki

the code which I wrote

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_primitives.h> 3 4int main() 5{ 6 al_init(); 7 al_init_primitives_addon(); 8 9 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); 10 al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST); 11 al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR); 12 13 ALLEGRO_DISPLAY *display = al_create_display(800, 600); 14 15 al_clear_to_color(al_map_rgb(255, 255, 255)); 16 //al_draw_circle(400, 300, 100, al_map_rgb_f(1, 0, 1), 2); 17 al_draw_rounded_rectangle(400-100, 300-20, 400+100, 300+20, 20, 20, al_map_rgb(70, 60 , 100), 2); 18 al_flip_display(); 19 al_rest(5); 20 21 al_destroy_display(display); 22 return 0; 23}

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

ALLEGRO_*_LINEAR only works for filtering bitmaps. ALLEGRO_SUGGEST is just that, a suggestion. It doesn't gurantee that the option you requested is active. You have to check with al_get_display_option to see if it was successful.

Doctor Cop
Member #16,833
April 2018
avatar

Is there a way to get smoother primitives guaranteed?

I want to make something with primitives, which library can provide me vector graphics like primitives?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

There is no guarantee. You can use ALLEGRO_REQUIRE and check for a null display. Also, primitives are not vector graphics. Vector graphics can scale to any size.

SiegeLord
Member #7,827
October 2006
avatar

Also, primitives are not vector graphics.

This is not correct.

I am trying Anti-aliasing in my code but it's not working.

What OS? If it's Windows, maybe try OpenGL.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Okay so draw an arc at two different sizes and tell me the curvature is the same. Primitives are approximations. Vector graphics can be drawn with primitives but that doesn't make them the same.

dthompson
Member #5,749
April 2005
avatar

which library can provide me vector graphics like primitives?

Maybe worth mentioning that if you're including vector graphics storage formats (like SVG) in that question: these can't be rendered with Allegro 5. There might be a library out there that can load an SVG and resolve its paths to vertices for a given scale, but a quick Google yielded nothing for me.

However, because of SVG's abundance, I wonder whether this'd make a good add-on?

______________________________________________________
Website. It was freakdesign.bafsoft.net.
This isn't a game!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Run time generation of SVG images scaled to destination would be cool. Pre-rendered or drawn on the fly? There's a big performance hit for decoding it multiple times, and there's always mip-maps.

Peter Hull
Member #1,136
March 2001

librsvg will do it. You'd have to make cairo render to a memory buffer which could be converted to an ALLEGRO_BITMAP.
SVG is so complicated that I would imagine doing that in real time would be quite slow.

Doctor Cop
Member #16,833
April 2018
avatar

Hmm, so vector graphics for GUI is a no?

I wonder, How are browsers like Mozilla and Chrome are drawing so smooth layouts?

dthompson
Member #5,749
April 2005
avatar

GUIs absolutely can (and arguably should) be built from vector graphics such that you can do smooth DPI scaling. The user always has the option to veto antialiasing regardless.

How are browsers like Mozilla and Chrome are drawing so smooth layouts?

Trust me, you don't want to worry about how web browsers optimise their renders. It isn't pretty. :P

You'd have to make cairo render to a memory buffer which could be converted to an ALLEGRO_BITMAP.

Huh, this'd be great if we're happy to do the initial [expensive] rasterisation at init, so we end up with mipmaps like Edgar's suggesting.

______________________________________________________
Website. It was freakdesign.bafsoft.net.
This isn't a game!

Erin Maus
Member #7,537
July 2006
avatar

You can do realtime rendering of resolution independent curves in with antialiasing on a non-MSAA framebuffer: https://www.microsoft.com/en-us/research/wp-content/uploads/2005/01/p1000-loop.pdf

I have an implementation for quadratic curves that's really optimized: https://github.com/aaronbolyard/Algae.Canvas

It's just patented until 2026. Thus, unless you license it, you're SOL unless you find a different way of doing it. :'(

I decided the difficulties aren't worth it and have been using vector graphics rasterized offline (ItsyRealm) or vector graphics decomposed into straight lines segments then rasterized to a texture at runtime (Lacklore; necessary for changing fill styles, etc at runtime).

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / them / their

Go to: