Java Code Examples for org.lwjgl.opengl.DisplayMode#getWidth()

The following examples show how to use org.lwjgl.opengl.DisplayMode#getWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Window.java    From LowPolyWater with The Unlicense 6 votes vote down vote up
protected Window(Context context, WindowBuilder settings) {
	this.fpsCap = settings.getFpsCap();
	try {
		getSuitableFullScreenModes();
		DisplayMode resolution = getStartResolution(settings);
		Display.setInitialBackground(1, 1, 1);
		this.aspectRatio = (float) resolution.getWidth() / resolution.getHeight();
		setResolution(resolution, settings.isFullScreen());
		if (settings.hasIcon()) {
			Display.setIcon(settings.getIcon());
		}
		Display.setVSyncEnabled(settings.isvSync());
		Display.setTitle(settings.getTitle());
		Display.create(new PixelFormat().withDepthBits(24).withSamples(4), context.getAttribs());
		GL11.glViewport(0, 0, resolution.getWidth(), resolution.getHeight());
	} catch (LWJGLException e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: GLHelper.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * from org.newdawn.slick.AppGameContainer#setDisplayMode
 */
public static DisplayMode findFullscreenDisplayMode(int targetBPP, int targetFrequency, int width, int height) throws LWJGLException {
	DisplayMode[] modes = Display.getAvailableDisplayModes();
	DisplayMode foundMode = null;
	int freq = 0;
	int bpp = 0;

	for (DisplayMode current : modes) {
		if (current.getWidth() != width || current.getHeight() != height) {
			continue;
		}

		if (current.getBitsPerPixel() == targetBPP && current.getFrequency() == targetFrequency) {
			return current;
		}

		if (current.getFrequency() >= freq && (foundMode == null || current.getBitsPerPixel() >= bpp)) {
			foundMode = current;
			freq = foundMode.getFrequency();
			bpp = foundMode.getBitsPerPixel();
		}
	}
	return foundMode;
}
 
Example 3
Source File: LwjglDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected DisplayMode getFullscreenDisplayMode(int width, int height, int bpp, int freq){
    try {
        DisplayMode[] modes = Display.getAvailableDisplayModes();
        for (DisplayMode mode : modes){
            if (mode.getWidth() == width
             && mode.getHeight() == height
             && (mode.getBitsPerPixel() == bpp || (bpp==24&&mode.getBitsPerPixel()==32))
             && mode.getFrequency() == freq){
                return mode;
            }
        }
    } catch (LWJGLException ex) {
        listener.handleError("Failed to acquire fullscreen display mode!", ex);
    }
    return null;
}
 
Example 4
Source File: Window.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
private boolean isSuitableFullScreenResolution(DisplayMode resolution, DisplayMode desktopResolution) {
	if (resolution.getBitsPerPixel() == desktopResolution.getBitsPerPixel()) {
		if (resolution.getFrequency() == desktopResolution.getFrequency()) {
			float desktopAspect = (float) desktopResolution.getWidth() / desktopResolution.getHeight();
			float resAspect = (float) resolution.getWidth() / resolution.getHeight();
			float check = resAspect / desktopAspect;
			if (check > 0.95f && check < 1.05f) {
				return resolution.getHeight() > MIN_HEIGHT;
			}
		}
	}
	return false;
}
 
Example 5
Source File: Window.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
private DisplayMode getFullScreenDisplayMode(int width, int height) {
	for (DisplayMode potentialMode : availableResolutions) {
		if (potentialMode.getWidth() == width && potentialMode.getHeight() == height) {
			return potentialMode;
		}
	}
	return null;
}
 
Example 6
Source File: Options.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/** Returns whether this resolution is possible to use in fullscreen mode. */
public boolean hasFullscreenDisplayMode() {
	try {
		for (DisplayMode mode : Display.getAvailableDisplayModes()) {
			if (width == mode.getWidth() && height == mode.getHeight())
				return true;
		}
	} catch (LWJGLException e) {
		ErrorHandler.error("Failed to get available display modes.", e, true);
	}
	return false;
}
 
Example 7
Source File: SerializableDisplayMode.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public SerializableDisplayMode(DisplayMode mode) {
	this(mode.getWidth(), mode.getHeight(), mode.getBitsPerPixel(), mode.getFrequency());
}
 
Example 8
Source File: SerializableDisplayMode.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public final static boolean isModeValid(DisplayMode mode) {
	return mode.getWidth() >= 800 && mode.getHeight() >= 600;
}