|
How to make a resizable window in Allegro 5 |
DidaFM
Member #16,802
January 2018
|
Hello guys, this is my first post on this site so I hope I'm not making anything wrong. I use three functions in the document for the visualization of the world, one to create it (showworld_new), one to update it (showworld_update) and one to destroy it (showworld_destroy), which I then call on the main program. If you could help me with any tips u have #include "showworld.h" /* The implementation of SHOWWORLD type used in this simple text-based world /* Variable for the canvas */ ALLEGRO_EVENT_QUEUE *event_queue; ALLEGRO_TIMEOUT timeout; ALLEGRO_FONT *font1 = NULL; /* Variables of the drawings of the agents on the canvas*/ int w_init, h_init, w_new, h_new; /* Create a new display/visualization object for the simulation world. al_init(); al_set_new_display_flags(ALLEGRO_WINDOWED); SHOWWORLD *sw = NULL; display = al_create_display((sw->xdim)*32, (sw->ydim)*32); event_queue = al_create_event_queue(); font1 = al_load_font("uni0553.ttf",16,0); w_init = (int *)((sw->xdim) * 32); w_new = al_get_display_width(display); if (w_init > w_new) { if (h_init > h_new) { printf("%d\n", h_new); w_new = al_get_display_width(display); if (w_init > w_new) { if (h_init > h_new) { al_resize_display(display, w_init * reason_w, h_init * reason_h ); /* /* int larg = xdim.innerWidth; /*if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { return sw; } /* Destroy a display/visualization object for the simulation world. al_destroy_bitmap(h_playable); /* Update the simulation world display/visualization. printf("%d\n", h_new); /* Load the respective images of each type */ /* Cycle through all the rows */ /* Cycle through all the columns for the current row */ /* Get state of the world (in bit packed fashion) using the user /* Extract the agent type (2 bits). */ /* Determine the agent type. */ /* If no agent is present at (x,y), draw Bg. */ /* If human agent present at (x,y) draw Human1 or Human2. */ /* If zombie agent present at (x,y) draw Zombie1 or Zombie2. */ /* Print '?' if unknown type detected. This should never } /* Print two newlines after each row. */ } } |
bamccaig
Member #7,536
July 2006
|
To make it easier to read your post please edit it (there is an icon with a pencil) and wrap the code in <code> tags (XHTML style). I don't know of a good answer to your question, but that will help somebody that does. I think it's rare for games to be resizeable in this way precisely for this reason. It's difficult to scale all of the drawn content to fit the window properly. A robust job might have to detect certain "thresholds" and change the scale of content (e.g., text) to keep it usable. Most games just let you choose a "resolution" and then can either load content specifically made for that resolution, or possibly scale the content dynamically at the setting change to adjust. I think Allegro 4 used to support scaled drawing too so it's likely Allegro 5 supports it too, but the graphics will necessarily lose quality in the process. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Edgar Reynaldo
Major Reynaldo
May 2007
|
You need to bitwise OR the values in the argument to the function al_set_new_display_flags like so : al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE); Also, you don't want to call al_resize_display when you get an ALLEGRO_EVENT_DISPLAY_RESIZE event. You only want to call al_acknowledge_resize. 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 |
|