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

The following examples show how to use org.lwjgl.opengl.Display#destroy() . 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: LevelEditor.java    From FEMultiplayer with 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 2
Source File: LevelEditor.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void loop() {
	while(!Display.isCloseRequested()) {
		final long time = System.nanoTime();
		glClear(GL_COLOR_BUFFER_BIT |
		        GL_DEPTH_BUFFER_BIT |
		        GL_STENCIL_BUFFER_BIT);
		glClearDepth(1.0f);
		getInput();
		glPushMatrix();
			currentStage.beginStep(emptyList());
			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 3
Source File: LwjglRasteriser.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void destroy()
{
	if (type == DisplayType.Window)
	{
		Display.destroy();
	}
	else if (type == DisplayType.Offscreen)
	{
		pbuffer.destroy();
	}
}
 
Example 4
Source File: DisplayContainer.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
public void teardown() {
	destroyImages();
	CurveRenderState.shutdown();
	VolumeControl.destroyProgram();
	Display.destroy();
	this.glReady = false;
}
 
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: Graphics.java    From AnyaBasic with MIT License 5 votes vote down vote up
public void destroy()
{
    spriteFont.shutDown();
    glowImages.shutDown();
    //noinspection Convert2streamapi
    for(SpriteGL sprite: sprites)
    {
        sprite.shutDown();
    }
    Display.destroy();
}
 
Example 7
Source File: FEMultiplayer.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
	public void loop() {
		while(!Display.isCloseRequested()) {
			final long time = System.nanoTime();
			glClear(GL_COLOR_BUFFER_BIT |
			        GL_DEPTH_BUFFER_BIT |
			        GL_STENCIL_BUFFER_BIT);
			glClearDepth(1.0f);
			getInput();
			final ArrayList<Message> messages = new ArrayList<>();
			if(client != null){
				synchronized (client.messagesLock) {
					messages.addAll(client.messages);
					for(Message m : messages)
						client.messages.remove(m);
				}
			}
			SoundStore.get().poll(0);
			glPushMatrix();
			//Global resolution scale
//			Renderer.scale(scaleX, scaleY);
				currentStage.beginStep(messages);
				currentStage.onStep();
				currentStage.processAddStack();
				currentStage.processRemoveStack();
				currentStage.render();
//				FEResources.getBitmapFont("stat_numbers").render(
//						(int)(1.0f/getDeltaSeconds())+"", 440f, 0f, 0f);
				currentStage.endStep();
				postRenderRunnables.runAll();
			glPopMatrix();
			Display.update();
			Display.sync(FEResources.getTargetFPS());
			timeDelta = System.nanoTime()-time;
		}
		AL.destroy();
		Display.destroy();
		if(client != null && client.isOpen()) client.quit();
	}
 
Example 8
Source File: LwjglDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void destroyContext(){
    try {
        renderer.cleanup();
        Display.releaseContext();
        Display.destroy();
    } catch (LWJGLException ex) {
        listener.handleError("Failed to destroy context", ex);
    }
}
 
Example 9
Source File: FEMultiplayer.java    From FEMultiplayer with GNU General Public License v3.0 5 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();
			messages.clear();
			if(client != null){
				messages.addAll(client.getMessages());
				for(Message m : messages)
					client.messages.remove(m);
			}
			SoundStore.get().poll(0);
			glPushMatrix();
			//Global resolution scale
//			Renderer.scale(scaleX, scaleY);
			if(!paused) {
				currentStage.beginStep();
				currentStage.onStep();
				currentStage.processAddStack();
				currentStage.processRemoveStack();
				currentStage.render();
//				FEResources.getBitmapFont("stat_numbers").render(
//						(int)(1.0f/getDeltaSeconds())+"", 440f, 0f, 0f);
				currentStage.endStep();
			}
			glPopMatrix();
			Display.update();
			timeDelta = System.nanoTime()-time;
		}
		AL.destroy();
		Display.destroy();
		if(client != null && client.isOpen()) client.quit();
	}
 
Example 10
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 11
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create the LWJGL display
 * 
 * @throws Exception Failure to create display
 */
private void createDisplay() throws Exception {
   try {
      // create display with alpha
      Display.create(new PixelFormat(8,8,GameContainer.stencil ? 8 : 0));
      alphaSupport = true;
   } catch (Exception e) {
      // if we couldn't get alpha, let us know
      alphaSupport = false;
       Display.destroy();
       // create display without alpha
      Display.create();
   }
}
 
