Display changing woes

Started by CodeBunny, March 19, 2011, 20:54:11

Previous topic - Next topic

CodeBunny

So, I've been changing the way I manage the Display to make it a little more robust. In short, I create the Display initially (windowed at 640x400), and then I use the following method to redefine the Display in the future:

public static void defineWindow(int width, int height, boolean fullscreen)
	{
		if ((Display.getDisplayMode().getWidth() == width) && (Display.getDisplayMode().getHeight() == height) &&
				(Display.isFullscreen() == fullscreen))
		{
			return;
		}

		try
		{
			DisplayMode targetDisplayMode = null;

			if (fullscreen)
			{
				if(width == 0 || height == 0)
				{
					width = (int) Display.getDesktopDisplayMode().getWidth();
					height = (int) Display.getDesktopDisplayMode().getHeight();
				}
				
				DisplayMode[] modes = Display.getAvailableDisplayModes();
				int freq = 0;

				for (int i=0;i<modes.length;i++)
				{
					DisplayMode current = modes[i];

					if ((current.getWidth() == width) && (current.getHeight() == height))
					{
						if ((targetDisplayMode == null) || (current.getFrequency() >= freq))
						{
							if ((targetDisplayMode == null) || 
									(current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel()))
							{
								targetDisplayMode = current;
								freq = targetDisplayMode.getFrequency();
							}
						}

						// if we've found a match for bpp and frequence 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
			{
				targetDisplayMode = new DisplayMode(width, height);
			}

			if (targetDisplayMode == null)
			{
				System.err.println("The desired window size is unavailable, we'll try to make do!");
				targetDisplayMode = getClosestWindowSize(width, height);
			}

			Display.setDisplayMode(targetDisplayMode);
			Display.setFullscreen(fullscreen);

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


This is mostly the same as in the tutorial, but I've modified it to find the nearest possible dimensions if the specified ones aren't available, instead of crashing. Also, if a width or height of 0 is supplied in fullscreen mode, the method creates a display at full resolution.  These particular features are working.

The problem is that the portion of the screen being rendered stays at the initial resolution, 640x400, and is contained at the bottom left of the screen:



Based on a couple of tests, this seems related to my settings with glOrtho. My first tests have changed what's being shown, but not the way it's constrained to that portion of the screen.

How can I fix this?

Mickelukas

It seems to me like you forget to set the GL11.glViewport to the correct values after the change.

Mike

CodeBunny

Ah, of course. Thank you very much, it's all working now.