|
Windows programming and changing resolutions |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Hello everyone - hoping to find some advice / pointers to info on : 1. Does anyone know how/where I could get started programming with the Windows API so that I could write my own Windows Main function? 2. Been having problems changing graphics modes , specifically : -I also have problems changing to fullscreen after I have changed resolutions in windowed mode (which seems to work ok) I have been programming with Allegro for a few months now and am using Thanks for you help. 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 |
Jakub Wasilewski
Member #3,653
June 2003
|
As for 2), please post some minimal code that exhibits the problems you described. It'll be much easier for us to help you this way. Also, what version of Allegro are you using? --------------------------- |
DanielH
Member #934
January 2001
|
1) Yes Attached is a basic win32 project created from msvcnet. |
Kris Asick
Member #1,424
July 2001
|
Someone else recently had similar problems. It might benefit you to read through this thread: http://www.allegro.cc/forums/thread/591194 As per writing a WinMain() instead of a regular main(), the book I learned to do that from was "Tricks of the Windows Game Programming Gurus", which is a 1000+ page book that covers many of the basics in detail without relying on libraries made by other people. (Like Allegro.) --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Jakub - Nevermind , just had to push the help button. I am using Allegro 4.21 DanielH - Where do I find the headers and WIN32 API library? Does Microsoft offer the library and documentation? Will do a search through Microsoft and report back. Kris -
I will probably change from using constants for scr_wid and scr_ht to a small integer array so I can get rid of the switch statements ie ... (scr_wid[resolution_num]) and allow for more resolution choices (program can be processor intensive and I want it to work well for people with slower computers. Can you make values in an array const? If so how do you declare them? I will probably add error checking for the color resolution in case 32 doesn't work. 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 |
gnolam
Member #2,030
March 2002
|
Quote: Well , I was going to put up the code , but it looks really awful because I don't know how to put it in a scrollable window. Can anyone tell me how to do that first? Use code tags: [code][/code] See the help icon above the reply box for more info. -- |
Jakub Wasilewski
Member #3,653
June 2003
|
Try changing: set_gfx_mode(WHATEVER, scr_w, scr_h, scr_w, scr_h); to set_gfx_mode(WHATEVER, scr_w, scr_h, 0, 0); The 4th and 5th parameter have little to do with the actual resolution - they're the minimum required size of the so-called "virtual screen", and the support for that is kind of quirky nowadays (it's more of a remnant of Allegro DOS days). You can read more in the manual entry for set_gfx_mode. --------------------------- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Sorry Jakub - No luck setting v_w and v_h to 0 , I still have the same problem. 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 |
Kris Asick
Member #1,424
July 2001
|
Did you look over the contents of the thread I pointed you to? I think the key thing you should check is if setting the display switching mode immediately after setting a resolution at any time (both the first time and on each change thereafter) to SWITCH_BACKGROUND (windowed) or SWITCH_BACKAMNESIA (fullscreen) solves the problem. The person who was having crashes with changing resolutions, upon running my own game which had a nearly identical display switching method, didn't experience them, and that was the only real difference I could see that might matter. Plus, you must set the display switching mode to a background mode if you plan on using Allegro with your own custom window, otherwise numerous things can go wrong. (Using your own WinMain entry point is fine. You only want to make a custom window if you want to add your own Windows event handling or if you need to override some of Allegro's built-in capabilities... and after swearing enough times at my computer I can tell you it's not easy...) Regardless of what you do, leave the virtual x and y values at 0 in set_gfx_mode(). You're only supposed to set them if you want to set up a virtual screen, which is pointless to do in anything but DOS. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Marco Radaelli
Member #3,028
December 2002
|
Edgar Reynaldo said: 1. Does anyone know how/where I could get started programming with the Windows API so that I could write my own Windows Main function? I f a book is what you're looking for, I found the Petzold very nice. Consider it talks about pure Win32 API programming, nothing about the newer technologies (Windows.Forms, WPF, ...).
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
I found more information on the WIN32 API : Marco , will take a look at your book , thanks for the pointer. Okay Kris , I've been working on implementing set_display_switch_mode and here's what I've come up with. The call to set_display_switch_mode(switch_pause) works generally when changing from resolution to resolution , however when changing from fullscreen to windowed mode , switch_pause and switch_background failed and only switch_backamnesia worked All five tests conducted using GFX_DIRECTX_ACCEL for fullscreen and Test 1 Switch_pause works when changing between resolutions in windowed mode. Switch_pause fails and Switch_background fails when changing from fullscreen mode to windowed mode within same resolution. Change_res function code (Used in Test 1)
Test 2 At least one of the switching modes worked because my program would have deallocated memory and quit if it hadn't. However , when changing from fullscreen mode to windowed mode in either res(640X480 or 480X320) the window was not the proper size (ie desktop resolution sized and not the called resolution with desktop screen artifacts. Test 3 Changing between resolutions in windowed mode worked successfully but while changing from fullscreen to windowed about 1/4th of the time , it resulted in the improperly sized window (desktop sized resolution with desktop leftovers). The other 3/4ths of the time the window worked successfully. Test 4 Changing between resolutions in windowed mode worked fine and changing between resolutions in fullscreen mode worked ok. However , when changing from fullscreen to windowed mode in either resolution there was 100% failure to properly size the window(the window was in a desktop sized resolution drawing to the size set Test 5 I tried Test 1 again this time with calling allegro_message(outputstring) to display switch_mode_success and this time didn't have any errors (when changing from fullscreen to windowed mode it worked fine). So to sum up However when changing from any fullscreen mode to any other mode (another fullscreen res or a windowed res same size) switch_pause failed , switch_background failed , and then switch_backamnesia worked. The only time changing from a fullscreen mode to a windowed mode worked all the time was using { So everythings working for now , will have to try using more resolutions to change between. I still don't understand why it does and does not work though. Derrrrrr. Confusion. 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 |
Kris Asick
Member #1,424
July 2001
|
A few things: 1. You need to set the display switch mode immediately after calling set_gfx_mode(). Calling it right before changing resolutions means it might not be properly set up by the time the switch occurs. (Not sure about this one actually, but considering the multi-threaded nature of Allegro, it couldn't hurt.) 2. In fullscreen, the only two valid switching modes are SWITCH_AMNESIA and SWITCH_BACKAMNESIA. In windowed, the only two valid switching modes are SWITCH_PAUSE and SWITCH_BACKGROUND. 3. When you run full-screen, set the switching to SWITCH_BACKAMNESIA. When you run windowed, set the switching to SWITCH_BACKGROUND. Make sure you set the switching mode after any call to set_gfx_mode(). This should prevent the problems you're having. 4. Use GFX_AUTODETECT_WINDOWED and GFX_AUTODETECT_FULLSCREEN for best results. 5. PLEASE look at the large chunk of code I posted in the thread I pointed you to. It will make things a lot easier for you by showing you the order in which you should be calling the functions. The link again is: http://www.allegro.cc/forums/thread/591194 --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Sorry Kris , but my program is picky. Then as soon as I added There is something really bizarre going on here. By the way, what parts of Allegro are multi-threaded? Keyboard and timer and mouse? 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 |
Kris Asick
Member #1,424
July 2001
|
With your code exactly as you described it, try removing the call to set_gfx_mode(GFX_TEXT,0,0,0,0). That might solve all your problems. And don't forget to also set the switching mode after your very first call to set_gfx_mode too, in case you're not using your resolution changing routine exclusively to set video modes. As per the multi-threading, Allegro's extra threads aren't always present, but here they are: Event Thread: Handles Windows messages and I/O, if you're not using a custom window. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Edgar Reynaldo
Major Reynaldo
May 2007
|
I tried removing the call to set_gfx_mode(GFX_TEXT,0,0,0,0) which also takes out allegro_message(outputstring) which left me with this. Note: Only change_res is called to change graphics modes. Without adding back in set_gfx_mode(GFX_TEXT,0,0,0,0) and allegro_message(outputstring) my program just refuses to change from fullscreen to windowed mode without ending up in a desktop-sized resolution drawing to the top left corner with a bunch of desktop artifacts around it. In any case my program is working correctly when changing between the two resolutions I am using and the two GFX_AUTODETECT modes. I am going to add in more resolutions now and see if it still works. Question : Do the resolutions all have to be smaller than the size of the user's desktop? Thanks for all your help Kris and all. 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 |
Kris Asick
Member #1,424
July 2001
|
Quote: When you run windowed, set the switching to SWITCH_BACKGROUND. Try that. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
|