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

The following examples show how to use org.lwjgl.opengl.Display#isCreated() . 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: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 5 votes vote down vote up
private void exitOnGLError(String errorMessage) {
    int errorValue = GL11.glGetError();
     
    if (errorValue != GL11.GL_NO_ERROR) {
        String errorString = GLU.gluErrorString(errorValue);
        System.err.println("ERROR - " + errorMessage + ": " + errorString);
         
        if (Display.isCreated()) Display.destroy();
        System.exit(-1);
    }
}
 
Example 3
Source File: Main.java    From tribaltrouble with 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 4
Source File: Container.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets up the environment.
 */
private void runSetup() throws SlickException {
	try {
		setup();
	} catch (SlickException e) {
		if (!Display.isCreated()) {
			// try running in software mode
			System.setProperty("org.lwjgl.opengl.Display.allowSoftwareOpenGL", "true");
			softwareMode = true;
			setup();
		} else
			throw e;
	}
}
 
Example 5
Source File: LwjglAbstractDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Does LWJGL display initialization in the OpenGL thread
 */
protected void initInThread(){
    try{
        if (!JmeSystem.isLowPermissions()){
            // Enable uncaught exception handler only for current thread
            Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                public void uncaughtException(Thread thread, Throwable thrown) {
                    listener.handleError("Uncaught exception thrown in "+thread.toString(), thrown);
                    if (needClose.get()){
                        // listener.handleError() has requested the 
                        // context to close. Satisfy request.
                        deinitInThread();
                    }
                }
            });
        }

        // For canvas, this will create a pbuffer,
        // allowing us to query information.
        // When the canvas context becomes available, it will
        // be replaced seamlessly.
        createContext(settings);
        printContextInitInfo();

        created.set(true);
    } catch (Exception ex){
        try {
            if (Display.isCreated())
                Display.destroy();
        } catch (Exception ex2){
            logger.log(Level.WARNING, null, ex2);
        }

        listener.handleError("Failed to create display", ex);
        return; // if we failed to create display, do not continue
    }
    super.internalCreate();
    listener.initialize();
}
 
Example 6
Source File: MixinMinecraft.java    From VanillaFix with MIT License 4 votes vote down vote up
private void runGUILoop(GuiScreen screen) throws IOException {
    displayGuiScreen(screen);
    while (running && currentScreen != null && !(currentScreen instanceof GuiMainMenu) && !(Loader.isModLoaded("custommainmenu") && currentScreen instanceof GuiCustom)) {
        if (Display.isCreated() && Display.isCloseRequested()) System.exit(0);
        leftClickCounter = 10000;
        currentScreen.handleInput();
        currentScreen.updateScreen();

        GlStateManager.pushMatrix();
        GlStateManager.clear(16640);
        framebuffer.bindFramebuffer(true);
        GlStateManager.enableTexture2D();

        GlStateManager.viewport(0, 0, displayWidth, displayHeight);

        // EntityRenderer.setupOverlayRendering
        ScaledResolution scaledResolution = new ScaledResolution((Minecraft) (Object) this);
        GlStateManager.clear(256);
        GlStateManager.matrixMode(5889);
        GlStateManager.loadIdentity();
        GlStateManager.ortho(0.0D, scaledResolution.getScaledWidth_double(), scaledResolution.getScaledHeight_double(), 0, 1000, 3000);
        GlStateManager.matrixMode(5888);
        GlStateManager.loadIdentity();
        GlStateManager.translate(0, 0, -2000);
        GlStateManager.clear(256);

        int width = scaledResolution.getScaledWidth();
        int height = scaledResolution.getScaledHeight();
        int mouseX = Mouse.getX() * width / displayWidth;
        int mouseY = height - Mouse.getY() * height / displayHeight - 1;
        currentScreen.drawScreen(mouseX, mouseY, 0);

        framebuffer.unbindFramebuffer();
        GlStateManager.popMatrix();

        GlStateManager.pushMatrix();
        framebuffer.framebufferRender(displayWidth, displayHeight);
        GlStateManager.popMatrix();

        updateDisplay();
        Thread.yield();
        Display.sync(60);
        checkGLError("VanillaFix GUI Loop");
    }
}
 
Example 7
Source File: LwjglCanvas.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * This is called:
 * 1) When the context thread ends
 * 2) Any time the canvas becomes non-displayable
 */
