LWJGL DisplayMode Change

Hey, I’m changing the DisplayMode of my Display while rendering (Like in an Options Menu) with Display.setDisplayMode(dm);
The Problem i get from this is, that the Gui I have doesn’t get resized so that it fits the Display, it just stays at it’s previous size (800x600 by default).
If i set some other DisplayMode at the beginning it works fine but when I change it while the Display is created it just gets messed up.

my init Code:


		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glLoadIdentity();
		GL11.glOrtho(0, 800, 0, 600, -1, 1);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		GL11.glLoadIdentity();

and when i change the displaymode and render a white Quad (0,0,800,600) it shows up like this:

Any ideas how to fix it?

Edit: after Changing the DisplayMode calling GL11.glViewPort(0,0,Display.getWidth(),Display.getHeight); fixed it :smiley:

btw, that blue color is my clear color :smiley:

I use this and it works fine for me.


if (isKeyDown(KEY_F) && !isKeyDown(KEY_LSHIFT))
    setDisplayMode(1600, 900, true);
        
if (isKeyDown(KEY_F) && isKeyDown(KEY_LSHIFT))
    setDisplayMode(800, 600, false);

And the method [icode]setDisplayMode()[/icode] is


public static boolean setDisplayMode(int width, int height, boolean fullscreen)
{
    // return if requested DisplayMode is already set
    if ((Display.getDisplayMode().getWidth() == width) && (Display.getDisplayMode().getHeight() == height) && (Display.isFullscreen() == fullscreen))
        return true;

    try
    {
        // The target DisplayMode
        DisplayMode targetDisplayMode = null;

        if (fullscreen)
        {
            // Gather all the DisplayModes available at fullscreen
            DisplayMode[] modes = Display.getAvailableDisplayModes();
            int freq = 0;

            // Iterate through all of them
            for (DisplayMode current: modes)
            {
                // Make sure that the width and height matches
                if ((current.getWidth() == width) && (current.getHeight() == height))
                {
                    // Select the one with greater frequency
                    if ((targetDisplayMode == null) || (current.getFrequency() >= freq))
                    {
                        // Select the one with greater bits per pixel
                        if ((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel()))
                        {
                            targetDisplayMode = current;
                            freq = targetDisplayMode.getFrequency();
                        }
                    }

                    // if we've found a match for bpp and frequency against the
                    // original display mode then it's probably best to go for
                    // this one since it's most likely compatible with the monitor
                    if ((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel()) && (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency()))
                    {
                        targetDisplayMode = current;
                        break;
                    }
                }
            }
        }
        else
        {
            // No need to query for windowed mode
            targetDisplayMode = new DisplayMode(width, height);
        }

        if (targetDisplayMode == null)
        {
            System.out.println("Failed to find value mode: " + width + "x" + height + " fs=" + fullscreen);
            return false;
        }

        // Set the DisplayMode we've found
        Display.setDisplayMode(targetDisplayMode);
        Display.setFullscreen(fullscreen);

        System.out.println("Selected DisplayMode: " + targetDisplayMode.toString());

        // Generate a resized event
        instance.resized();

        return true;
    }
    catch (LWJGLException e)
    {
        System.out.println("Unable to setup mode " + width + "x" + height + " fullscreen=" + fullscreen + e);
    }

    return false;
}

Hope this helps.

Tested that, didn’t work :confused: though what is that “instance.resized” ? what does it do?

Instance is the reference to the game. Resized is a method that is called whenever the display size changes.

Can you tell me, what that method does? cause the code without that method isn’t working (results in the same)

It just resets the viewport settings.

ah ok, Thx :smiley: