Java Code Examples for org.lwjgl.opengl.Display

The following examples show how to use org.lwjgl.opengl.Display. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Start a thread to run LWJGL in
 */
public void startLWJGL() {
   if (gameThread != null) {
      return;
   }
   
   gameThread = new Thread() {
      public void run() {
         try {
            canvas.start();
         }
         catch (Exception e) {
            e.printStackTrace();
            if (Display.isCreated()) {
               Display.destroy();
            }
            displayParent.setVisible(false);//removeAll();
            add(new ConsolePanel(e));
            validate();
         }
      }
   };
   
   gameThread.start();
}
 
Example 2
public void update(GameContainer container, int delta)
		throws SlickException {
	if (!paused) {
		ypos += delta * 0.002 * systemMove;
		if (ypos > 300) {
			ypos = -300;
		}
		if (ypos < -300) {
			ypos = 300;
		}

		for (int i = 0; i < emitters.size(); i++) {
			((ConfigurableEmitter) emitters.get(i)).replayCheck();
		}
		for (int i = 0; i < delta; i++) {
			system.update(1);
		}
	}

	Display.sync(100);
}
 
Example 3
/**
 * Start the game container
 * 
 * @throws Exception Failure to create display
 */
public void start() throws Exception {
   Display.setParent(displayParent);
   Display.setVSyncEnabled(true);
   
   try {
      createDisplay();
   } catch (LWJGLException e) {
      e.printStackTrace();
      // failed to create Display, apply workaround (sleep for 1 second) and try again
      Thread.sleep(1000);
      createDisplay();
   }
   
   initGL();
   displayParent.requestFocus();
   container.runloop();
}
 
Example 4
Source Project: FEMultiplayer   Source File: LevelEditor.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void loop() {
	while(!Display.isCloseRequested()) {
		time = System.nanoTime();
		glClear(GL_COLOR_BUFFER_BIT |
		        GL_DEPTH_BUFFER_BIT |
		        GL_STENCIL_BUFFER_BIT);
		glClearDepth(1.0f);
		getInput();
		glPushMatrix();
		if(!paused) {
			currentStage.beginStep();
			currentStage.onStep();
			currentStage.processAddStack();
			currentStage.processRemoveStack();
			Renderer.getCamera().lookThrough();
			currentStage.render();
			currentStage.endStep();
		}
		glPopMatrix();
		Display.update();
		timeDelta = System.nanoTime()-time;
	}
	AL.destroy();
	Display.destroy();
}
 
Example 5
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 6
protected void printContextInitInfo(){
    logger.log(Level.FINE, "Running on thread: {0}", Thread.currentThread().getName());

    logger.log(Level.INFO, "Adapter: {0}", Display.getAdapter());
    logger.log(Level.INFO, "Driver Version: {0}", Display.getVersion());

    String vendor = GL11.glGetString(GL11.GL_VENDOR);
    logger.log(Level.INFO, "Vendor: {0}", vendor);

    String version = GL11.glGetString(GL11.GL_VERSION);
    logger.log(Level.INFO, "OpenGL Version: {0}", version);

    String renderGl = GL11.glGetString(GL11.GL_RENDERER);
    logger.log(Level.INFO, "Renderer: {0}", renderGl);

    if (GLContext.getCapabilities().OpenGL20){
        String shadingLang = GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION);
        logger.log(Level.INFO, "GLSL Ver: {0}", shadingLang);
    }
}
 
Example 7
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 8
Source Project: tribaltrouble   Source File: Renderer.java    License: GNU General Public License v2.0 6 votes vote down vote up
private final void initVisibleGL() {
	if (Settings.getSettings().fullscreen_depth_workaround) {
		IntBuffer dummy_buf = BufferUtils.createIntBuffer(1);
		GL11.glReadPixels(0, 0, 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_UNSIGNED_INT, dummy_buf);
	}

	FloatBuffer float_array = BufferUtils.createFloatBuffer(4);
	GL11.glEnable(GL11.GL_LIGHT0);
	float[] light_diff_color = {1.0f, 1.0f, 1.0f, 1.0f};
	float_array.put(light_diff_color);
	float_array.rewind();
	GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, float_array);
	GL11.glLightModeli(GL11.GL_LIGHT_MODEL_LOCAL_VIEWER, 1);

	float[] global_ambient = {0.65f, 0.65f, 0.65f, 1.0f};
	float_array.put(global_ambient);
	float_array.rewind();
	GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, float_array);
	float[] material_color = {1.0f, 1.0f, 1.0f, 1.0f};
	float_array.put(material_color);
	float_array.rewind();
	GL11.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE, float_array);
	Display.update();
}
 
