Java Code Examples for java.awt.image.BufferStrategy#show()
The following examples show how to use
java.awt.image.BufferStrategy#show() .
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: DrawReconstruction.java From deeplearning4j with Apache License 2.0 | 6 votes |
public void start() { int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData(); boolean running = true; while (running) { BufferStrategy bs = frame.getBufferStrategy(); if (bs == null) { frame.createBufferStrategy(4); return; } for (int i = 0; i < width * height; i++) pixels[i] = 0; Graphics g = bs.getDrawGraphics(); g.drawImage(img, heightOffset, widthOffset, width, height, null); g.dispose(); bs.show(); } }
Example 2
Source File: DrawReconstruction.java From Canova with Apache License 2.0 | 6 votes |
public void start(){ int[] pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData(); boolean running = true; while(running){ BufferStrategy bs = frame.getBufferStrategy(); if(bs==null){ frame.createBufferStrategy(4); return; } for (int i = 0; i < width * height; i++) pixels[i] = 0; Graphics g= bs.getDrawGraphics(); g.drawImage(img, heightOffset, widthOffset, width, height, null); g.dispose(); bs.show(); } }
Example 3
Source File: BufferStrategyExceptionTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 4
Source File: InventoryWindow.java From JavaGame with GNU Affero General Public License v3.0 | 5 votes |
private void render() { BufferStrategy bs = frame.getBufferStrategy(); if(bs == null){ frame.createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); g.setColor(Color.BLACK); g.fillRect(0, 0, WIDTH*SCALE+10, HEIGHT*SCALE+10); g.setColor(Color.WHITE); g.drawString(NAME, 50, 50); bs.show(); g.dispose(); }
Example 5
Source File: GameCanvas.java From design_principles_dojo with MIT License | 5 votes |
public void draw() throws Exception { BufferStrategy strategy = getBufferStrategy(); Graphics2D graphics = (Graphics2D) strategy.getDrawGraphics(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setColor(Color.white); graphics.fill(new Rectangle(dimension)); currentScreen = currentScreen.getNextScreen(); currentScreen.draw(graphics); graphics.dispose(); strategy.show(); }
Example 6
Source File: BufferStrategyExceptionTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 7
Source File: BufferStrategyExceptionTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 8
Source File: BufferStrategyExceptionTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 9
Source File: BufferStrategyExceptionTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 10
Source File: Menu.java From JavaGame with GNU Affero General Public License v3.0 | 5 votes |
private void render() { // frame.getFrame().getContentPane().setBackground(Color.GREEN); frame.addMouseMotionListener((MouseMotionListener) Mouse); frame.addMouseListener(Mouse); frame.addKeyListener(Key); BufferStrategy bs = frame.getBufferStrategy(); if (bs == null) { frame.createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); g.setColor(Color.BLACK); g.fillRect(0, 0, frame.getWidth(), frame.getHeight()); g.setColor(new Color(0xFF660000)); g.fillRect(0, 0, WIDTH * 3, HEIGHT * 3); g.setColor(new Color(0xFFFF9900)); g.setFont(font.getArial()); if (isGameOver()) { g.drawString("GAME OVER... What will you do now?", 35, 30); } else { String name = (Game.getJdata_UserName().length() >= 1) ? WordUtils .capitalizeFully(Game.getJdata_UserName()).toString() : "Player"; g.drawString("Welcome to JavaGame " + name, 35, 30); } g.drawLine(0, HEIGHT * 3, 0, 0); g.drawLine(0, 0, (WIDTH * 3), 0); g.drawLine((WIDTH * 3), 0, (WIDTH * 3), (HEIGHT * 3)); g.drawLine(0, (HEIGHT * 3), (WIDTH * 3), (HEIGHT * 3)); // (LEFT,DOWN,WIDTH,HEIGHT) paintButtons(isSelectedStart(), isSelectedExit(), g); bs.show(); g.dispose(); }
Example 11
Source File: BufferStrategyExceptionTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 12
Source File: BufferStrategyExceptionTest.java From hottub with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 13
Source File: BufferStrategyExceptionTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 14
Source File: BufferStrategyExceptionTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 15
Source File: BufferStrategyExceptionTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 16
Source File: BufferStrategyExceptionTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 17
Source File: BufferStrategyExceptionTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 18
Source File: BufferStrategyExceptionTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void render() { ImageCapabilities imgBackBufCap = new ImageCapabilities(true); ImageCapabilities imgFrontBufCap = new ImageCapabilities(true); BufferCapabilities bufCap = new BufferCapabilities(imgFrontBufCap, imgBackBufCap, BufferCapabilities.FlipContents.COPIED); try { createBufferStrategy(2, bufCap); } catch (AWTException ex) { createBufferStrategy(2); } BufferStrategy bs = getBufferStrategy(); do { Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.red); g.drawString("Rendering test", 20, 20); g.drawImage(bi, 50, 50, null); g.dispose(); bs.show(); } while (bs.contentsLost()||bs.contentsRestored()); }
Example 19
Source File: Renderer.java From minicraft-plus-revived with GNU General Public License v3.0 | 4 votes |
/** renders the current screen. Called in game loop, a bit after tick(). */ public static void render() { if(!HAS_GUI || screen == null) return; // no point in this if there's no gui... :P if(readyToRenderGameplay) { if(isValidServer()) { screen.clear(0); Font.drawCentered("Awaiting client connections"+ ellipsis.updateAndGet(), screen, 10, Color.get(-1, 444)); Font.drawCentered("So far:", screen, 20, Color.get(-1, 444)); int i = 0; for(String playerString: server.getClientInfo()) { Font.drawCentered(playerString, screen, 30+i*10, Color.get(-1, 134)); i++; } renderDebugInfo(); } else { renderLevel(); renderGui(); } } if (menu != null) // renders menu, if present. menu.render(screen); if (!canvas.hasFocus() && !ISONLINE) renderFocusNagger(); // calls the renderFocusNagger() method, which creates the "Click to Focus" message. BufferStrategy bs = canvas.getBufferStrategy(); // creates a buffer strategy to determine how the graphics should be buffered. Graphics g = bs.getDrawGraphics(); // gets the graphics in which java draws the picture g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); // draws the a rect to fill the whole window (to cover last?) // scales the pixels. int ww = getWindowSize().width; int hh = getWindowSize().height; // gets the image offset. int xo = (canvas.getWidth() - ww) / 2 + canvas.getParent().getInsets().left; int yo = (canvas.getHeight() - hh) / 2 + canvas.getParent().getInsets().top; g.drawImage(image, xo, yo, ww, hh, null); //draws the image on the window g.dispose(); // releases any system items that are using this method. (so we don't have crappy framerates) bs.show(); // makes the picture visible. (probably) }
Example 20
Source File: Game.java From JavaGame with GNU Affero General Public License v3.0 | 4 votes |
/** * This method displays the current state of the game. */ public void render() { BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3); // Creates a new bs with triple buffering, which reduces tearing and cross-image pixelation return; } // Centres the player in the middle of the screen int xOffset = (int) getPlayer().getX() - (screen.getWidth() / 2); int yOffset = (int) getPlayer().getY() - (screen.getHeight() / 2); level.renderTiles(screen, xOffset, yOffset); /* * for (int x = 0; x < level.width; x++) { int colour = Colours.get(-1, * -1, -1, 000); if (x % 10 == 0 && x != 0) { colour = Colours.get(-1, * -1, -1, 500); } Font.render((x % 10) + "", screen, 0 + (x * 8), 0, * colour, 1); } */ level.renderEntities(screen); level.renderProjectileEntities(screen); // Copies pixel data from the screen into the game for (int y = 0; y < screen.getHeight(); y++) { for (int x = 0; x < screen.getWidth(); x++) { int colourCode = screen.getPixels()[x + y * screen.getWidth()]; if (colourCode < 255) { // If it is a valid colour code pixels[x + y * WIDTH] = colours[colourCode]; // Sets the corresponding pixel from the screen to the game } } } if (isChangeLevel() == true && getTickCount() % 60 == 0) { Game.setChangeLevel(true); setChangeLevel(false); } if (changeLevel == true) { // If the player is teleporting to a different level print.print("Teleported into new world", PrintTypes.GAME); if (getMap() == 1) { // If the player is currently on custom_level setMap("/levels/water_level.png"); if (getDummy() != null) { // Gave nullPointerException(); upon // entering new world. level.removeEntity(getDummy()); setNpc(false); } level.removeEntity(getVendor()); // When teleporting away from custom_level, remove vendor NPC (always found on custom_level) setMap(2); } else if (getMap() == 2) { // If the player is currently on water_level setMap("/levels/custom_level.png"); level.removeEntity(getDummy()); setNpc(false); level.addEntity(getVendor()); // Add a vendor NPC - they are always found on custom_level setMap(1); } changeLevel = false; } Graphics g = bs.getDrawGraphics(); g.drawRect(0, 0, getWidth(), getHeight()); // Creates a rectangle the same size as the screen g.drawImage(image, 0, 0, getWidth(), getHeight() - 30, null); status(g, isDevMode(), isClosing()); // Font.render("Hi", screen, 0, 0, Colours.get(-1, -1, -1, 555), 1); g.drawImage(image2, 0, getHeight() - 30, getWidth(), getHeight(), null); g.setColor(Color.WHITE); g.setFont(font.getSegoe()); g.drawString( "Welcome " + WordUtils.capitalizeFully(player .getSanitisedUsername()), 3, getHeight() - 17); g.setColor(Color.ORANGE); if (context.getLocale().getCountry().equals("BE") // If the player resides in Belgium or France (i.e. uses AZERTY keyboard) || context.getLocale().getCountry().equals("FR")) { // Displays "Press A to quit" in orange at the bottom-middle portion of the screen g.drawString("Press A to quit", (getWidth() / 2) - ("Press A to quit".length() * 3), getHeight() - 17); } else { // If the player resides anywhere else (i.e. uses QWERTY keyboard) g.drawString("Press Q to quit", (getWidth() / 2) // Displays "Press Q to quit" in orange at the bottom-middle portion of the screen - ("Press Q to quit".length() * 3), getHeight() - 17); } g.setColor(Color.YELLOW); g.drawString(time.getTime(), (getWidth() - 58), (getHeight() - 3)); // Displays the current time in yellow in the bottom right corner of the screen (hh:mm:ss) g.setColor(Color.GREEN); if (backgroundMusic.getActive()) { // If music is turned on g.drawString("MUSIC is ON ", 3, getHeight() - 3); // Displays "MUSIC IS ON" in green in the bottom left corner of the screen. } g.dispose(); // Frees up memory and resources for graphics bs.show(); }