[AD] DirectX fullscreen alt-tab |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hi,
In the attached program:
AFAIK I'm following the guidelines for lost devices, but after
alt-tabbing a few times it often gets into a state where the screen is
no longer drawn. The log file shows a lot of
"D3DERR_INVALIDCALL in reset" so I guess it wasn't reset properly.
The only slightly tricky thing is that I'm using al_put_pixel
draw to an offscreen video bitmap, i.e. region locking.
Alt-tabbing seemed to work reliably though when I used al_put_pixel
to draw to the backbuffer.
Tested in XP and Vista, 5.1 branch.
Peter
#include <allegro5/allegro.h>
int main(void)
{
const int w = 800;
const int h = 600;
ALLEGRO_DISPLAY *dpy;
ALLEGRO_BITMAP *bmp;
ALLEGRO_TIMER *timer;
ALLEGRO_EVENT_QUEUE *queue;
ALLEGRO_EVENT ev;
bool redraw;
bool lost;
if (!al_init())
return 1;
al_install_keyboard();
al_set_new_display_flags(ALLEGRO_FULLSCREEN);
dpy = al_create_display(w, h);
if (!dpy)
return 1;
al_set_new_bitmap_flags(ALLEGRO_NO_PRESERVE_TEXTURE);
bmp = al_create_bitmap(w, h);
if (!bmp)
return 1;
timer = al_create_timer(1/60.0);
queue = al_create_event_queue();
al_register_event_source(queue, al_get_keyboard_event_source());
al_register_event_source(queue, al_get_timer_event_source(timer));
al_register_event_source(queue, al_get_display_event_source(dpy));
al_start_timer(timer);
redraw = false;
lost = false;
for (;;) {
al_wait_for_event(queue, &ev);
if (ev.type == ALLEGRO_EVENT_KEY_CHAR && ev.keyboard.unichar == 27) {
break;
}
if (ev.type == ALLEGRO_EVENT_TIMER) {
redraw = true;
}
if (ev.type == ALLEGRO_EVENT_DISPLAY_LOST) {
lost = true;
}
if (ev.type == ALLEGRO_EVENT_DISPLAY_FOUND) {
lost = false;
redraw = true;
}
if (redraw && !lost && al_event_queue_is_empty(queue)) {
al_set_target_bitmap(bmp);
al_put_pixel(rand()%w, rand()%h, al_map_rgb(rand()%256, rand()%256, rand()%256));
al_set_target_backbuffer(dpy);
al_draw_bitmap(bmp, 0, 0, 0);
al_flip_display();
redraw = false;
}
}
return 0;
}
/* vim: set sts=3 sw=3 et: */