List of usage examples for org.lwjgl.opengl GL11 glPixelStorei
public static void glPixelStorei(@NativeType("GLenum") int pname, @NativeType("GLint") int param)
From source file:minebot.ui.Screenshot.java
public static void screenshot() { if (currPixVal != null) { System.out.println("Skipping"); return;//from w ww . j a va 2 s. c om } int width = Minecraft.theMinecraft.displayWidth; int height = Minecraft.theMinecraft.displayHeight; int i = width * height; final IntBuffer pixelBuffer = getBuf(i); GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer); new Thread() { @Override public void run() { int[] pixelValues = getInt(i); pixelBuffer.get(pixelValues); TextureUtil.processPixelValues(pixelValues, width, height); /*BufferedImage bufferedimage; bufferedimage = new BufferedImage(width, height, 1); bufferedimage.setRGB(0, 0, width, height, pixelValues, 0, width);*/ pushBuf(pixelBuffer); boolean hasSockets; synchronized (socketsLock) { hasSockets = !sockets.isEmpty(); } if (!hasSockets) { pushInt(pixelValues); return; } synchronized (currPixLock) { if (currPixVal != null) { pushInt(currPixVal); } currPixVal = pixelValues; currWidth = width; currHeight = height; } } }.start(); }
From source file:net.neilcsmith.praxis.video.opengl.internal.Texture.java
License:Apache License
private void init() { glHandle = createGLHandle();/* w ww . j a v a 2 s . com*/ GL11.glBindTexture(GL11.GL_TEXTURE_2D, glHandle); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, dstImageFormat, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, BufferUtils.createIntBuffer(width * height)); setFilter(minFilter, magFilter); setWrap(uWrap, vWrap); getFrameBuffer(); }
From source file:org.free.jake2.render.lwjgl.Misc.java
License:Open Source License
void GL_ScreenShot_f() { StringBuilder sb = new StringBuilder(FileSystem.Gamedir() + "/scrshot/jake00.tga"); FileSystem.CreatePath(sb.toString()); File file = new File(sb.toString()); // find a valid file name int i = 0;//w w w . ja v a 2 s. c om int offset = sb.length() - 6; while (file.exists() && i++ < 100) { sb.setCharAt(offset, (char) ((i / 10) + '0')); sb.setCharAt(offset + 1, (char) ((i % 10) + '0')); file = new File(sb.toString()); } if (i == 100) { VID.Printf(Defines.PRINT_ALL, "Clean up your screenshots\n"); return; } try { RandomAccessFile out = new RandomAccessFile(file, "rw"); FileChannel ch = out.getChannel(); int fileLength = TGA_HEADER_SIZE + vid.width * vid.height * 3; out.setLength(fileLength); MappedByteBuffer image = ch.map(FileChannel.MapMode.READ_WRITE, 0, fileLength); // write the TGA header image.put(0, (byte) 0).put(1, (byte) 0); image.put(2, (byte) 2); // uncompressed type image.put(12, (byte) (vid.width & 0xFF)); // vid.width image.put(13, (byte) (vid.width >> 8)); // vid.width image.put(14, (byte) (vid.height & 0xFF)); // vid.height image.put(15, (byte) (vid.height >> 8)); // vid.height image.put(16, (byte) 24); // pixel size // go to image data position image.position(TGA_HEADER_SIZE); // change pixel alignment for reading if (vid.width % 4 != 0) { GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); } // OpenGL 1.2+ supports the GL_BGR color format // check the GL_VERSION to use the TARGA BGR order if possible // e.g.: 1.5.2 NVIDIA 66.29 if (gl_config.getOpenGLVersion() >= 1.2f) { // read the BGR values into the image buffer GL11.glReadPixels(0, 0, vid.width, vid.height, GL12.GL_BGR, GL11.GL_UNSIGNED_BYTE, image); } else { // read the RGB values into the image buffer GL11.glReadPixels(0, 0, vid.width, vid.height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, image); // flip RGB to BGR byte tmp; for (i = TGA_HEADER_SIZE; i < fileLength; i += 3) { tmp = image.get(i); image.put(i, image.get(i + 2)); image.put(i + 2, tmp); } } // reset to default alignment GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 4); // close the file channel ch.close(); } catch (IOException e) { VID.Printf(Defines.PRINT_ALL, e.getMessage() + '\n'); } VID.Printf(Defines.PRINT_ALL, "Wrote " + file + '\n'); }
From source file:org.jge.util.LWJGLHandler.java
License:Open Source License
public static BufferedImage takeScreenshot() { int k = Display.getWidth() * Display.getHeight(); if (screenshotBuffer == null || screenshotBuffer.capacity() < k) { screenshotBuffer = BufferUtils.createIntBuffer(k); screenshotBufferArray = new int[k]; }//from w ww . ja v a 2s. c o m GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); screenshotBuffer.clear(); GL11.glReadPixels(0, 0, Display.getWidth(), Display.getHeight(), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, screenshotBuffer); screenshotBuffer.get(screenshotBufferArray); int[] aint1 = new int[Display.getWidth()]; int j = Display.getHeight() / 2; for (int l = 0; l < j; ++l) { System.arraycopy(screenshotBufferArray, l * Display.getWidth(), aint1, 0, Display.getWidth()); System.arraycopy(screenshotBufferArray, (Display.getHeight() - 1 - l) * Display.getWidth(), screenshotBufferArray, l * Display.getWidth(), Display.getWidth()); System.arraycopy(aint1, 0, screenshotBufferArray, (Display.getHeight() - 1 - l) * Display.getWidth(), Display.getWidth()); } BufferedImage bufferedimage = new BufferedImage(Display.getWidth(), Display.getHeight(), BufferedImage.TYPE_INT_RGB); for (int i = 0; i < screenshotBufferArray.length; i++) { Color c = ImageUtils.getColor(screenshotBufferArray[i]); screenshotBufferArray[i] = new Color(c.getBlue(), c.getGreen(), c.getRed()).getRGB(); } bufferedimage.setRGB(0, 0, Display.getWidth(), Display.getHeight(), screenshotBufferArray, 0, Display.getWidth()); return bufferedimage; }
From source file:org.oscim.gdx.LwjglGL20.java
License:Apache License
public void pixelStorei(int pname, int param) { GL11.glPixelStorei(pname, param); }
From source file:org.spout.renderer.lwjgl.gl20.GL20Texture.java
License:Open Source License
@Override public void setImageData(ByteBuffer imageData, int width, int height) { checkCreated();//ww w . j av a 2s .com if (width <= 0) { throw new IllegalArgumentException("Width must be greater than zero"); } if (height <= 0) { throw new IllegalArgumentException("Height must be greater than zero"); } this.width = width; this.height = height; // Bind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // Upload the texture to the GPU final boolean hasInternalFormat = internalFormat != null; if (minFilter.needsMipMaps() && imageData != null) { // Build mipmaps if using mip mapped filters GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, hasInternalFormat ? internalFormat.getGLConstant() : format.getGLConstant(), width, height, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } else { // Else just make it a normal texture // Use byte alignment GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Upload the image GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, hasInternalFormat ? internalFormat.getGLConstant() : format.getGLConstant(), width, height, 0, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } // Unbind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); // Check for errors LWJGLUtil.checkForGLError(); }
From source file:org.spout.renderer.lwjgl.gl30.GL30Texture.java
License:Open Source License
@Override public void setImageData(ByteBuffer imageData, int width, int height) { checkCreated();/*from w w w.ja v a 2 s.com*/ if (width <= 0) { throw new IllegalArgumentException("Width must be greater than zero"); } if (height <= 0) { throw new IllegalArgumentException("Height must be greater than zero"); } this.width = width; this.height = height; // Bind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // Use byte alignment GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Upload the texture final boolean hasInternalFormat = internalFormat != null; GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, hasInternalFormat ? internalFormat.getGLConstant() : format.getGLConstant(), width, height, 0, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); // Generate mipmaps if necessary if (minFilter.needsMipMaps() && imageData != null) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); } // Unbind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); // Check for errors LWJGLUtil.checkForGLError(); }
From source file:org.terasology.logic.manager.TextureManager.java
License:Apache License
public Texture loadTexture(String path, String[] mipMapPaths) throws IOException { Texture texture = new Texture(); texture.id = glGenTextures();//from w w w.ja va2 s.c o m glBindTexture(GL11.GL_TEXTURE_2D, texture.id); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL_NEAREST); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST); readTexture(path, texture); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 4); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, texture.width, texture.height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, texture.data); if (mipMapPaths != null) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, mipMapPaths.length); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST); for (int i = 0; i < mipMapPaths.length; i++) { Texture t = new Texture(); readTexture(mipMapPaths[i], t); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, i + 1, GL11.GL_RGBA, t.width, t.height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, t.data); } } return texture; }
From source file:org.terasology.rendering.assets.Texture.java
License:Apache License
public Texture(AssetUri uri, ByteBuffer[] data, int width, int height, WrapMode wrapMode, FilterMode filterMode) {//w w w . j av a 2s .c o m if (data.length == 0) throw new IllegalArgumentException("Expected Data.length >= 1"); this.uri = uri; this.width = width; this.height = height; this.wrapMode = wrapMode; this.filterMode = filterMode; this.data = data; id = glGenTextures(); logger.debug("Bound texture '{}' - {}", uri, id); glBindTexture(GL11.GL_TEXTURE_2D, id); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode.getGLMode()); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode.getGLMode()); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filterMode.getGlMinFilter()); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filterMode.getGlMagFilter()); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 4); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, data.length - 1); for (int i = 0; i < data.length; i++) { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, i, GL11.GL_RGBA, width >> i, height >> i, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data[i]); } }
From source file:org.terasology.rendering.opengl.OpenGLTexture.java
License:Apache License
@Override public void reload(TextureData data) { this.width = data.getWidth(); this.height = data.getHeight(); this.depth = data.getDepth(); this.wrapMode = data.getWrapMode(); this.filterMode = data.getFilterMode(); this.textureType = data.getType(); this.textureData = data; if (id == 0) { id = glGenTextures();// w w w .j a v a 2 s .c om } switch (textureType) { case TEXTURE2D: logger.debug("Bound texture '{}' - {}", getURI(), id); glBindTexture(GL11.GL_TEXTURE_2D, id); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, getGLMode(wrapMode)); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, getGLMode(wrapMode)); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, getGlMinFilter(filterMode)); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, getGlMagFilter(filterMode)); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 4); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, data.getBuffers().length - 1); if (data.getBuffers().length > 0) { for (int i = 0; i < data.getBuffers().length; i++) { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, i, GL11.GL_RGBA, width >> i, height >> i, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data.getBuffers()[i]); } } else { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); } break; case TEXTURE3D: logger.debug("Bound texture '{}' - {}", getURI(), id); glBindTexture(GL12.GL_TEXTURE_3D, id); glTexParameterf(GL12.GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, getGLMode(wrapMode)); glTexParameterf(GL12.GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, getGLMode(wrapMode)); glTexParameterf(GL12.GL_TEXTURE_3D, GL12.GL_TEXTURE_WRAP_R, getGLMode(wrapMode)); GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL11.GL_TEXTURE_MIN_FILTER, getGlMinFilter(filterMode)); GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL11.GL_TEXTURE_MAG_FILTER, getGlMagFilter(filterMode)); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 4); GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL12.GL_TEXTURE_MAX_LEVEL, data.getBuffers().length - 1); if (data.getBuffers().length > 0) { for (int i = 0; i < data.getBuffers().length; i++) { GL12.glTexImage3D(GL12.GL_TEXTURE_3D, i, GL11.GL_RGBA, width, height, depth, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data.getBuffers()[i]); } } else { GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL11.GL_RGBA, width, height, depth, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); } break; } }