Java Code Examples for org.lwjgl.opengl.Display#setFullscreen()

The following examples show how to use org.lwjgl.opengl.Display#setFullscreen() . 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: LwJglRenderingEngine.java    From Gaalop with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * Starts the lwjgl engine and shows a window, where the point clouds are rendered
 */
public void startEngine() {
    int width = 800;
    int height = 600;
    
    try {
        Display.setDisplayMode(new DisplayMode(width, height));
        Display.setFullscreen(false);
        Display.setTitle("Gaalop Visualization Window");

        Display.create();
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(0);
    }
    
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    changeSize(width, height);
    GL11.glDisable(GL11.GL_LIGHTING);


    // init OpenGL
    GL11.glViewport(0, 0, width, height);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GLU.gluPerspective((float) 65.0, (float) width / (float) height, (float) 0.1, 100);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    
    
}
 
Example 2
Source File: HyperiumMinecraft.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void displayFix(CallbackInfo ci, boolean fullscreen, int displayWidth, int displayHeight)
    throws LWJGLException {
    Display.setFullscreen(false);
    if (fullscreen) {
        if (Settings.WINDOWED_FULLSCREEN) {
            System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");
        } else {
            Display.setFullscreen(true);
            DisplayMode displaymode = Display.getDisplayMode();
            parent.displayWidth = Math.max(1, displaymode.getWidth());
            parent.displayHeight = Math.max(1, displaymode.getHeight());
        }
    } else {
        if (Settings.WINDOWED_FULLSCREEN) {
            System.setProperty("org.lwjgl.opengl.Window.undecorated", "false");
        } else {
            Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
        }
    }

    Display.setResizable(false);
    Display.setResizable(true);

    // effectively overwrites the method
    ci.cancel();
}
 
Example 3
Source File: HyperiumMinecraft.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void fullScreenFix(boolean fullscreen, int displayWidth, int displayHeight) throws LWJGLException {
    if (Settings.WINDOWED_FULLSCREEN) {
        if (fullscreen) {
            System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");
            Display.setDisplayMode(Display.getDesktopDisplayMode());
            Display.setLocation(0, 0);
            Display.setFullscreen(false);
        } else {
            System.setProperty("org.lwjgl.opengl.Window.undecorated", "false");
            Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
        }
    } else {
        Display.setFullscreen(fullscreen);
        System.setProperty("org.lwjgl.opengl.Window.undecorated", "false");
    }

    Display.setResizable(false);
    Display.setResizable(true);
}
 
Example 4
Source File: AppGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Indicate whether we want to be in fullscreen mode. Note that the current
 * display mode must be valid as a fullscreen mode for this to work
 * 
 * @param fullscreen True if we want to be in fullscreen mode
 * @throws SlickException Indicates we failed to change the display mode
 */
public void setFullscreen(boolean fullscreen) throws SlickException {
	if (isFullscreen() == fullscreen) {
		return;
	}
	
	if (!fullscreen) {
		try {
			Display.setFullscreen(fullscreen);
		} catch (LWJGLException e) {
			throw new SlickException("Unable to set fullscreen="+fullscreen, e);
		}
	} else {
		setDisplayMode(width, height, fullscreen);
	}
	getDelta();
}
 
Example 5
Source File: Window.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
public void setResolution(DisplayMode resolution, boolean fullscreen) {
	try {
		Display.setDisplayMode(resolution);
		this.resolution = resolution;
		if (fullscreen && resolution.isFullscreenCapable()) {
			Display.setFullscreen(true);
			this.fullScreen = fullscreen;
		}
	} catch (LWJGLException e) {
		e.printStackTrace();
	}
}
 
Example 6
Source File: LocalInput.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public static final void toggleFullscreen() {
	fullscreen = !fullscreen;
	try {
		Display.setFullscreen(fullscreen && !LocalEventQueue.getQueue().getDeterministic().isPlayback());
		Renderer.resetInput();
	} catch (LWJGLException e) {
		System.out.println("Mode switching failed with exception: " + e);
		throw new RuntimeException("Mode switching failed");
	}
}
 
Example 7
Source File: GLProgram.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initializes the application in fullscreen mode.
 * 
 * @param vsync Enables/disables the vertical-sync feature, where the rendering is in sync with the monitor's refresh rate.
 *        With v-sync off, there is no framerate cap and the gameloop will run as fast as the hardware can handle.
 *        A framerate can be set with the <code>setFPS(int fps)</code> method.
 */
public GLProgram(boolean vsync) {
	try {
		Display.setFullscreen(true);
		Display.setVSyncEnabled(vsync);
	} catch(Exception exc) {
		exc.printStackTrace();
	}
}
 
