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

The following examples show how to use org.lwjgl.opengl.Display#sync() . 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: ParticleGame.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 2
Source File: TestUtils.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 3
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 6 votes vote down vote up
public TheQuadExampleTextured() {
    // Initialize OpenGL (Display)
    this.setupOpenGL();
     
    this.setupQuad();
    this.setupShaders();
    this.setupTextures();
     
    while (!Display.isCloseRequested()) {
        // Do a single loop (logic/render)
        this.loopCycle();
         
        // Force a maximum FPS of about 60
        Display.sync(60);
        // Let the CPU synchronize with the GPU if GPU is tagging behind
        Display.update();
    }
     
    // Destroy OpenGL (Display)
    this.destroyOpenGL();
}
 
Example 4
Source File: DisplayManager.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
public static void update() {
	Display.sync(FPS_CAP);
	Display.update();
	long currentFrameTime = getCurrentTime();
	delta = (currentFrameTime - lastFrameTime) / 1000f;
	lastFrameTime = currentFrameTime;
}
 
Example 5
Source File: LwjglGraphicsModule.java    From tprogers2048game with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Отрисовывает переданное игровое поле
 *
 * @param field Игровое поле, которое необходимо отрисовать
 */
@Override
public void draw(GameField field) {
    glClear(GL_COLOR_BUFFER_BIT);

    for(int i = 0; i < COUNT_CELLS_X; i++) {
        for (int j = 0; j < COUNT_CELLS_Y; j++) {
            drawCell(CELL_SIZE*i, CELL_SIZE*j, field.getState(i,j));
        }
    }

    Display.update();
    Display.sync(60);
}
 
Example 6
Source File: LwjglRasteriser.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void sync()
{
	prevKeyStates.clear();
	for (Integer i : keyCodeMap.values())
	{
		prevKeyStates.put(i, Keyboard.isKeyDown(i));
	}
	
	Display.update();
	Display.sync(60);
}
 
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: SlytherClient.java    From Slyther with MIT License 4 votes vote down vote up
@Override
public void run() {
    double delta = 0;
    long previousTime = System.nanoTime();
    long timer = System.currentTimeMillis();
    int ups = 0;
    double nanoUpdates = 1000000000.0 / 30.0;

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
    GL11.glClearDepth(1);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    setupDisplay();

    boolean doResize = false;

    while (!Display.isCloseRequested()) {
        if (Display.wasResized() && doResize) {
            setupDisplay();
        }
        doResize = true;

        long currentTime = System.nanoTime();
        double currentTickDelta = (currentTime - previousTime) / nanoUpdates;
        delta += currentTickDelta;
        frameDelta = (frameDelta + currentTickDelta) % 1.0;
        previousTime = currentTime;

        while (delta >= 1) {
            update();
            renderHandler.update();
            delta--;
            ups++;
        }

        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
        GL11.glPushMatrix();

        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

        renderHandler.render();

        fps++;

        if (System.currentTimeMillis() - timer > 1000) {
            int bytesPerSecond = 0;
            int packetsPerSecond = 0;
            if (networkManager != null) {
                bytesPerSecond = networkManager.bytesPerSecond;
                packetsPerSecond = networkManager.packetsPerSecond;
                networkManager.bytesPerSecond = 0;
                networkManager.packetsPerSecond = 0;
            }
            Display.setTitle("Slyther - FPS: " + fps + " - UPS: " + ups + " - BPS: " + bytesPerSecond + " - PPS: " + packetsPerSecond);
            fps = 0;

            timer += 1000;
            ups = 0;
        }

        GL11.glPopMatrix();
        Display.sync(60);
        Display.update();
    }
    if (networkManager != null && networkManager.isOpen()) {
        networkManager.closeConnection(ClientNetworkManager.SHUTDOWN_CODE, "");
    }
    try {
        ConfigHandler.INSTANCE.saveConfig(CONFIGURATION_FILE, configuration);
    } catch (IOException e) {
        Log.error("Failed to save config");
        Log.catching(e);
    }
    Display.destroy();
}
 
Example 9
Source File: LwjglCanvas.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected void runLoop(){
    if (desiredTask != TASK_NOTHING){
        synchronized (taskLock){
            switch (desiredTask){
                case TASK_CREATE_DISPLAY:
                    logger.log(Level.INFO, "OGL: Creating display ..");
                    restoreCanvas();
                    listener.gainFocus();
                    desiredTask = TASK_NOTHING;
                    break;
                case TASK_DESTROY_DISPLAY:
                    logger.log(Level.INFO, "OGL: Destroying display ..");
                    listener.loseFocus();
                    pauseCanvas();
                    break;
            }
            desiredTask = TASK_COMPLETE;
            taskLock.notifyAll();
        }
    }
    
    if (renderable.get()){
        int newWidth = Math.max(canvas.getWidth(), 1);
        int newHeight = Math.max(canvas.getHeight(), 1);
        if (width != newWidth || height != newHeight){
            width = newWidth;
            height = newHeight;
            if (listener != null){
                listener.reshape(width, height);
            }
        }
    }else{
        if (frameRate <= 0){
            // NOTE: MUST be done otherwise 
            // Windows OS will freeze
            Display.sync(30);
        }
    }
    
    super.runLoop();
}
 
