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

The following examples show how to use org.lwjgl.opengl.Display#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: Example3_10.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void resized() {
	int w = Display.getWidth(), h = Display.getHeight();
	
	if(h == 0)
		h = 1;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	float aspect = (float)w / h;
	if(w <= h)
		glOrtho(-100, 100, -100 / aspect, 100 / aspect, 100, -100);
	else
		glOrtho(-100 * aspect, 100 * aspect, -100, 100, 100, -100);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
 
Example 2
Source File: Example3_11.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void resized() {
	int w = Display.getWidth(), h = Display.getHeight();
	
	if(h == 0)
		h = 1;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	float aspect = (float)w / h;
	if(w <= h)
		glOrtho(-100, 100, -100 / aspect, 100 / aspect, 100, -100);
	else
		glOrtho(-100 * aspect, 100 * aspect, -100, 100, 100, -100);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
 
Example 3
Source File: VideoHook.java    From malmo with MIT License 6 votes vote down vote up
/**
 * Resizes the window and the Minecraft rendering if necessary. Set renderWidth and renderHeight first.
 */
private void resizeIfNeeded()
{
    // resize the window if we need to
    int oldRenderWidth = Display.getWidth(); 
    int oldRenderHeight = Display.getHeight();
    if( this.renderWidth == oldRenderWidth && this.renderHeight == oldRenderHeight )
        return;
    
    try {
        int old_x = Display.getX();
        int old_y = Display.getY();
        Display.setLocation(old_x, old_y);
        Display.setDisplayMode(new DisplayMode(this.renderWidth, this.renderHeight));
        System.out.println("Resized the window");
    } catch (LWJGLException e) {
        System.out.println("Failed to resize the window!");
        e.printStackTrace();
    }
    forceResize(this.renderWidth, this.renderHeight);
}
 
Example 4
Source File: Example3_4.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void resized() {
	int w = Display.getWidth(), h = Display.getHeight();
	
	if(h == 0)
		h = 1;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	float aspect = (float)w / h;
	if(w <= h)
		glOrtho(-100, 100, -100 / aspect, 100 / aspect, 100, -100);
	else
		glOrtho(-100 * aspect, 100 * aspect, -100, 100, 100, -100);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
 
Example 5
Source File: Example2_3.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void resized() {
	int w = Display.getWidth(), h = Display.getHeight();
	
	if(h == 0)
		h = 1;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	float aspect = (float)w / h;
	if(w <= h) {
		width = 100;
		height = 100 / aspect;
	} else {
		width = 100 * aspect;
		height = 100;
	}
	
	glOrtho(-width, width, -height, height, 1, -1);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
 
Example 6
Source File: Example3_6.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void resized() {
	int w = Display.getWidth(), h = Display.getHeight();
	
	if(h == 0)
		h = 1;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	float aspect = (float)w / h;
	if(w <= h)
		glOrtho(-100, 100, -100 / aspect, 100 / aspect, 100, -100);
	else
		glOrtho(-100 * aspect, 100 * aspect, -100, 100, 100, -100);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
 
Example 7
Source File: WindowParamsPersistingApplicationWrapper.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
private void saveWindowParams() {
    int width = Display.getWidth();
    int height = Display.getHeight();
    int x = Display.getX();
    int y = Display.getY();

    //FIXME For some reason actual window position shifted by 6 pixels on Windows (by 12 at y when maximized).
    if (LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS) {
        x += 6;
        y += 6;
    }

    Preferences prefs = Gdx.app.getPreferences("window_params.xml");
    prefs.putInteger("x", x);
    prefs.putInteger("y", y);
    prefs.putInteger("width", width);
    prefs.putInteger("height", height);
    prefs.flush();
}
 
Example 8
Source File: Example3_2.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void resized() {
	int w = Display.getWidth(), h = Display.getHeight();
	
	if(h == 0)
		h = 1;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	float aspect = (float)w / h;
	if(w <= h)
		glOrtho(-100, 100, -100 / aspect, 100 / aspect, 100, -100);
	else
		glOrtho(-100 * aspect, 100 * aspect, -100, 100, 100, -100);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
 
Example 9
Source File: Example3_5.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void resized() {
	int w = Display.getWidth(), h = Display.getHeight();
	
	if(h == 0)
		h = 1;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	float aspect = (float)w / h;
	if(w <= h)
		glOrtho(-100, 100, -100 / aspect, 100 / aspect, 100, -100);
	else
		glOrtho(-100 * aspect, 100 * aspect, -100, 100, 100, -100);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
 
Example 10
Source File: Example2_2.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void resized() {
	int w = Display.getWidth(), h = Display.getHeight();
	
	if(h == 0)
		h = 1;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	float aspect = (float)w / h;
	if(w <= h)
		glOrtho(-100, 100, -100 / aspect, 100 / aspect, 1, -1);
	else
		glOrtho(-100 * aspect, 100 * aspect, -100, 100, 1, -1);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
 
Example 11
Source File: Example3_8.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void resized() {
	int w = Display.getWidth(), h = Display.getHeight();
	
	if(h == 0)
		h = 1;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	float aspect = (float)w / h;
	if(w <= h)
		glOrtho(-100, 100, -100 / aspect, 100 / aspect, 100, -100);
	else
		glOrtho(-100 * aspect, 100 * aspect, -100, 100, 100, -100);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
 
Example 12
Source File: Example3_13.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void resized() {
	int w = Display.getWidth(), h = Display.getHeight();
	
	if(h == 0)
		h = 1;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	float aspect = (float)w / h;
	if(w <= h)
		glOrtho(-100, 100, -100 / aspect, 100 / aspect, 100, -100);
	else
		glOrtho(-100 * aspect, 100 * aspect, -100, 100, 100, -100);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
 
Example 13
Source File: Camera.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
private static Matrix4f createProjectionMatrix() {
	Matrix4f projectionMatrix = new Matrix4f();
	float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
	float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))));
	float x_scale = y_scale / aspectRatio;
	float frustum_length = FAR_PLANE - NEAR_PLANE;

	projectionMatrix.m00 = x_scale;
	projectionMatrix.m11 = y_scale;
	projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
	projectionMatrix.m23 = -1;
	projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_length);
	projectionMatrix.m33 = 0;
	return projectionMatrix;
}
 
Example 14
Source File: DrawModelTest.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void resize()
{
	//final int range = 100;
	
	glViewport(0, 0, Display.getWidth(), Display.getHeight());
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	float aspect = Display.getWidth() / Display.getHeight();
    gluPerspective(25.0f, aspect, 1.0f, 300.0f);
	//glOrtho(-range, range, -range*Display.getHeight()/Display.getWidth(), range*Display.getHeight()/Display.getWidth(), -range, range);
	glMatrixMode(GL_MODELVIEW);
	glTranslatef(0,0, -50);
}
 
Example 15
Source File: RenderResolution.java    From Slyther with MIT License 5 votes vote down vote up
public RenderResolution() {
    int displayWidth = Display.getWidth();
    int displayHeight = Display.getHeight();

    while (displayWidth / (scale + 1.0F) >= BASE_WIDTH && displayHeight / (scale + 1.0F) >= BASE_HEIGHT) {
        scale++;
    }

    width = (int) Math.ceil(displayWidth / scale);
    height = (int) Math.ceil(displayHeight / scale);
}
 
Example 16
Source File: SlytherClient.java    From Slyther with MIT License 5 votes vote down vote up
private void setupDisplay() {
    int width = Display.getWidth();
    int height = Display.getHeight();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glScissor(0, 0, width, height);
    GL11.glViewport(0, 0, width, height);
    renderHandler.init();
}
 
Example 17
Source File: Camera.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
private static Matrix4f createProjectionMatrix() {
	Matrix4f projectionMatrix = new Matrix4f();
	float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
	float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))));
	float x_scale = y_scale / aspectRatio;
	float frustum_length = FAR_PLANE - NEAR_PLANE;

	projectionMatrix.m00 = x_scale;
	projectionMatrix.m11 = y_scale;
	projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
	projectionMatrix.m23 = -1;
	projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_length);
	projectionMatrix.m33 = 0;
	return projectionMatrix;
}
 
Example 18
Source File: GLRenderer.java    From amcgala with Educational Community License v2.0 4 votes vote down vote up
@Override
public int getWidth() {
    return Display.getWidth();
}
 
Example 19
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 20
Source File: GLProgram.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Returns the width of the window.
 * 
 * @return The width of the window.
 */
public int getWidth() {
	return Display.getWidth();
}