#include "examples_common.c"

int main(void)
{
    srand(time(NULL));

    allegro_init();
    set_color_depth(32);

    int mode;
#ifdef ALLEGROGL
    mode = GFX_OPENGL_WINDOWED;
    install_allegro_gl();
#else
    mode = GFX_AUTODETECT_WINDOWED;
#endif

    set_gfx_mode(mode, 640, 480, 0, 0);
    install_keyboard();
    install_timer();

    install_fudgefont();

    /* Load 4 fonts with different sizes. */
    FONT *f[4];
    int i;
    for (i = 0; i < 4; i++)
    {
        int size = 8 + i * 8;
        f[i] = my_load_font("ttf/DejaVuSans.ttf",  size);
    }

    #ifdef ALLEGROGL
        allegro_gl_set_allegro_mode();
    #endif

    int unicode = '*';

    while (1)
    {
#ifdef ALLEGROGL
        glClearColor(0, 0, 0, 1);
        glClear(GL_COLOR_BUFFER_BIT);
#else
        clear_to_color(screen, makecol(0, 0, 0));
#endif

        char str[16];
        ustrzcpy(str, 16, "");
        uinsert(str, 0, unicode);
        for (i = 0; i < 100; i++)
        {
            int x = rand() % 640;
            int y = rand() % 480;
            int size = rand() % 4;
            char const *texts[] = {
                str,
                "FudgeFont",
#ifdef ALLEGROGL
                "AllegroGL"
#else
                "Allegro"
#endif
            };

            char const * str = texts[rand() % (sizeof(texts) / sizeof(texts[0]))];
    
#ifdef ALLEGROGL
            glColor3ub(rand() & 255, rand() & 255, rand() & 255);
            glPushMatrix();
            glRotatef(rand() % 31 - 25, 0, 0, 1);
#else
            fudgefont_color_range(0, 0, 0, rand() & 255, rand() & 255,rand() & 255);
#endif
            my_print(f[size], x, y, 1, "%s", str);
#ifdef ALLEGROGL
            glPopMatrix();
#endif
        }
#ifdef ALLEGROGL
        allegro_gl_flip();
#endif

        unicode = ureadkey(NULL);
        if (unicode == 27)
            break;
    }

    return 0;
}
