Screen Resolution Changer Module (glfw)
Monkey Forums/User Modules/Screen Resolution Changer Module (glfw)
| ||
So I eventually got around to revisiting my glfw code from this topic: http://www.monkeycoder.co.nz/Community/posts.php?topic=4418 I have now created a module to handle screen resolution changing in glfw. https://github.com/skn3/screenres Please read the installation instructions! https://github.com/skn3/screenres/wiki/Installation Enjoy, for free :D Please note that this module has not been extensively tested on different platforms! So the module is really easy to use. You just call ChangeScreenMode(300, 300, 32, False) This will change the screen resolution. When you change screen resolution in OpenGL it will lose all images that you had previously loaded. To get around this please call AddAutoLoadImage(image1) Call this for any image you want to be automatically reloaded when the resolution changes. Please remember that this will hold onto a pointer to the image. You have to remove the image when you are done with it in your game. RemoveAutoLoadImage(image1)or ClearAutoLoadImages() If you don't do this then the garbage collector will still see your image as alive. When you change resolution the native code will transfer all autoload images from video memory into system memory. The glfw window is recreated and then all the texture data is transferred back to the video card. Monkey images have a separate surface object which stores the handle to the texture. This means we can simply update this surface and everything will work automatically without making changes. |
| ||
You are the man! Will be kicking something your way soon. |
| ||
:D Small update ' - updated example ' - changed function name to ChangeScreenMode() ' - added GetAvailableScreenModes() ' - added ScreenModeExists() |
| ||
Oh wow, well done Skn, you're making GLFW seem like a proper desktop target now :D With regards to AddAutoLoadImage(image1) I have 2 main images, GFX.spriteSheet:Image GFX.worldSheet:Image and from that I derive lots of sub images using for example Local t:Image = GFX.spriteSheet.GrabImage(0,0,16,16,1,Image.MidHandle) Do I have to AddAutoLoadImage for each "sub" image, or can I do it for just the upmost images? Ta! :) |
| ||
You can do it just for the upmost images. If you look at screenres.monkey ChangeScreenMode() function, it compiles a list of unique image surfaces. So even if you did add the sub-images, the reload would only bother with the original image anyway. |
| ||
Awesome! I was expecting it to be each image reference, but wow :D Thanks. |
| ||
This looks pretty interesting, I didn't even realize you did this when I was rewriting it myself. If my code helps at all, by all means, use it. |
| ||
Skn3, thanks for your work on this! Unfortunately, the resolution change isn't working on Mac for me (monkey 70g, OS 10.7.5): Running the example, the screen and the smileys display, and in the console the available resolutions are displayed, as well as confirmation that 640x480 mode is available -- so that much is working, but when I hit space, the app disappears (crashes), and the console shows this error: 'glfwOpenWindow failed TRANS FAILED: Error executing './MonkeyGame', return code=65280'. Don't think it should be an ogl driver issue as they're built into OS X and I have other gl things that are working. Tried altering the resolution switched to, didn't have any effect. Here's the full monkey console from a run: Graphics Mode: 640 x 480 15bit Graphics Mode: 720 x 480 15bit Graphics Mode: 800 x 500 15bit Graphics Mode: 800 x 600 15bit Graphics Mode: 1024 x 640 15bit Graphics Mode: 1024 x 768 15bit Graphics Mode: 1152 x 720 15bit Graphics Mode: 1280 x 800 15bit Graphics Mode: 1344 x 840 15bit Graphics Mode: 1440 x 900 15bit Graphics Mode: 640 x 480 32bit Graphics Mode: 720 x 480 32bit Graphics Mode: 800 x 500 32bit Graphics Mode: 800 x 600 32bit Graphics Mode: 1024 x 640 32bit Graphics Mode: 1024 x 768 32bit Graphics Mode: 1152 x 720 32bit Graphics Mode: 1280 x 800 32bit Graphics Mode: 1344 x 840 32bit Graphics Mode: 1440 x 900 32bit SreenModeExists(640,480,32) = 1 glfwOpenWindow failed TRANS FAILED: Error executing './MonkeyGame', return code=65280 Done. Do I need to be using 71 to use the module? |
| ||
Thanks sonickidnextgen, glad to see you taking the initiative from your other thread :D jjsonick, thanks I have fixed this now on mac. Check the repo. Please update to version 71+ to be sure though. |
| ||
Great, it's working now! Tested fullscreen too. The only thing I notice now is that after doing a resolution change, the first pressing of space (to change again) is ignored - the first space key press is always ignored after a change, it always takes two (doesn't seem to be a matter of timing - happens even if I wait a while after a change). Donated for your efforts. :) |
| ||
Hey Joshua, Thanks for the donation :D Cheers for reporting this. Check the repo it is fixed now. |
| ||
You're my hero :D |
| ||
lol thanks mofo :D |
| ||
Great work Skn3! |
| ||
Nice work! I'll have a go at making images automagically survive the mode change, and after that probably adding a 'glfw' module or something. |
| ||
What would be great would be the ability to set this ahla BlitzMax/Blitz3d as the way of initialising the system/screen (ie. Graphics 800,600,32). But I guess that would then change the standard startup functionality of Monkey. The reason I make this point is that the Monkey initialises the screen then you override it with this. Having not (yet) played with this I'm assuming that's how it works looking at the example. |
| ||
> What would be great would be the ability to set this ahla BlitzMax/Blitz3d as the way of initialising the system/screen (ie. Graphics 800,600,32). I think this should be possible - perhaps setting GLFW_WINDOW_WIDTH/HEIGHT to 0 in CONFIG.TXT could prevent creation of initial window? |
| ||
Nice work! I'll have a go at making images automagically survive the mode change, and after that probably adding a 'glfw' module or something. Hurrah good to hear! |