@Override
protected void destroyContext(){
    try {
        // invalidate the state so renderer can resume operation
        if (!USE_SHARED_CONTEXT){
            renderer.cleanup();
        }
        
        if (Display.isCreated()){
            /* FIXES:
             * org.lwjgl.LWJGLException: X Error
             * BadWindow (invalid Window parameter) request_code: 2 minor_code: 0
             * 
             * Destroying keyboard early prevents the error above, triggered
             * by destroying keyboard in by Display.destroy() or Display.setParent(null).
             * Therefore Keyboard.destroy() should precede any of these calls.
             */
            if (Keyboard.isCreated()){
                // Should only happen if called in 
                // LwjglAbstractDisplay.deinitInThread().
                Keyboard.destroy();
            }

            //try {
                // NOTE: On Windows XP, not calling setParent(null)
                // freezes the application.
                // On Mac it freezes the application.
                // On Linux it fixes a crash with X Window System.
                if (JmeSystem.getPlatform() == Platform.Windows32
                 || JmeSystem.getPlatform() == Platform.Windows64){
                    //Display.setParent(null);
                }
            //} catch (LWJGLException ex) {
            //    logger.log(Level.SEVERE, "Encountered exception when setting parent to null", ex);
            //}

            Display.destroy();
        }
        
        // The canvas is no longer visible,
        // but the context thread is still running.
        if (!needClose.get()){
            // MUST make sure there's still a context current here ..
            // Display is dead, make pbuffer available to the system
            makePbufferAvailable();
            
            renderer.invalidateState();
        }else{
            // The context thread is no longer running.
            // Destroy pbuffer.
            destroyPbuffer();
        }
    } catch (LWJGLException ex) {
        listener.handleError("Failed make pbuffer available", ex);
    }
}
 
Example 8
Source File: LwjglAbstractDisplay.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Does LWJGL display initialization in the OpenGL thread
 */
protected boolean initInThread() {
    try {
        if (!JmeSystem.isLowPermissions()) {
            // Enable uncaught exception handler only for current thread
            Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread thread, Throwable thrown) {
                    listener.handleError("Uncaught exception thrown in "+thread.toString(), thrown);
                    if (needClose.get()) {
                        // listener.handleError() has requested the
                        // context to close. Satisfy request.
                        deinitInThread();
                    }
                }
            });
        }

        // For canvas, this will create a pbuffer,
        // allowing us to query information.
        // When the canvas context becomes available, it will
        // be replaced seamlessly.
        createContext(settings);
        printContextInitInfo();

        created.set(true);
        super.internalCreate();
    } catch (Exception ex) {
        try {
            if (Display.isCreated()) {
                Display.destroy();
            }
        } catch (Exception ex2){
            logger.log(Level.WARNING, null, ex2);
        }

        listener.handleError("Failed to create display", ex);
        createdLock.notifyAll(); // Release the lock, so start(true) doesn't deadlock.
        return false; // if we failed to create display, do not continue
    }

    listener.initialize();
    return true;
}
 
Example 9
Source File: LwjglCanvas.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * This is called:
 * 1) When the context thread ends
 * 2) Any time the canvas becomes non-displayable
 */
protected void destroyContext(){
    try {
        // invalidate the state so renderer can resume operation
        if (!USE_SHARED_CONTEXT){
            renderer.cleanup();
        }
        
        if (Display.isCreated()){
            /* FIXES:
             * org.lwjgl.LWJGLException: X Error
             * BadWindow (invalid Window parameter) request_code: 2 minor_code: 0
             * 
             * Destroying keyboard early prevents the error above, triggered
             * by destroying keyboard in by Display.destroy() or Display.setParent(null).
             * Therefore Keyboard.destroy() should precede any of these calls.
             */
            if (Keyboard.isCreated()){
                // Should only happen if called in 
                // LwjglAbstractDisplay.deinitInThread().
                Keyboard.destroy();
            }

            //try {
                // NOTE: On Windows XP, not calling setParent(null)
                // freezes the application.
                // On Mac it freezes the application.
                // On Linux it fixes a crash with X Window System.
                if (JmeSystem.getPlatform() == Platform.Windows32
                 || JmeSystem.getPlatform() == Platform.Windows64){
                    //Display.setParent(null);
                }
            //} catch (LWJGLException ex) {
            //    logger.log(Level.SEVERE, "Encountered exception when setting parent to null", ex);
            //}

            Display.destroy();
        }
        
        // The canvas is no longer visible,
        // but the context thread is still running.
        if (!needClose.get()){
            // MUST make sure there's still a context current here ..
            // Display is dead, make pbuffer available to the system
            makePbufferAvailable();
            
            renderer.invalidateState();
        }else{
            // The context thread is no longer running.
            // Destroy pbuffer.
            destroyPbuffer();
        }
    } catch (LWJGLException ex) {
        listener.handleError("Failed make pbuffer available", ex);
    }
}