From: Neil R. <no...@co...> - 2012-07-18 13:23:02
|
On 13/07/2012 9:33 AM, Frédéric Drouillon wrote: > hello, > > i begin with allegro 5 and it is the most beautifull library i know : like > nithrill in the mines of Moria... > > I use allegro 5.0.7 and i meet a problem with playing in FULLLSCREEN different > kinds of drawings : the display is blurred a little like a very old TV and > whatever the resolution. I link with allegro-5.0.7-monolith-mt-debug and > allegro-5.0.7-monolith-mt > > i work with cobeblock and Mingw32, windows 7, Dell XPS15 with a NVIDIA GeForce > GT 420M video card. > > May be i do some thing wrong ? here is the code i test : > > /*******************************************************************/ > #include <allegro5/allegro.h> > #include <allegro5/allegro_native_dialog.h> > #include <allegro5/allegro_primitives.h> > > void erreur(const char*txt) > { > al_show_native_message_box( NULL, "Erreur", txt ,NULL, NULL, 0); > exit(EXIT_FAILURE); > } > > int main() > { > ALLEGRO_DISPLAY*display; > ALLEGRO_KEYBOARD_STATE key; > ALLEGRO_DISPLAY_MODE mode; > > if(!al_init()) > erreur("initialisation"); > > if (!al_init_primitives_addon()) > erreur("init primitives"); > > if(!al_install_keyboard()) > erreur("install keyboard"); > > // to have destop résolution > al_get_display_mode(al_get_num_display_modes()-1, &mode); > > // THE FULLSCREEN DOESN'T WORK PROPERLY > al_set_new_display_flags(ALLEGRO_FULLSCREEN); > > display=al_create_display(mode.width,mode.height); > if (!display) > erreur("create_display"); > int scrx=al_get_display_width(display); > int scry=al_get_display_height(display); > > > do{ > > al_get_keyboard_state(&key); > > int x1=rand()%scrx; > int y1=rand()%scry; > int x2=rand()%scrx; > int y2=rand()%scry; > > ALLEGRO_COLOR color = > al_map_rgba(rand()%255,rand()%255,rand()%255,rand()%255); > float thickness = rand()%10 - 5; > > > if (al_key_down(&key,ALLEGRO_KEY_F1)) > al_draw_line(x1, y1, x2, y2, color, thickness); > > al_flip_display(); > > > }while (!al_key_down(&key,ALLEGRO_KEY_ESCAPE)); > > al_destroy_display(display); > } > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ I recommend using ALLEGRO_FULLSCREEN_WINDOW which will use the person's desktop resolution. There is a bug in Allegro 5.0.7 where there is lag in ALLEGRO_FULLSCREEN, someone identified what was the likely cause of it on allegro.cc in a topic I started. Trent Gamblin stated: "I think the latest release has a bug in d3d where the reference driver gets used as a fallback, which is extremely slow. It is fixed in svn." Since switching to ALLEGRO_FULLSCREEN_WINDOW and adding in the following function to set up translations it works fine. Plus a fullscreen window has the added benefit of having faster ALT+TABS and such. a5_scale_screen.c: * // Scale Screen: // Sets up transforms in order to fit any resolution // onto an ALLEGRO_FULLSCREEN_WINDOW. // // (Special thanks to Matthew Leverton for help with this!) #include <allegro5/allegro.h> // usage: a5_scale_screen(BUFFER_WIDTH, BUFFER_HEIGHT, display_width, display_height); void a5_scale_screen(int bw, int bh, int dw, int dh) { ALLEGRO_TRANSFORM t; // Calculate the horizontal and vertial aspect ratios const float HAR = dw/(float)bw; const float VAR = dh/(float)bh; // The aspect ratio, x-offset and y-offset (in pixels) float ar, ox, oy; if (bw == dw && bh == dh) { // 1:1, just reset everything al_identity_transform(&t); al_use_transform(&t); al_set_clipping_rectangle(0, 0, bw, bh); } else { // Choose the smaller aspect ratio if (HAR < VAR) { // horizontal bars on the top and bottom ar = HAR; ox = 0; oy = (dh - (ar * bh)) / 2.0; } else { // vertical bars on the left and right ar = VAR; ox = (dw - (ar * bw)) / 2.0; oy = 0; } // set up the transformation to scale and translate al_build_transform(&t, ox, oy, ar, ar, 0); al_use_transform(&t); // make sure nothing is drawn into the black bars al_set_clipping_rectangle(ox, oy, ar * bw, ar * bh); } }* And the header I use for it: a5_scale_screen.h: *#ifndef _a5_scale_screen_h_ #define _a5_scale_screen_h_ // usage: a5_scale_screen(BUFFER_WIDTH, BUFFER_HEIGHT, display_width, display_height); void a5_scale_screen(int bw, int bh, int dw, int dh); #endif //_scale_screen_h_* You use this with a fullscreen window to set up whatever resolution you wish inside that window and it will look and act just like a fullscreen mode. I also used the following code as well after using the above function: *al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_VIDEO_BITMAP); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST); *Hope this helps. |