Example 9
Source Project: uracer-kotd   Source File: URacerDesktopFinalizer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void dispose () {
	boot.load();
	boot.setWindowX(Display.getX());
	boot.setWindowY(Display.getY());
	boot.store();

	// destroy display
	Display.destroy();

	// destroy audio, if any
	if (this.audio != null) {
		this.audio.dispose();
		this.audio = null;
	}
}
 
Example 10
/**
 * Start the test 
 */
public void start() {
	initGL(800,600);
	init();
	
	while (true) {
		update();
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
		render();
		
		Display.update();
		Display.sync(100);

		if (Display.isCloseRequested()) {
			System.exit(0);
		}
	}
}
 
Example 11
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 Project: OpenGL-Animation   Source File: DisplayManager.java    License: The Unlicense 6 votes vote down vote up
public static void createDisplay() {
	try {
		Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
		ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true);
		Display.create(new PixelFormat().withDepthBits(24).withSamples(4), attribs);
		Display.setTitle(TITLE);
		Display.setInitialBackground(1, 1, 1);
		GL11.glEnable(GL13.GL_MULTISAMPLE);
	} catch (LWJGLException e) {
		e.printStackTrace();
		System.err.println("Couldn't create display!");
		System.exit(-1);
	}
	GL11.glViewport(0, 0, WIDTH, HEIGHT);
	lastFrameTime = getCurrentTime();
}
 
Example 13
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 14
Source Project: malmo   Source File: VideoHook.java    License: 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 15
private Rectangle findCurrentScreenDimensionsAndPosition(int x, int y)
    {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] screens = env.getScreenDevices();

        for(GraphicsDevice dev : screens)
        {
            GraphicsConfiguration displayMode = dev.getDefaultConfiguration();
            Rectangle bounds = displayMode.getBounds();

            if(bounds.contains(x, y))
                return bounds;
        }

        //if Java isn't able to find a matching screen then use the old LWJGL calcs.
        return new Rectangle(0, 0, Display.getDesktopDisplayMode().getWidth(), Display.getDesktopDisplayMode().getHeight());
}
 
Example 16
private final static void createWindow() throws LWJGLException {
	int[] depth_array = new int[]{24, 16};
	int[] samples_array = new int[]{/*Settings.getSettings().samples, */0};
	LWJGLException last_exception = new LWJGLException("Could not find a suitable pixel format");
	for (int d = 0; d < depth_array.length; d++)
		for (int s = 0; s < samples_array.length; s++) {
			int depth = depth_array[d];
			int samples = samples_array[s];
			try {
				Display.create(new PixelFormat(0, depth, 0, samples));
				return;
			} catch (LWJGLException e) {
				last_exception = e;
				System.out.println("Failed window: depthbits = " + depth + " | samples = " + samples + " with exception " + e);
			}
		}
	throw last_exception;
}
 
Example 17
/**
 * Initialise the PBuffer that will be used to render to
 * 
 * @throws SlickException
 */
private void init() throws SlickException {
	try {
		Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter());

		pbuffer = new Pbuffer(screenWidth, screenHeight, new PixelFormat(8, 0, 0), null, null);
		// Initialise state of the pbuffer context.
		pbuffer.makeCurrent();

		initGL();
		image.draw(0,0);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID());
		GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 0, 0, 
							  tex.getTextureWidth(), 
							  tex.getTextureHeight(), 0);
		image.setTexture(tex);
		
		Display.makeCurrent();
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?");
	}
}
 
