![]() |
|
Flickering Explanation |
AMCerasoli
Member #11,955
May 2010
![]() |
Aloha. I has being messing around with allegro and stuff, and found an strange behavior when I use al_flip_display without al_clear_to_color. I'ts some kind of flickering only when it's full screen. Does have something to do with monitor Hz or vsync? This is an executable example (Windows) Well I just was curious about this... What it causes that behavior?.
|
torhu
Member #2,727
September 2002
![]() |
Could you post the source? |
AMCerasoli
Member #11,955
May 2010
![]() |
Yep. That is inside a class... 1
2#ifndef MENU_H
3#define MENU_H
4
5#include <iostream>
6#include <vector>
7#include <fstream>
8#include "fade.h"
9
10#define ALLEGRO_STATICLINK
11#include "allegro5/allegro.h"
12#include "allegro5/allegro_font.h"
13#include "allegro5/allegro_ttf.h"
14#include "allegro5/allegro_image.h"
15#include <allegro5/allegro_audio.h>
16#include <allegro5/allegro_acodec.h>
17
18
19
20class MENU
21{
22
23 private:
24
25 ALLEGRO_BITMAP *fondo;
26 ALLEGRO_BITMAP *fondo2;
27 ALLEGRO_EVENT event;
28
29 //FADE fade;
30
31 int R, G, B, A;
32 int mouse_x, mouse_y;
33 bool cerrar_menu;
34
35 ALLEGRO_FONT *font;
36
37 public:
38
39 MENU() {
40
41 fondo = al_load_bitmap("menu_img/1.png");
42 //fondo2 = al_load_bitmap("menu_img/packed.png");
43 font = al_load_font("consola.ttf",14,0);
44 R=0; G=0; B=0; A=0;
45 cerrar_menu=false;
46
47 }
48
49 ~MENU() {
50
51 al_destroy_bitmap(fondo);
52 //al_destroy_bitmap(fondo2);
53
54 }
55
56 unsigned short mostr_menu(ALLEGRO_EVENT_QUEUE* event_queue){
57
58 while(!cerrar_menu){
59
60 al_wait_for_event(event_queue, &event);
61
62 switch(event.type){
63
64 case ALLEGRO_EVENT_TIMER:
65 if(al_is_event_queue_empty(event_queue))
66 dibujar();
67 break;
68
69 case ALLEGRO_EVENT_MOUSE_AXES:
70 Mouse_Axes();
71 break;
72
73 case ALLEGRO_EVENT_KEY_CHAR:
74 Key_Down();
75 break;
76
77 };
78 }
79
80 return 2;
81 }
82
83 void dibujar(){
84
85 //al_clear_to_color(al_map_rgb(0,0,0));
86
87 //al_draw_tinted_bitmap(fondo2, al_map_rgba(255, 255, 255, 255),0, 0, 0);
88 al_draw_tinted_bitmap(fondo, al_map_rgba(R, G, B, A),mouse_x-330, mouse_y-250, 0);
89 al_draw_tinted_bitmap(fondo, al_map_rgba(0, 0, 0, 125),400, 280, 0);
90
91 //fade.in();
92
93 al_draw_textf(font, al_map_rgba(255, 255, 255, 255),780, 500, ALLEGRO_ALIGN_RIGHT,"R: %f", R);
94 al_draw_textf(font, al_map_rgba(255, 255, 255, 255),780, 515, ALLEGRO_ALIGN_RIGHT,"G: %f", G);
95 al_draw_textf(font, al_map_rgba(255, 255, 255, 255),780, 530, ALLEGRO_ALIGN_RIGHT,"B: %f", B);
96 al_draw_textf(font, al_map_rgba(255, 255, 255, 255),780, 545, ALLEGRO_ALIGN_RIGHT,"A: %f", A);
97 al_draw_text(font,al_map_rgba(255, 255, 255, 255), 0, 0, 0, "Press the keys: R,G,B and A to increse its value, and the left key to decrease it <exept A> ");
98 al_draw_text(font,al_map_rgba(255, 255, 255, 255), 0, 18, 0, "then move arround the mouse ");
99 al_draw_text(font,al_map_rgba(255, 255, 255, 255), 0, 36, 0, "Press enter to reset the colors ");
100
101 al_flip_display();
102 }
103
104 void Mouse_Axes(){
105
106 mouse_x = event.mouse.x;
107 mouse_y = event.mouse.y;
108 }
109
110 void Key_Down(){
111
112 int cantidad=5;
113
114
115
116 if(event.keyboard.keycode == ALLEGRO_KEY_R&&R<=250)
117 R+=cantidad;
118 else if(event.keyboard.keycode == ALLEGRO_KEY_E&&R>=5)
119 R-=cantidad;
120
121 else if(event.keyboard.keycode == ALLEGRO_KEY_G&&G<=250)
122 G+=cantidad;
123 else if(event.keyboard.keycode == ALLEGRO_KEY_F&&G>=5)
124 G-=cantidad;
125
126 else if(event.keyboard.keycode == ALLEGRO_KEY_B&&B<=250)
127 B+=cantidad;
128 else if(event.keyboard.keycode == ALLEGRO_KEY_V&&B>=5)
129 B-=cantidad;
130
131 else if(event.keyboard.keycode == ALLEGRO_KEY_A&&A<=250)
132 A+=cantidad;
133 else if(event.keyboard.keycode == ALLEGRO_KEY_S&&A>=5)
134 A-=cantidad;
135
136 else if(event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
137
138 cerrar_menu=true;
139
140 else if(event.keyboard.keycode == ALLEGRO_KEY_ENTER){
141
142 R=0; G=0; B=0; A=0;
143
144 }
145
146
147 }
148
149
150
151};
152
153#endif // MENU_H
Edit: This is the initialization process... I forgot it... 1#include <iostream>
2#include <vector>
3#include <fstream>
4
5#include "Menu.h"
6#include "presentacion.h"
7
8#define ALLEGRO_STATICLINK
9#include "allegro5/allegro.h"
10#include "allegro5/allegro_font.h"
11#include "allegro5/allegro_ttf.h"
12#include "allegro5/allegro_image.h"
13#include <allegro5/allegro_audio.h>
14#include <allegro5/allegro_acodec.h>
15#include <allegro5/allegro_native_dialog.h>
16
17
18
19int main(int argc, char **argv){
20
21 ALLEGRO_DISPLAY *display = NULL;
22 ALLEGRO_EVENT_QUEUE *event_queue = NULL;
23 ALLEGRO_TIMER *FPS = NULL; //Frames
24 unsigned short suiche=1;
25
26 ///Variables
27 bool cerrar_juego=false;
28
29 if(!al_init()) {
30 al_show_native_message_box(display, "Error", "Error", "Failed to initialize allegro!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
31 return -1;
32 }
33
34 if(!al_init_image_addon()) {
35 al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_image_addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
36 return -1;
37 }
38
39 al_init_font_addon();
40
41 if(!al_init_ttf_addon()) {
42 al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_ttf_addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
43 return -1;
44 }
45
46 if(!al_install_audio()) {
47 al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_install_audio!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
48 return -1;
49 }
50
51 if(!al_init_acodec_addon()) {
52 al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_acodec_addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
53 return -1;
54 }
55
56 if(!al_reserve_samples(5)) {
57 al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_reserve_samples!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
58 return -1;
59 }
60
61
62 FPS = al_create_timer(1.0 / 30); //Frames
63
64 if(!FPS) {
65 al_show_native_message_box(display, "Error", "Error", "Failed to initialize FPS!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
66 return -1;
67 }
68
69 if(!al_install_keyboard()) {
70 al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_install_keyboard!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
71 return -1;
72 }
73
74 if(!al_install_mouse()) {
75 al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_install_mouse!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
76 return -1;
77 }
78
79 //al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR );
80 al_set_new_display_flags(ALLEGRO_FULLSCREEN);
81
82
83 display = al_create_display(800, 600);
84
85 if(!display) {
86 al_show_native_message_box(display, "Error", "Error", "Failed to initialize display!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
87 return -1;
88 }
89 //al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE );
90 event_queue = al_create_event_queue();
91
92 if(!event_queue) {
93 al_show_native_message_box(display, "Error", "Error", "Failed to initialize event_queue!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
94 return -1;
95 }
96
97 al_register_event_source(event_queue, al_get_display_event_source(display));
98 al_register_event_source(event_queue, al_get_timer_event_source(FPS));
99 al_register_event_source(event_queue, al_get_mouse_event_source());
100 al_register_event_source(event_queue, al_get_keyboard_event_source());
101 al_clear_to_color(al_map_rgb(0,0,0));
102 al_flip_display();
103 al_start_timer(FPS);
104 al_set_window_title(display, "Trivial Relax 2011");
105
106 while(!cerrar_juego)
107 {
108
109 switch(suiche){
110
111 case 0:{
112 //PRESENTACION presentacion;
113 //suiche = presentacion.mostr_presentacion(event_queue);
114 break;
115 }
116 case 1:{
117 MENU menu;
118 suiche = menu.mostr_menu(event_queue);
119 break;
120 }
121
122 };
123 if(suiche==2)
124 break;
125 }
126
127
128 al_destroy_timer(FPS);
129 al_destroy_display(display);
130 al_destroy_event_queue(event_queue);
131 al_uninstall_audio();
132
133 return 0;
134}
|
Matthew Leverton
Supreme Loser
January 1999
![]() |
Does al_get_display_option(display, ALLEGRO_UPDATE_DISPLAY_REGION) indicate the display supports partial updates? But that aside, I don't think al_flip_display() isn't guaranteed to clear your backbuffer. So if you are only updating a partial part of the backbuffer, then I would expect "odd" behavior if you don't first clear it. |
torhu
Member #2,727
September 2002
![]() |
I don't know, sorry. Just try making some changes and see what happens. |
AMCerasoli
Member #11,955
May 2010
![]() |
No actually there is no problem... I shouldn't being doing that anyway... I just wanted to know... Matthew Leverton said: Does al_get_display_option(display, ALLEGRO_UPDATE_DISPLAY_REGION) indicate the display supports partial updates?
Let me process that... Quote: But that aside, I don't think al_flip_display() isn't guaranteed to clear your backbuffer. So if you are only updating a partial part of the backbuffer, then I would expect "odd" behavior if you don't first clear it. Yes that is what I thought.
|
kenmasters1976
Member #8,794
July 2007
|
This code, for example, will flicker like crazy on my machine if I use OpenGL but not if I use Direct3D. So I guess whether the backbuffer is cleared or not depends on the driver. 1#include <allegro5/allegro.h>
2#include <allegro5/allegro_primitives.h>
3
4
5
6ALLEGRO_DISPLAY *display;
7ALLEGRO_EVENT_QUEUE *events;
8
9
10
11int main() {
12 al_init();
13 al_install_keyboard();
14 al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_OPENGL);
15 display = al_create_display(640, 480);
16 al_init_primitives_addon();
17
18 events = al_create_event_queue();
19 al_register_event_source(events, al_get_keyboard_event_source());
20
21 al_clear_to_color(al_map_rgb(0, 128, 128));
22 while (al_is_event_queue_empty(events)) {
23 al_draw_line(0, 0, 640, 480, al_map_rgb(255, 255, 255), 2);
24 al_flip_display();
25 al_rest(0.015);
26 }
27}
|
AMCerasoli
Member #11,955
May 2010
![]() |
Yes on my computer also flicks a lot with OpenGL. I think when I don't do this: al_set_new_display_flags(ALLEGRO_OPENGL); Automatically is using Direct3D but when I do this: al_set_new_display_flags(ALLEGRO_DIRECT3D); Tells me that 'ALLEGRO_DIRECT3D' was not declared in this scope. Why's that? Edit: If I use 'ALLEGRO_OPENGL_3_0' instead of 'ALLEGRO_OPENGL' doesn't flicks anymore on windowed mode, but if I go fullscreen do it again.
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
AMCerasoli said: Tells me that 'ALLEGRO_DIRECT3D' was not declared in this scope. Why's that?
You have to include <allegro5/allegro_direct3d.h> for it to work. The manual neglects to mention that little fact. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
AMCerasoli
Member #11,955
May 2010
![]() |
Finally you could download the last driver for your PC? I think mines is very similar to yours. Mines is a Toshiba Satellite A215, but I couldn't find the Drivers. You downloaded it from Toshiba or from AMD?
|
kenmasters1976
Member #8,794
July 2007
|
Edgar Reynaldo said: You have to include <allegro5/allegro_direct3d.h> for it to work. The manual neglects to mention that little fact. At some point in 4.9.x you had to include allegro5/allegro_opengl.h so that you could use ALLEGRO_OPENGL. I never tried to use ALLEGRO_DIRECT3D since it's the default. AMCerasoli said: Finally you could download the last driver for your PC? I think mines is very similar to yours. Mines is a Toshiba Satellite A215, but I couldn't find the Drivers. You downloaded it from Toshiba or from AMD? My PC is an old IBM with integrated Intel graphics card. I have the latest drivers (dated 2005). You should be able to find the latest drivers for your machine at Toshiba. Anyway, you should always clear the backbuffer. Even for a simple program like the one I posted you could do: al_clear_to_color(al_map_rgb(0, 128, 128)); al_flip_display(); al_clear_to_color(al_map_rgb(0, 128, 128)); or simply force ALLEGRO_SINGLE_BUFFER.
|
|