List of usage examples for org.lwjgl.opengl GL11 glReadBuffer
public static void glReadBuffer(@NativeType("GLenum") int src)
From source file:cellSim2.SimLWJGL.java
License:Open Source License
public static int main(String[] args, int width, int height, String title, Simulation demoApp) throws LWJGLException { Display.setDisplayMode(new DisplayMode(width, height)); Display.setTitle(title);//w ww . j a va 2 s. co m Display.create(new PixelFormat(0, 24, 0)); Keyboard.create(); Keyboard.enableRepeatEvents(true); Mouse.create(); gl.init(); demoApp.myinit(); demoApp.reshape(width, height); boolean quit = false; long lastTime = System.currentTimeMillis(); int frames = 0; while (!Display.isCloseRequested() && !quit && !demoApp.readyToQuit()) { demoApp.moveAndDisplay(); Display.update(); if (demoApp.timeToOutputImage()) { GL11.glReadBuffer(GL11.GL_FRONT); int w = Display.getDisplayMode().getWidth(); int h = Display.getDisplayMode().getHeight(); ByteBuffer buf = demoApp.getImageBuffer(w, h); GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); demoApp.outputImage(); } int modifiers = 0; if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) modifiers |= KeyEvent.SHIFT_DOWN_MASK; if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) modifiers |= KeyEvent.CTRL_DOWN_MASK; if (Keyboard.isKeyDown(Keyboard.KEY_LMETA) || Keyboard.isKeyDown(Keyboard.KEY_RMETA)) modifiers |= KeyEvent.ALT_DOWN_MASK; while (Keyboard.next()) { if (Keyboard.getEventCharacter() != '\0') { demoApp.keyboardCallback(Keyboard.getEventCharacter(), Mouse.getX(), Mouse.getY(), modifiers); } if (Keyboard.getEventKeyState()) { demoApp.specialKeyboard(Keyboard.getEventKey(), Mouse.getX(), Mouse.getY(), modifiers); } else { demoApp.specialKeyboardUp(Keyboard.getEventKey(), Mouse.getX(), Mouse.getY(), modifiers); } if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) quit = true; if (Keyboard.getEventKey() == Keyboard.KEY_Q) quit = true; } while (Mouse.next()) { if (Mouse.getEventButton() != -1) { int btn = Mouse.getEventButton(); if (btn == 1) { btn = 2; } else if (btn == 2) { btn = 1; } demoApp.mouseFunc(btn, Mouse.getEventButtonState() ? 0 : 1, Mouse.getEventX(), Display.getDisplayMode().getHeight() - 1 - Mouse.getEventY()); } demoApp.mouseMotionFunc(Mouse.getEventX(), Display.getDisplayMode().getHeight() - 1 - Mouse.getEventY()); } long time = System.currentTimeMillis(); if (time - lastTime < 1000) { frames++; } else { Display.setTitle(title + " | FPS: " + frames); lastTime = time; frames = 0; } } //This line is the whole point of making this class demoApp.wrapUp(); Display.destroy(); demoApp.destroy(); return 0; }
From source file:com.ardor3d.framework.lwjgl.LwjglHeadlessCanvas.java
License:Open Source License
public void draw() { // bind correct fbo EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _useMSAA ? _msfboID : _fboID); // Make sure this OpenGL context is current. ContextManager.switchContext(this); try {//ww w .ja va 2 s . c o m _buff.makeCurrent(); } catch (final LWJGLException ex) { ex.printStackTrace(); } // make sure camera is set if (Camera.getCurrentCamera() != _camera) { _camera.update(); } _camera.apply(_renderer); // clear buffers GL11.glDisable(GL11.GL_SCISSOR_TEST); _renderer.clearBuffers(Renderer.BUFFER_COLOR | Renderer.BUFFER_DEPTH); // draw our scene _scene.renderUnto(_renderer); _renderer.flushFrame(false); // if we're multisampled, we need to blit to a non-multisampled fbo first if (_useMSAA) { EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferBlit.GL_DRAW_FRAMEBUFFER_EXT, _fboID); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferBlit.GL_READ_FRAMEBUFFER_EXT, _msfboID); EXTFramebufferBlit.glBlitFramebufferEXT(0, 0, _settings.getWidth(), _settings.getHeight(), 0, 0, _settings.getWidth(), _settings.getHeight(), GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT, GL11.GL_NEAREST); // get ready to read non-msaa fbo EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _fboID); } // read data from our color buffer _data.rewind(); GL11.glReadBuffer(EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT); GL11.glReadPixels(0, 0, _settings.getWidth(), _settings.getHeight(), GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, _data); // release our FBO. EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0); }
From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java
License:Open Source License
private void setReadBuffer(final int attachVal) { GL11.glReadBuffer(attachVal); }
From source file:com.badlogic.gdx.backends.jglfw.JglfwGL30.java
License:Apache License
@Override public void glReadBuffer(int mode) { GL11.glReadBuffer(mode); }
From source file:com.company.Rendering.RenderingUtils.java
public static void TakeScreenShot() { GL11.glReadBuffer(GL11.GL_FRONT); ByteBuffer videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); int width = (GLFWvidmode.width(videoMode)); int height = (GLFWvidmode.height(videoMode)); int bpp = 4;/*from w w w.j a v a 2 s.c o m*/ ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp); GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); try { ImageIO.write(RenderingUtils.BufferToImage(width, height, bpp, buffer), "bmp", new File("Screen_Shot_" + System.currentTimeMillis() + ".bmp")); } catch (IOException ex) { Logger.getLogger(TestGame.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.flowpowered.caustic.lwjgl.gl20.GL20Context.java
License:MIT License
@Override public ByteBuffer readFrame(Rectangle size, InternalFormat format) { checkCreated();/* www.j a v a 2 s .c o m*/ // Create the image buffer final ByteBuffer buffer = CausticUtil.createByteBuffer(size.getArea() * format.getBytes()); // Read from the front buffer GL11.glReadBuffer(GL11.GL_FRONT); // Use byte alignment GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); // Read the pixels GL11.glReadPixels(size.getX(), size.getY(), size.getWidth(), size.getHeight(), format.getFormat().getGLConstant(), format.getComponentType().getGLConstant(), buffer); // Check for errors LWJGLUtil.checkForGLError(); return buffer; }
From source file:com.flowpowered.caustic.lwjgl.gl20.GL20FrameBuffer.java
License:MIT License
@Override public void create() { checkNotCreated();//from ww w.ja v a 2 s .c o m // Generate and bind the frame buffer id = EXTFramebufferObject.glGenFramebuffersEXT(); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, id); // Disable input buffers GL11.glReadBuffer(GL11.GL_NONE); // Unbind the frame buffer EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0); // Update the state super.create(); // Check for errors LWJGLUtil.checkForGLError(); }
From source file:com.flowpowered.caustic.lwjgl.gl30.GL30FrameBuffer.java
License:MIT License
@Override public void create() { checkNotCreated();//from w w w . j a va 2 s . c om // Generate and bind the frame buffer id = GL30.glGenFramebuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, id); // Disable input buffers GL11.glReadBuffer(GL11.GL_NONE); // Unbind the frame buffer GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); // Update the state super.create(); // Check for errors LWJGLUtil.checkForGLError(); }
From source file:com.gameminers.mav.render.IconRenderer.java
License:Open Source License
@Override public void run() { try {/*from ww w.ja va 2 s. c om*/ init(); } catch (Exception e) { return; } try { final ByteBuffer icon = BufferUtils.createByteBuffer(SIZE * SIZE * 4); while (run) { // LWJGL makes a deep copy of our ByteBuffer, so skip frames we don't need to render if (!ArrayUtils.isEquals(RenderState.lagRGB, previousRGB)) { previousRGB = RenderState.lagRGB.clone(); Rendering.beforeFrame(SIZE, SIZE); GL11.glPushMatrix(); Mav.personality.renderIconBackground(SIZE); GL11.glTranslatef(SIZE / 2f, SIZE / 2f, 0); Mav.personality.renderIconForeground(SIZE); GL11.glPopMatrix(); GL11.glReadBuffer(GL11.GL_FRONT); GL11.glReadPixels(0, 0, SIZE, SIZE, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, icon); Display.setIcon(new ByteBuffer[] { icon }); } sleep(33L); // We don't care very much about accuracy, and using LWJGL's sync() method screws up the main context } } catch (InterruptedException e) { } }
From source file:com.legendzero.exploration.control.controllers.ScreenShotController.java
License:Open Source License
@Override public void update(IExploration game) { if (Keyboard.isKeyDown(Keyboard.KEY_F2) && System.currentTimeMillis() - this.lastScreenshot >= 1000) { this.lastScreenshot = System.currentTimeMillis(); GL11.glReadBuffer(GL11.GL_FRONT); int width = Display.getWidth(); int height = Display.getHeight(); int bpp = 4; // Assuming a 32-bit display with a byte each for red, green, blue, and alpha. ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp); GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); File file = new File(folder, this.format.format(new Date())); System.out.println(file.getAbsolutePath()); String type = "PNG"; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int i = (x + (width * y)) * bpp; int r = buffer.get(i) & 0xFF; int g = buffer.get(i + 1) & 0xFF; int b = buffer.get(i + 2) & 0xFF; int a = buffer.get(i + 3) & 0xFF; image.setRGB(x, height - (y + 1), (a << 24) | (r << 16) | (g << 8) | b); }/*from w w w . j av a 2s . c o m*/ } try { if (file.createNewFile()) { ImageIO.write(image, type, file); } else { System.err.println("File already exists! Ignoring screenshot."); } } catch (IOException e) { e.printStackTrace(); } } }