Example 8
Source File: ClientProxy.java    From Fullscreen-Windowed-Minecraft with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void toggleFullScreen(boolean goFullScreen, int desiredMonitor) {

    //Set value if it isn't set already.
    if(System.getProperty("org.lwjgl.opengl.Window.undecorated") == null){
        System.setProperty("org.lwjgl.opengl.Window.undecorated", "false");
    }

    //If we're in actual fullscreen right now, then we need to fix that.
    if(Display.isFullscreen()) {
        fullscreen = true;
    }

    String expectedState = goFullScreen ? "true":"false";
    // If all state is valid, there is nothing to do and we just exit.
    if(fullscreen == goFullScreen
            && !Display.isFullscreen()//Display in fullscreen mode: Change required
            && System.getProperty("org.lwjgl.opengl.Window.undecorated") == expectedState // Window not in expected state
    )
        return;

    //Save our current display parameters
    Rectangle currentCoordinates = new Rectangle(Display.getX(), Display.getY(), Display.getWidth(), Display.getHeight());
    if(goFullScreen && !Display.isFullscreen())
        _savedWindowedBounds = currentCoordinates;

    //Changing this property and causing a Display update will cause LWJGL to add/remove decorations (borderless).
    System.setProperty("org.lwjgl.opengl.Window.undecorated",expectedState);

    //Get the fullscreen dimensions for the appropriate screen.
    Rectangle screenBounds = getAppropriateScreenBounds(currentCoordinates, desiredMonitor);

    //This is the new bounds we have to apply.
    Rectangle newBounds = goFullScreen ? screenBounds : _savedWindowedBounds;
    if(newBounds == null)
        newBounds = screenBounds;

    if(goFullScreen == false && ClientProxy.fullscreen == false) {
        newBounds = currentCoordinates;
        _savedWindowedBounds = currentCoordinates;
    }

    try {
        fullscreen = goFullScreen;
        client.fullscreen = fullscreen;
        if( client.gameSettings.fullScreen != fullscreen) {
            client.gameSettings.fullScreen = fullscreen;
            client.gameSettings.saveOptions();
        }
        Display.setFullscreen(false);
        Display.setResizable(!goFullScreen);
        Display.setDisplayMode(new DisplayMode((int) newBounds.getWidth(), (int) newBounds.getHeight()));
        Display.setLocation(newBounds.x, newBounds.y);

        client.resize((int) newBounds.getWidth(), (int) newBounds.getHeight());
        Display.setVSyncEnabled(client.gameSettings.enableVsync);
        client.updateDisplay();

    } catch (LWJGLException e) {
        e.printStackTrace();
    }

}
 
Example 9
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setFullscreen(boolean fullscreen) throws SlickException {
   if (fullscreen == isFullscreen()) {
      return;
   }

   try {
      if (fullscreen) {
         // get current screen resolution
         int screenWidth = Display.getDisplayMode().getWidth();
         int screenHeight = Display.getDisplayMode().getHeight();

         // calculate aspect ratio
         float gameAspectRatio = (float) width / height;
         float screenAspectRatio = (float) screenWidth
               / screenHeight;

         int newWidth;
         int newHeight;

         // get new screen resolution to match aspect ratio

         if (gameAspectRatio >= screenAspectRatio) {
            newWidth = screenWidth;
            newHeight = (int) (height / ((float) width / screenWidth));
         } else {
            newWidth = (int) (width / ((float) height / screenHeight));
            newHeight = screenHeight;
         }

         // center new screen
         int xoffset = (screenWidth - newWidth) / 2;
         int yoffset = (screenHeight - newHeight) / 2;

         // scale game to match new resolution
         GL11.glViewport(xoffset, yoffset, newWidth, newHeight);

         enterOrtho();

         // fix input to match new resolution
         this.getInput().setOffset(
               -xoffset * (float) width / newWidth,
               -yoffset * (float) height / newHeight);

         this.getInput().setScale((float) width / newWidth,
               (float) height / newHeight);

         width = screenWidth;
         height = screenHeight;
         Display.setFullscreen(true);
      } else {
         // restore input
         this.getInput().setOffset(0, 0);
         this.getInput().setScale(1, 1);
         width = AppletGameContainer.this.getWidth();
         height = AppletGameContainer.this.getHeight();
         GL11.glViewport(0, 0, width, height);

         enterOrtho();

         Display.setFullscreen(false);
      }
   } catch (LWJGLException e) {
      Log.error(e);
   }

}