Rebuilding Display

Hi,

I’m wanting to give the ability to dynamically change things such as resolution, depth and Screen title. I’ve tried changing the parameters, calling Display.destroy() and then Display.create() with the new parameters. It appears to MOSTLY work, ie the screen changes to reflect these new values, but there is not longer any rendering being done and the Keyboard class no longer responds to keyboard input. Any ideas?

Thank you,
Mark

Just a thought, but have you tried recreating the GL context and recalling create() on the keyboard?

Yes, I tried that. Here’s a code snippet:


if (Keyboard.key == Keyboard.KEY_0) {
                DisplaySystem.getDisplaySystem().setResolution(1024,768);
                try{
                    Keyboard.create();
                    Keyboard.enableBuffer();
                } catch (Exception e) {
                    LoggingSystem.getLoggingSystem().getLogger().log(Level.WARNING,
                            "Lost Keyboard");
                }

where in the DisplaySystem class we have:


 //recreate the display
        Display.destroy();
        initDisplay();
        initGL();

where init display calls Display.create and initGL call gl.create.

Mark

did you do a gl.destroy() too?

  • elias

No, I didn’t. But I added it, and there was no change.

Does any of the lwjgl examples work for you?

  • elias

All the examples run fine. LWJGL runs great for me, and I have been having a wonderful time using it. It’s only the one problem of switching resolutions while running that I need to take care of. Is there a specific example that changes resolution that you want me to look at?

Some of the mouse creation/test examples destroy and recreate the display several times, they should be doing what you’re after.

Fixed. Had two problems: First I wasn’t destroying the keyboard before recreating it. Secondly, I wasn’t initializing the rendering states, i.e. setting the viewport, etc. Thanks for all the help!

As changing resolution, bit depth etc on the fly is something I expect a lot of people would be interested in, there should probably be an example to do just that.

That’s a really cool feature of the library that should be advertised!

By the way, there are tricks you need to pull in MFC to let display lists etc survive a context rebuild. How does LWJGL handle that? Is there a cross-platform way of doing it, or is it better to just force people to rebuild all GL-held assets etc after recreating the GL context?

I removed my fullscreen/windowed switch method when I noticed I had to upload all textures etc again when I destroyed the context and created a new one…

Heh, Yeah, that’s exactly what led to my descovery of my problem with my TextureManager deletion. I added a method to the texture manager to “refresh” all textures. Which really means reload all of them when the gl object is recreated.