Example 12
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 13
Source File: DisplayManager.java    From OpenGL-Tutorial-1 with The Unlicense 4 votes vote down vote up
/**
 * This closes the window when the game is closed.
 */
public static void closeDisplay() {
	Display.destroy();
}
 
Example 14
Source File: Renderer.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
private final static void destroyNative() {
	destroyAL();
	Display.destroy();
}
 
Example 15
Source File: Test.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public final static void main(String[] args) {
		try {
			Display.setDisplayMode(new DisplayMode(DISPLAY_WIDTH, DISPLAY_HEIGHT));
			Display.create();
			initGL();

			// Load font
			InputStream font_is = Utils.makeURL("/fonts/tahoma.ttf").openStream();
			java.awt.Font src_font = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, font_is);
			java.awt.Font font = src_font.deriveFont(14f);

			// Load text
			InputStreamReader text_is = new InputStreamReader(Utils.makeURL("/test_text.txt").openStream());
			StringBuffer str_buffer = new StringBuffer();
			int c = text_is.read();
			do {
				str_buffer.append((char)c);
				c = text_is.read();
			} while (c != -1);
			String str = str_buffer.toString();

			// Build texture
			int[] pixels = new int[WIDTH*HEIGHT];
//			ByteBuffer pixel_data = ByteBuffer.wrap(pixels);						// NEW
//			pixelDataFromString(WIDTH, HEIGHT, str, font, pixels);					// NEW
			IntBuffer pixel_data = BufferUtils.createIntBuffer(WIDTH*HEIGHT);	// OLD
			pixel_data.put(pixels);													// OLD
			pixel_data.rewind();

			int texture_handle = createTexture(WIDTH, HEIGHT, pixel_data);
			
		FontRenderContext frc = g2d.getFontRenderContext();
		AttributedString att_str = new AttributedString(str);
		att_str.addAttribute(TextAttribute.FONT, font);
		AttributedCharacterIterator iterator = att_str.getIterator();
		LineBreakMeasurer measurer = new LineBreakMeasurer(iterator, frc);
		
			while (!Display.isCloseRequested()) {
long start_time = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
pixelDataFromString(WIDTH, HEIGHT, str, font, pixels, measurer);
pixel_data.put(pixels); // OLD
pixel_data.rewind();

//texture_handle = createTexture(WIDTH, HEIGHT, pixel_data);
updateTexture(WIDTH, HEIGHT, pixel_data);
				GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
				GL11.glLoadIdentity();
				
				// Background
				/*
				GL11.glDisable(GL11.GL_TEXTURE_2D);
				GL11.glColor4f(.1f, .1f, .1f, 1f);
				GL11.glBegin(GL11.GL_QUADS);
				GL11.glVertex3f(0f, DISPLAY_HEIGHT-RENDER_SIZE, 1f);
				GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT-RENDER_SIZE, 1f);
				GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT, 1f);
				GL11.glVertex3f(0f, DISPLAY_HEIGHT, 1f);
				GL11.glEnd();
				*/

				// Text
				GL11.glEnable(GL11.GL_TEXTURE_2D);
				GL11.glColor4f(1f, 1f, 1f, 1f);
				GL11.glBegin(GL11.GL_QUADS);
				GL11.glTexCoord2f(0f, 1f);
				GL11.glVertex3f(0f, DISPLAY_HEIGHT-RENDER_SIZE, 1f);
				GL11.glTexCoord2f(1f, 1f);
				GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT-RENDER_SIZE, 1f);
				GL11.glTexCoord2f(1f, 0f);
				GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT, 1f);
				GL11.glTexCoord2f(0f, 0f);
				GL11.glVertex3f(0f, DISPLAY_HEIGHT, 1f);
				GL11.glEnd();
				Display.update();
}
long total_time = System.currentTimeMillis() - start_time;
System.out.println("total_time = " + total_time);

			}
			Display.destroy();
		} catch (Exception t) {
			t.printStackTrace();
		}
	}
 
Example 16
Source File: LwJglRenderingEngine.java    From Gaalop with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Poll all inputs of the keyboard<br>
 * F3:Start recording
 * F4:Stop recording
 * ESC: Close window
 */
