Ejemplo n.º 1
0
static void xdpy_apply_window_constraints(ALLEGRO_DISPLAY *display,
   bool onoff)
{
   int posX;
   int posY;
   ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();

   _al_mutex_lock(&system->lock);

   if (onoff) {
      al_get_window_position(display, &posX, &posY);
      _al_xwin_set_size_hints(display, posX, posY);
   }
   else {
      _al_xwin_reset_size_hints(display);
   }

   _al_mutex_unlock(&system->lock);
   al_resize_display(display, display->w, display->h);
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    ALLEGRO_DISPLAY *display, *ms_display;
    ALLEGRO_EVENT_QUEUE *queue;
    ALLEGRO_TIMER *timer;
    ALLEGRO_BITMAP *memory;
    char title[1024];
    bool quit = false;
    bool redraw = true;
    int wx, wy;

    (void)argc;
    (void)argv;

    if (!al_init()) {
        abort_example("Couldn't initialise Allegro.\n");
    }
    al_init_primitives_addon();

    al_install_keyboard();

    al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
    memory = create_bitmap();

    /* Create the normal display. */
    al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 0, ALLEGRO_REQUIRE);
    al_set_new_display_option(ALLEGRO_SAMPLES, 0, ALLEGRO_SUGGEST);
    display = al_create_display(300, 450);
    if (!display) {
        abort_example("Error creating display\n");
    }
    al_set_window_title(display, "Normal");

    /* Create bitmaps for the normal display. */
    al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
    bitmap_filter = al_clone_bitmap(memory);
    al_set_new_bitmap_flags(0);
    bitmap_normal = al_clone_bitmap(memory);

    font = al_create_builtin_font();

    al_get_window_position(display, &wx, &wy);
    if (wx < 160)
        wx = 160;

    /* Create the multi-sampling display. */
    al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE);
    al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);
    ms_display = al_create_display(300, 450);
    if (!ms_display) {
        abort_example("Multisampling not available.\n");
    }
    sprintf(title, "Multisampling (%dx)", al_get_display_option(
                ms_display, ALLEGRO_SAMPLES));
    al_set_window_title(ms_display, title);

    /* Create bitmaps for the multi-sampling display. */
    al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
    bitmap_filter_ms = al_clone_bitmap(memory);
    al_set_new_bitmap_flags(0);
    bitmap_normal_ms = al_clone_bitmap(memory);

    font_ms = al_create_builtin_font();

    /* Move the windows next to each other, because some window manager
     * would put them on top of each other otherwise.
     */
    al_set_window_position(display, wx - 160, wy);
    al_set_window_position(ms_display, wx + 160, wy);

    timer = al_create_timer(1.0 / 30.0);

    queue = al_create_event_queue();
    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));
    al_register_event_source(queue, al_get_display_event_source(ms_display));
    al_register_event_source(queue, al_get_timer_event_source(timer));

    al_start_timer(timer);
    while (!quit) {
        ALLEGRO_EVENT event;

        /* Check for ESC key or close button event and quit in either case. */
        al_wait_for_event(queue, &event);
        switch (event.type) {
        case ALLEGRO_EVENT_DISPLAY_CLOSE:
            quit = true;
            break;

        case ALLEGRO_EVENT_KEY_DOWN:
            if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
                quit = true;
            break;

        case ALLEGRO_EVENT_TIMER:
            bitmap_move();
            redraw = true;
            break;
        }

        if (redraw && al_is_event_queue_empty(queue)) {
            /* Draw the multi-sampled version into the first window. */
            al_set_target_backbuffer(ms_display);

            al_clear_to_color(al_map_rgb_f(1, 1, 1));

            draw(bitmap_filter_ms, 0, "filtered, multi-sample");
            draw(bitmap_normal_ms, 250, "no filter, multi-sample");

            al_flip_display();

            /* Draw the normal version into the second window. */
            al_set_target_backbuffer(display);

            al_clear_to_color(al_map_rgb_f(1, 1, 1));

            draw(bitmap_filter, 0, "filtered");
            draw(bitmap_normal, 250, "no filter");

            al_flip_display();

            redraw = false;
        }
    }

    return 0;
}