Example 18
Source Project: opsu   Source File: GameRanking.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void enter(GameContainer container, StateBasedGame game)
		throws SlickException {
	UI.enter();
	Display.setTitle(game.getTitle());
	if (!data.isGameplay()) {
		if (!MusicController.isTrackDimmed())
			MusicController.toggleTrackDimmed(0.5f);
		replayButton.setY(retryY);
		animationProgress.setTime(animationProgress.getDuration());
	} else {
		SoundController.playSound(SoundEffect.APPLAUSE);
		retryButton.resetHover();
		if (GameMod.AUTO.isActive()) {
			replayButton.setY(retryY);
			animationProgress.setTime(animationProgress.getDuration());
		} else {
			replayButton.setY(replayY);
			animationProgress.setTime(0);
		}
	}
	replayButton.resetHover();
	loadReplay();
}
 
Example 19
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 20
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 21
Source Project: The-5zig-Mod   Source File: GuiListChat.java    License: MIT License 5 votes vote down vote up
/**
 * Handle Mouse Input
 */
@Override
public void handleMouseInput() {
	super.handleMouseInput();

	if (!Display.isActive()) // Don't allow multiple URL-Clicks if Display is not focused.
		return;

	int mouseX = this.i;
	int mouseY = this.j;

	if (this.g(mouseY)) {
		if (Mouse.isButtonDown(0) && this.q()) {
			int y = mouseY - this.d - this.t + (int) this.n - 4;
			int id = -1;
			int minY = -1;
			// Search for the right ChatLine-ID
			for (int i1 = 0; i1 < heightMap.size(); i1++) {
				Integer integer = heightMap.get(i1);
				Row line = rows.get(i1);
				if (y >= integer - 2 && y <= integer + line.getLineHeight() - 2) {
					id = i1;
					minY = integer;
					break;
				}
			}

			if (id < 0 || id >= rows.size())
				return;

			callback.chatLineClicked(rows.get(id), mouseX, y, minY, getLeft());
		}
	}
}
 
Example 22
private final static void nativeSetMode(DisplayMode mode) throws LWJGLException {
		if (!Display.getDisplayMode().equals(mode)) {
System.out.println("setting mode = " + mode);
			Display.setDisplayMode(mode);
			Renderer.resetInput();
		}
	}
 
Example 23
Source Project: tribaltrouble   Source File: LocalInput.java    License: 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 24
Source Project: tribaltrouble   Source File: Main.java    License: GNU General Public License v2.0 5 votes vote down vote up
public final static void fail(Throwable t) {
	try {
		t.printStackTrace();
		if (Display.isCreated())
			Display.destroy();
		while (t.getCause() != null)
			t = t.getCause();
		ResourceBundle bundle = ResourceBundle.getBundle(Main.class.getName());
		String error = Utils.getBundleString(bundle, "error");
		String error_msg = Utils.getBundleString(bundle, "error_message", new Object[]{t.toString(), Globals.SUPPORT_ADDRESS});
		Sys.alert(error, error_msg);
	} finally {
		shutdown();
	}
}
 
Example 25
Source Project: The-5zig-Mod   Source File: GuiListChat.java    License: MIT License 5 votes vote down vote up
/**
 * Handle Mouse Input
 */
@Override
public void handleMouseInput() {
	super.handleMouseInput();

	if (!Display.isActive()) // Don't allow multiple URL-Clicks if Display is not focused.
		return;

	int mouseX = this.i;
	int mouseY = this.j;

	if (this.g(mouseY)) {
		if (Mouse.isButtonDown(0) && this.q()) {
			int y = mouseY - this.d - this.t + (int) this.n - 4;
			int id = -1;
			int minY = -1;
			// Search for the right ChatLine-ID
			for (int i1 = 0; i1 < heightMap.size(); i1++) {
				Integer integer = heightMap.get(i1);
				Row line = rows.get(i1);
				if (y >= integer - 2 && y <= integer + line.getLineHeight() - 2) {
					id = i1;
					minY = integer;
					break;
				}
			}

			if (id < 0 || id >= rows.size())
				return;

			callback.chatLineClicked(rows.get(id), mouseX, y, minY, getLeft());
		}
	}
}
 
Example 26
Source Project: The-5zig-Mod   Source File: GuiListChat.java    License: MIT License 5 votes vote down vote up
/**
 * Handle Mouse Input
 */