private void pollInput() {
    
    if (Keyboard.isKeyDown(Keyboard.KEY_F3)) {
        //Start recording
        if (recorder == null) {
            recorder = new GIFRecorder();
            recorder.startRecording();
        }
    }
    
    if (Keyboard.isKeyDown(Keyboard.KEY_F4)) {
        //Stop recording
        if (recorder != null) {
            recorder.stopRecording();
            recorder = null;
        }
    }
    
    if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        if (recorder != null) 
            recorder.stopRecording();
        Display.destroy();
        System.exit(0);

    }

    int x = Mouse.getX();
    int y = Mouse.getY();

    for (int button = 0; button <= 2; button++) {
        if (Mouse.isButtonDown(button)) {
            if (!buttonDown[button]) {
                mouseAction(button, STATE_DOWN, x, y);
            } else {
                mouseMoved(x, y);
            }
            buttonDown[button] = true;
        } else {
            if (buttonDown[button]) {
                mouseAction(button, STATE_UP, x, y);
            }
            buttonDown[button] = false;
        }
    }
}
 
Example 17
Source File: ShoveTargetTest.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 4 votes vote down vote up
@After
public void globalDisplayAfter() {
	Display.destroy();
}
 
Example 18
Source File: ModelViewer.java    From OpenRS with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	if (args.length < 1) {
		System.err.println("Usage: modelfile");
		System.exit(1);
	}

	ModelList list = new ModelList();
	try (Cache cache = new Cache(FileStore.open(Constants.CACHE_PATH))) {
		list.initialize(cache);
	}

	Model md = list.list(Integer.valueOf(args[0]));

	Display.setDisplayMode(new DisplayMode(800, 600));
	Display.setTitle("Model Viewer");
	Display.setInitialBackground((float) Color.gray.getRed() / 255f, (float) Color.gray.getGreen() / 255f,
			(float) Color.gray.getBlue() / 255f);
	Display.create();

	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	double aspect = 1;
	double near = 1; // near should be chosen as far into the scene as
						// possible
	double far = 1000;
	double fov = 1; // 1 gives you a 90� field of view. It's
					// tan(fov_angle)/2.
	GL11.glFrustum(-aspect * near * fov, aspect * near * fov, -fov, fov, near, far);

	GL11.glCullFace(GL11.GL_BACK);

	long last = 0;

	while (!Display.isCloseRequested()) {
		// Clear the screen and depth buffer
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

		GL11.glBegin(GL11.GL_TRIANGLES);

		for (int i = 0; i < md.faceCount; ++i) {
			int vertexA = md.triangleX[i];
			int vertexB = md.triangleY[i];
			int vertexC = md.triangleZ[i];

			int vertexAx = md.vertexX[vertexA];
			int vertexAy = md.vertexY[vertexA];
			int vertexAz = md.vertexZ[vertexA];

			int vertexBx = md.vertexX[vertexB];
			int vertexBy = md.vertexY[vertexB];
			int vertexBz = md.vertexZ[vertexB];

			int vertexCx = md.vertexX[vertexC];
			int vertexCy = md.vertexY[vertexC];
			int vertexCz = md.vertexZ[vertexC];

			short hsb = md.faceColor[i];

			int rgb = hsbToRGB(hsb);
			Color c = new Color(rgb);

			// convert to range of 0-1
			float rf = (float) c.getRed() / 255f;
			float gf = (float) c.getGreen() / 255f;
			float bf = (float) c.getBlue() / 255f;

			GL11.glColor3f(rf, gf, bf);

			GL11.glVertex3i(vertexAx, vertexAy, vertexAz - 50);
			GL11.glVertex3i(vertexBx, vertexBy, vertexBz - 50);
			GL11.glVertex3i(vertexCx, vertexCy, vertexCz - 50);
		}

		GL11.glEnd();

		Display.update();
		Display.sync(50); // fps

		long delta = System.currentTimeMillis() - last;
		last = System.currentTimeMillis();

		Camera.create();
		Camera.acceptInput(delta);

		Camera.apply();
	}

	Display.destroy();
}
 
Example 19
Source File: AppGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Destroy the app game container
 */
public void destroy() {
	Display.destroy();
	AL.destroy();
}
 
Example 20
Source File: TestWithDisplay.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@AfterClass
public void destroyDisplay() {
    Display.destroy();
}