![]() |
|
got a bug in my FULLSCREEN WINDOWED MODE switchout |
Doctor Cop
Member #16,833
April 2018
![]() |
I was trying to emulate f11 key functionality, it works as expected when I press f11 first time (it successfully flags ALLEGRO_FULLSCREEN_WINDOW), but when I again press f11 then it switches back but it also trrigers ALLEGRO_EVENT_DISPLAY_RESIZE. 1#include <stdio.h>
2#include <allegro5/allegro5.h>
3#include <allegro5/keyboard.h>
4#include <allegro5/allegro_font.h>
5
6int width = 800, height = 600;
7
8int main()
9{
10 // Initalization
11 al_init();
12 al_install_keyboard();
13
14 ALLEGRO_MONITOR_INFO monitor;
15 al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE);
16 al_get_monitor_info(0, &monitor);
17 printf("%i x %i", monitor.x2, monitor.y2);
18
19 ALLEGRO_TIMER* timer = al_create_timer(1.0 / 30.0);
20 ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
21 ALLEGRO_DISPLAY* disp = al_create_display(width, height);
22 ALLEGRO_FONT* font = al_create_builtin_font();
23
24 // Registering event sources with an event
25 al_register_event_source(queue, al_get_keyboard_event_source());
26 al_register_event_source(queue, al_get_display_event_source(disp));
27 al_register_event_source(queue, al_get_timer_event_source(timer));
28
29 bool redraw = true, resize = 0, fullscreen_window = 0;
30 ALLEGRO_EVENT event;
31
32 // This sets the frames per second of the application
33 al_start_timer(timer);
34
35 // Main event loop
36 while(1)
37 {
38 al_wait_for_event(queue, &event);
39
40 if(event.type == ALLEGRO_EVENT_TIMER)
41 redraw = true;
42 // close the display
43 else if(event.keyboard.keycode == ALLEGRO_KEY_ESCAPE || event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
44 break;
45 // Resize the display
46 else if (event.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
47 {
48 resize = !resize;
49 if(resize == 1)
50 al_resize_display(disp, monitor.x2, monitor.y2);
51 else
52 al_resize_display(disp, width, height);
53 }
54 // FULLSCREEN WINDOWED MODE *There is a bug here, it can't disable the mode*
55 else if(event.keyboard.keycode == ALLEGRO_KEY_F11)
56 {
57 fullscreen_window = !fullscreen_window;
58 // if(fullscreen_window)
59 al_set_display_flag(disp, ALLEGRO_FULLSCREEN_WINDOW, fullscreen_window);
60 // else
61 // al_toggle_display_flag(disp, ALLEGRO_RESIZABLE, 1);
62
63 }
64
65 // Rendering happens here...
66 if(redraw && al_is_event_queue_empty(queue))
67 {
68 al_clear_to_color(al_map_rgb(0, 0, 0));
69 al_draw_text(font, al_map_rgb(255, 255, 255), 0, 0, 0, "Hello world!");
70 al_flip_display();
71
72 redraw = false;
73 }
74 }
75
76 al_destroy_font(font);
77 al_destroy_display(disp);
78 al_destroy_timer(timer);
79 al_destroy_event_queue(queue);
80
81 return 0;
82}
Why is it happening? Also, what did you guys do to the allegro forums, it has never been running so smooth ever since I joined. Gotta say, Wow.
|
MikiZX
Member #17,092
June 2019
|
I'm only noob guessing here but shouldn't the ' al_resize_display' actually be located under your 'if(event.keyboard.keycode == ALLEGRO_KEY_F11)' block? I'm guessing what happens now is that you are responding to a 'ALLEGRO_EVENT_DISPLAY_RESIZE' event with a command that asks Allegro to resize the display again. I'm not sure though... EDIT: also, https://liballeg.org/a5docs/trunk/display.html#al_acknowledge_resize might be of interest here? EDIT2: After trying your code this seems to work for me: 1...
2 else if (event.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
3 {
4 al_acknowledge_resize(disp);
5 }
6 // FULLSCREEN WINDOWED MODE *There is a bug here, it can't disable the mode*
7 else if(event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_F11)
8 {
9 fullscreen_window = !fullscreen_window;
10 // if(fullscreen_window)
11 al_set_display_flag(disp, ALLEGRO_FULLSCREEN_WINDOW, fullscreen_window);
12 // else
13 // al_toggle_display_flag(disp, ALLEGRO_RESIZABLE, 1);
14 //al_rest(0.1);
15
16 }
17...
|
Doctor Cop
Member #16,833
April 2018
![]() |
It worked, thanks. Now I know how important ALLEGRO_EVENT_KEY_DOWN is and I didn't know that al_acknowledge_resize() can solve the problem which I tried to solve with resize display. Now I don't need monitor info for display resize.
|
|