@Override
public void handleMouseInput() {
	super.handleMouseInput();

	if (!Display.isActive()) // Don't allow multiple URL-Clicks if Display is not focused.
		return;

	int mouseX = this.i;
	int mouseY = this.j;

	if (this.g(mouseY)) {
		if (Mouse.isButtonDown(0) && this.q()) {
			int y = mouseY - this.d - this.t + (int) this.n - 4;
			int id = -1;
			int minY = -1;
			// Search for the right ChatLine-ID
			for (int i1 = 0; i1 < heightMap.size(); i1++) {
				Integer integer = heightMap.get(i1);
				Row line = rows.get(i1);
				if (y >= integer - 2 && y <= integer + line.getLineHeight() - 2) {
					id = i1;
					minY = integer;
					break;
				}
			}

			if (id < 0 || id >= rows.size())
				return;

			callback.chatLineClicked(rows.get(id), mouseX, y, minY, getLeft());
		}
	}
}
 
Example 27
Source Project: The-5zig-Mod   Source File: GuiListChat.java    License: MIT License 5 votes vote down vote up
/**
 * Handle Mouse Input
 */
@Override
public void handleMouseInput() {
	super.handleMouseInput();

	if (!Display.isActive()) // Don't allow multiple URL-Clicks if Display is not focused.
		return;

	int mouseX = getMouseX();
	int mouseY = getMouseY();

	if (this.isMouseYWithinSlotBounds(mouseY)) {
		if (Mouse.isButtonDown(0) && this.i()) {
			int y = mouseY - getRight() - this.j + (int) getCurrentScroll() - 4;
			int id = -1;
			int minY = -1;
			// Search for the right ChatLine-ID
			for (int i1 = 0; i1 < heightMap.size(); i1++) {
				Integer integer = heightMap.get(i1);
				Row line = rows.get(i1);
				if (y >= integer - 2 && y <= integer + line.getLineHeight() - 2) {
					id = i1;
					minY = integer;
					break;
				}
			}

			if (id < 0 || id >= rows.size())
				return;

			callback.chatLineClicked(rows.get(id), mouseX, y, minY, getLeft());
		}
	}
}
 
Example 28
protected void destroyContext(){
    try {
        renderer.cleanup();
        Display.releaseContext();
        Display.destroy();
    } catch (LWJGLException ex) {
        listener.handleError("Failed to destroy context", ex);
    }
}
 
Example 29
Source Project: FEMultiplayer   Source File: Game.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void init(int width, int height, String name) {
	time = System.nanoTime();
	
	windowWidth = width*scaleX;
	windowHeight = height*scaleY;

	try {
		Display.setDisplayMode(new DisplayMode(windowWidth, windowHeight));
		Display.create();
		Display.setTitle(name);
		Keyboard.create();
		Keyboard.enableRepeatEvents(true);
		Mouse.create();
		glContextExists = true;
	} catch (LWJGLException e) {
		e.printStackTrace();
		System.exit(0);
	}
	
	//init OpenGL
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0.01f);
	glEnable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);
	glClearDepth(1.0f);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glViewport(0, 0, windowWidth, windowHeight);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, windowWidth/scaleX, windowHeight/scaleY, 0, 1, -1);		//It's basically a camera
	glMatrixMode(GL_MODELVIEW);
	
	keys = new ArrayList<KeyboardEvent>();
	mouseEvents = new ArrayList<MouseEvent>();
}
 
Example 30
private final static void doSetMode(SerializableDisplayMode target_mode) throws LWJGLException {
	DisplayMode[] lwjgl_modes = Display.getAvailableDisplayModes();
	for (int i = 0; i < lwjgl_modes.length; i++) {
		DisplayMode lwjgl_mode = lwjgl_modes[i];
		SerializableDisplayMode mode = new SerializableDisplayMode(lwjgl_mode);
		if (mode.equals(target_mode)) {
			nativeSetMode(lwjgl_mode);
			GL11.glViewport(0, 0, lwjgl_mode.getWidth(), lwjgl_mode.getHeight());
			return;
		}
	}
	throw new LWJGLException("Could not find mode matching: " + target_mode);
}