Java Code Examples for org.lwjgl.opengl.GL11#glPixelStorei()
The following examples show how to use
org.lwjgl.opengl.GL11#glPixelStorei() .
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: Recorder.java From Gaalop with GNU Lesser General Public License v3.0 | 6 votes |
/** * Make a screenshot from the current LWJGL Display * Code from pc */ public void makeScreenshot() { curTime = System.currentTimeMillis(); ByteBuffer screenBuffer = ByteBuffer.allocateDirect(Display.getDisplayMode().getWidth() * Display.getDisplayMode().getHeight() * 3); try { GL11.glReadBuffer(GL11.GL_BACK); GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glReadPixels(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight(), GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, screenBuffer); long delay = (lastTime == -1) ? 0: curTime-lastTime; lastTime = curTime; thread.addFrame(screenBuffer, delay); } catch (Exception e) { System.out.println("Streaming exception."); e.printStackTrace(); } }
Example 2
Source File: ClientDynamicTexture.java From AdvancedRocketry with MIT License | 6 votes |
private void init() { //create array, every single pixel ByteBuffer buffer = BufferUtils.createByteBuffer(image.getHeight() * image.getWidth() * BYTES_PER_PIXEL); for(int i = 0; i < image.getHeight() * image.getWidth(); i++) { buffer.putInt(0x00000000); } buffer.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureId()); //Just clamp to edge GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); //Scale linearly GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); }
Example 3
Source File: TextureUtils.java From OpenGL-Animation with The Unlicense | 5 votes |
protected static int loadTextureToOpenGL(TextureData data, TextureBuilder builder) { int texID = GL11.glGenTextures(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, data.getBuffer()); if (builder.isMipmap()) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); if (builder.isAnisotropic() && GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) { GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, 4.0f); } } else if (builder.isNearest()) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); } else { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); } if (builder.isClampEdges()) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); } else { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); } GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); return texID; }
Example 4
Source File: Renderer.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
public final static void initGL() { VBO.releaseAll(); GL11.glFrontFace(GL11.GL_CCW); GL11.glCullFace(GL11.GL_BACK); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glPixelStorei(GL11.GL_PACK_ROW_LENGTH, 0); GL11.glPixelStorei(GL11.GL_PACK_SKIP_PIXELS, 0); GL11.glPixelStorei(GL11.GL_PACK_SKIP_ROWS, 0); GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_PACK_SWAP_BYTES, 0); GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, 0); GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, 0); GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, 0); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_SWAP_BYTES, 0); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glShadeModel(GL11.GL_SMOOTH); // GL11.glAlphaFunc(GL11.GL_GREATER, Globals.ALPHA_CUTOFF); // Setup landscape texture coordinate gen GL11.glTexGeni(GL11.GL_S, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR); GL11.glTexGeni(GL11.GL_T, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE); GLState.activeTexture(GL13.GL_TEXTURE1); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_DECAL); GL11.glTexGeni(GL11.GL_S, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR); GL11.glTexGeni(GL11.GL_T, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR); GLState.activeTexture(GL13.GL_TEXTURE0); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glPointSize(7.0f); clearScreen(); GL11.glClearDepth(1.0); }
Example 5
Source File: GuiItemIconDumper.java From NotEnoughItems with MIT License | 5 votes |
private BufferedImage screenshot() { Framebuffer fb = Minecraft.getMinecraft().getFramebuffer(); Dimension mcSize = GuiDraw.displayRes(); Dimension texSize = mcSize; if (OpenGlHelper.isFramebufferEnabled()) texSize = new Dimension(fb.framebufferTextureWidth, fb.framebufferTextureHeight); int k = texSize.width * texSize.height; if (pixelBuffer == null || pixelBuffer.capacity() < k) { pixelBuffer = BufferUtils.createIntBuffer(k); pixelValues = new int[k]; } GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); pixelBuffer.clear(); if (OpenGlHelper.isFramebufferEnabled()) { GlStateManager.bindTexture(fb.framebufferTexture); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer); } else { GL11.glReadPixels(0, 0, texSize.width, texSize.height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer); } pixelBuffer.get(pixelValues); TextureUtil.processPixelValues(pixelValues, texSize.width, texSize.height); BufferedImage img = new BufferedImage(mcSize.width, mcSize.height, BufferedImage.TYPE_INT_ARGB); if (OpenGlHelper.isFramebufferEnabled()) { int yOff = texSize.height - mcSize.height; for (int y = 0; y < mcSize.height; ++y) for (int x = 0; x < mcSize.width; ++x) img.setRGB(x, y, pixelValues[(y + yOff) * texSize.width + x]); } else { img.setRGB(0, 0, texSize.width, height, pixelValues, 0, texSize.width); } return img; }
Example 6
Source File: Texture.java From mapwriter with MIT License | 5 votes |
public synchronized void updateTextureArea(int x, int y, int w, int h) { try { this.bind(); GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, this.w); this.pixelBuf.position((y * this.w) + x); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, x, y, w, h, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, this.pixelBuf); GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, 0); } catch (NullPointerException e) { MwUtil.log("MwTexture.updatePixels: null pointer exception (texture %d)", this.id); } }
Example 7
Source File: HyperiumScreenshotHelper.java From Hyperium with GNU Lesser General Public License v3.0 | 4 votes |
public static IChatComponent saveScreenshot(int width, int height, Framebuffer buffer, IntBuffer pixelBuffer, int[] pixelValues) { final File file1 = new File(Minecraft.getMinecraft().mcDataDir, "screenshots"); file1.mkdir(); if (OpenGlHelper.isFramebufferEnabled()) { width = buffer.framebufferTextureWidth; height = buffer.framebufferTextureHeight; } final int i = width * height; if (pixelBuffer == null || pixelBuffer.capacity() < i) { pixelBuffer = BufferUtils.createIntBuffer(i); pixelValues = new int[i]; } GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); pixelBuffer.clear(); if (OpenGlHelper.isFramebufferEnabled()) { GlStateManager.bindTexture(buffer.framebufferTexture); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer); } else { GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer); } boolean upload = true; pixelBuffer.get(pixelValues); if (!Settings.DEFAULT_UPLOAD_SS) { HyperiumBind uploadBind = Hyperium.INSTANCE.getHandlers().getKeybindHandler().getBinding("Upload Screenshot"); int keyCode = uploadBind.getKeyCode(); upload = keyCode < 0 ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode); } new Thread(new AsyncScreenshotSaver(width, height, pixelValues, Minecraft.getMinecraft().getFramebuffer(), new File(Minecraft.getMinecraft().mcDataDir, "screenshots"), upload)).start(); if (!upload) { return Settings.HYPERIUM_CHAT_PREFIX ? new ChatComponentText(ChatColor.RED + "[Hyperium] " + ChatColor.WHITE + "Capturing...") : new ChatComponentText(ChatColor.WHITE + "Capturing..."); } return Settings.HYPERIUM_CHAT_PREFIX ? new ChatComponentText(ChatColor.RED + "[Hyperium] " + ChatColor.WHITE + "Uploading...") : new ChatComponentText(ChatColor.WHITE + "Uploading..."); }
Example 8
Source File: Configuration.java From opsu-dance with GNU General Public License v3.0 | 4 votes |
/** * @author http://wiki.lwjgl.org/index.php?title=Taking_Screen_Shots */ public void takeScreenShot() { // TODO: get a decent place for this // create the screenshot directory if (!screenshotDir.isDirectory() && !screenshotDir.mkdir()) { bubNotifs.sendf( BUB_RED, "Failed to create screenshot directory at '%s'.", screenshotDir.getAbsolutePath() ); return; } // create file name SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss"); final String fileName = String.format("screenshot_%s.%s", date.format(new Date()), OPTION_SCREENSHOT_FORMAT.getValueString().toLowerCase()); final File file = new File(screenshotDir, fileName); SoundController.playSound(SoundEffect.SHUTTER); // copy the screen to file final int width = Display.getWidth(); final int height = Display.getHeight(); final int bpp = 3; // assuming a 32-bit display with a byte each for red, green, blue, and alpha final ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp); GL11.glReadBuffer(GL11.GL_FRONT); GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glReadPixels(0, 0, width, height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, buffer); new Thread() { @Override public void run() { try { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 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; image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b); } } ImageIO.write(image, OPTION_SCREENSHOT_FORMAT.getValueString().toLowerCase(), file); bubNotifs.send(BUB_PURPLE, "Created " + fileName); } catch (Exception e) { Log.error("Could not take screenshot", e); bubNotifs.send( BUB_PURPLE, "Failed to take a screenshot. See log file for details" ); } } }.start(); }
Example 9
Source File: GuiItemIconDumper.java From NotEnoughItems with MIT License | 4 votes |
private BufferedImage screenshot() { Framebuffer fb = Minecraft.getMinecraft().getFramebuffer(); Dimension mcSize = GuiDraw.getDisplayRes(); Dimension texSize = mcSize; if (OpenGlHelper.isFramebufferEnabled()) { texSize = new Dimension(fb.framebufferTextureWidth, fb.framebufferTextureHeight); } int k = texSize.width * texSize.height; if (pixelBuffer == null || pixelBuffer.capacity() < k) { pixelBuffer = BufferUtils.createIntBuffer(k); pixelValues = new int[k]; } GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); pixelBuffer.clear(); if (OpenGlHelper.isFramebufferEnabled()) { GlStateManager.bindTexture(fb.framebufferTexture); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer); } else { GL11.glReadPixels(0, 0, texSize.width, texSize.height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer); } pixelBuffer.get(pixelValues); TextureUtil.processPixelValues(pixelValues, texSize.width, texSize.height); BufferedImage img = new BufferedImage(mcSize.width, mcSize.height, BufferedImage.TYPE_INT_ARGB); if (OpenGlHelper.isFramebufferEnabled()) { int yOff = texSize.height - mcSize.height; for (int y = 0; y < mcSize.height; ++y) { for (int x = 0; x < mcSize.width; ++x) { img.setRGB(x, y, pixelValues[(y + yOff) * texSize.width + x]); } } } else { img.setRGB(0, 0, texSize.width, height, pixelValues, 0, texSize.width); } return img; }
Example 10
Source File: OpenGL3_TheQuadTextured.java From ldparteditor with MIT License | 4 votes |
private int loadPNGTexture(String filename, int textureUnit) { ByteBuffer buf = null; int tWidth = 0; int tHeight = 0; try { // Open the PNG file as an InputStream InputStream in = new FileInputStream(filename); // Link the PNG decoder to this stream PNGDecoder decoder = new PNGDecoder(in); // Get the width and height of the texture tWidth = decoder.getWidth(); tHeight = decoder.getHeight(); // Decode the PNG file in a ByteBuffer buf = ByteBuffer.allocateDirect( 4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); buf.flip(); in.close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } // Create a new texture object in memory and bind it int texId = GL11.glGenTextures(); GL13.glActiveTexture(textureUnit); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); // All RGB bytes are aligned to each other and each component is 1 byte GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Upload the texture data and generate mip maps (for scaling) GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); // Setup the ST coordinate system GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); // Setup what to do when the texture has to be scaled GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); this.exitOnGLError("loadPNGTexture"); return texId; }
Example 11
Source File: Video.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * Updates the video. * @param syncTime the nanosecond time the video should sync to (forward direction only) */ private void update(long syncTime) { if (finished || closed || pauseFrame > 0 || videoStream == null) return; // initialize frames if (!initialized) { videoIndex = 0; initFrame = System.nanoTime(); if (pauseFrame != 0) pauseFrame = initFrame; // change pixel store alignment to prevent distortion GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); initialized = true; } if (!isTimeForNextFrame(syncTime)) return; // grab and skip frames (if needed) ByteBuffer texBuffer = null; final int backlog = 5; int framesRead = 0; do { // free extra frames if (framesRead > 0) { videoStream.freeFrameData(texBuffer); texBuffer = null; videoIndex++; } // grab next frame texBuffer = videoStream.pollFrameData(); if (texBuffer == VideoStream.EOF) { finished = true; return; } if (texBuffer == null) return; framesRead++; } while (hasVideoBacklogOver(backlog, syncTime)); // render to texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID()); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, metadata.width, metadata.height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, texBuffer); videoStream.freeFrameData(texBuffer); videoIndex++; }
Example 12
Source File: LWJGL15DrawContext.java From settlers-remake with MIT License | 3 votes |
public LWJGL15DrawContext(GLCapabilities glcaps, boolean debug) { this.glcaps = glcaps; if(debug) debugOutput = new LWJGLDebugOutput(this); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); init(); }