Example 10
Source File: GLProgram.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void gameLoop() {
	try {
		init();
		
		Utils.checkGLError("init");
		
		resized();
		
		Utils.checkGLError("resized");
		
		long lastTime, lastFPS;
		lastTime = lastFPS = System.nanoTime();
		int frames = 0;
		
		while(!shouldStop()) {
			long deltaTime = System.nanoTime() - lastTime;
			lastTime += deltaTime;
			
			if(Display.wasResized())
				resized();
			
			while(Keyboard.next()) {
				if(Keyboard.getEventKeyState())
					keyPressed(Keyboard.getEventKey(), Keyboard.getEventCharacter());
				else
					keyReleased(Keyboard.getEventKey(), Keyboard.getEventCharacter());
			}
			
			update(deltaTime);
			
			Utils.checkGLError("update");
			
			render();
			
			Utils.checkGLError("render");
			
			Display.update();
			
			frames++;
			if(System.nanoTime() - lastFPS >= 1e9) {
				System.out.println("FPS: ".concat(String.valueOf(frames)));
				lastFPS += 1e9;
				frames = 0;
			}
			
			Display.sync(fps);
		}
	} catch(Throwable exc) {
		exc.printStackTrace();
	} finally {
		destroy();
	}
}
 
Example 11
Source File: LwjglCanvas.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void runLoop(){
    if (desiredTask != TASK_NOTHING){
        synchronized (taskLock){
            switch (desiredTask){
                case TASK_CREATE_DISPLAY:
                    logger.log(Level.FINE, "OGL: Creating display ..");
                    restoreCanvas();
                    listener.gainFocus();
                    desiredTask = TASK_NOTHING;
                    break;
                case TASK_DESTROY_DISPLAY:
                    logger.log(Level.FINE, "OGL: Destroying display ..");
                    listener.loseFocus();
                    pauseCanvas();
                    break;
            }
            desiredTask = TASK_COMPLETE;
            taskLock.notifyAll();
        }
    }
    
    if (renderable.get()){
        int newWidth = Math.max(canvas.getWidth(), 1);
        int newHeight = Math.max(canvas.getHeight(), 1);
        if (width != newWidth || height != newHeight){
            width = newWidth;
            height = newHeight;
            if (listener != null){
                listener.reshape(width, height);
            }
        }
    }else{
        if (frameRate <= 0){
            // NOTE: MUST be done otherwise 
            // Windows OS will freeze
            Display.sync(30);
        }
    }
    
    super.runLoop();
}
 
Example 12
Source File: LwJglRenderingEngine.java    From Gaalop with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
    startEngine();
    //long start = System.currentTimeMillis();
    while (!Display.isCloseRequested()) {
        //System.out.println(System.currentTimeMillis()-start);
        //start = System.currentTimeMillis();
        
        if (rendering.isNewDataSetAvailable()) {
            if (list != -1) GL11.glDeleteLists(list, 1);
            list = GL11.glGenLists(1);
            GL11.glNewList(list, GL11.GL_COMPILE);
            draw(rendering.getDataSet(), rendering.getVisibleObjects(), rendering.getLoadedPointClouds());
            GL11.glEndList();
            changed = true;
        }
        
        
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // clear the screen
        GL11.glLoadIdentity(); // apply camPos before rotation

        GL11.glTranslatef(0.0f, 0.0f, -5.0f);
        // draw
        GLU.gluLookAt(camPos.x, camPos.y, camPos.z, // Position
                camPos.x + camDir.x, camPos.y + camDir.y, camPos.z + camDir.z, // Lookat
                camUp.x, camUp.y, camUp.z);               // Up-direction
        // apply rotation
        GL11.glRotatef(camAngleX, 0, 1, 0); // window x axis rotates around up vector
        GL11.glRotatef(camAngleY, 1, 0, 0); // window y axis rotates around x

        //Render the scene
        if (list != -1) GL11.glCallList(list);

        pollInput();
        Display.update();
        if (recorder != null) {
            if (changed || firstFrame) {
                recorder.makeScreenshot();
                changed = false;
            }
            firstFrame = false;
            Display.sync(25); // cap fps to 60fps
        }
        else 
            Display.sync(60); 
    }

    Display.destroy();
}
 
Example 13
Source File: Graphics.java    From AnyaBasic with MIT License 4 votes vote down vote up
public void flip()
{
    Display.update();
    Display.sync(60);
}
 
Example 14
Source File: Graphics.java    From AnyaBasic with MIT License 4 votes vote down vote up
public void flip( int refreshRate )
{
    Display.update();
    Display.sync(refreshRate);
}
 
Example 15
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 16
Source File: Window.java    From LowPolyWater with The Unlicense 4 votes vote down vote up
public void update() {
	Display.sync(fpsCap);
	Display.update();
}
 
Example 17
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 18
Source File: DisplayManager.java    From OpenGL-Tutorial-1 with The Unlicense 2 votes vote down vote up
/**
 * This method is used to update the display at the end of every frame. When
 * we have set up a rendering process this method will display whatever
 * we've been rendering onto the screen. The "sync" method is used here to
 * cap the frame rate. Without this the computer would just try to run the
 * game as fast as it possibly can, doing more work than it needs to.
 */
public static void updateDisplay() {
	Display.sync(FPS_CAP);
	Display.update();
}