Allegro 5 中的抗锯齿

Joh*_*mac 1 c++ allegro antialiasing allegro5

绘图时如何让 allegro 5 使用抗锯齿?我需要对角线显得平滑。目前,它们只是阴影像素线,边缘看起来很硬。

Mat*_*hew 5

要为基元启用抗锯齿:

// before creating the display:
al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);

display = al_create_display(640, 480);
Run Code Online (Sandbox Code Playgroud)

请注意,抗锯齿仅适用于直接绘制到后台缓冲区的图元。它不会在其他任何地方工作。

在 OpenGL 上,您的卡必须支持ARB_multisample扩展。

要检查它是否已启用(使用 ALLEGRO_SUGGEST 时):

if (al_get_display_option(display, ALLEGRO_SAMPLE_BUFFERS)) {
   printf("With multisampling, level %i\n",
     al_get_display_option(display, ALLEGRO_SAMPLES));
}
else {
   printf("Without multisampling.\n");
}
Run Code Online (Sandbox Code Playgroud)