List of usage examples for org.lwjgl.opengl GL11 glGetTexImage
public static void glGetTexImage(@NativeType("GLenum") int tex, @NativeType("GLint") int level, @NativeType("GLenum") int format, @NativeType("GLenum") int type, @NativeType("void *") double[] pixels)
From source file:com.badlogic.gdx.hiero.BMFontUtil.java
License:Apache License
public void save(File outputBMFontFile) throws IOException { File outputDir = outputBMFontFile.getParentFile(); String outputName = outputBMFontFile.getName(); if (outputName.endsWith(".fnt")) outputName = outputName.substring(0, outputName.length() - 4); unicodeFont.loadGlyphs();//from w ww . ja va 2 s .com PrintStream out = new PrintStream(new FileOutputStream(new File(outputDir, outputName + ".fnt"))); Font font = unicodeFont.getFont(); int pageWidth = unicodeFont.getGlyphPageWidth(); int pageHeight = unicodeFont.getGlyphPageHeight(); out.println("info face=\"" + font.getFontName() + "\" size=" + font.getSize() + " bold=" + (font.isBold() ? 1 : 0) + " italic=" + (font.isItalic() ? 1 : 0) + " charset=\"\" unicode=0 stretchH=100 smooth=1 aa=1 padding=" + unicodeFont.getPaddingTop() + "," + unicodeFont.getPaddingLeft() + "," + unicodeFont.getPaddingBottom() + "," + unicodeFont.getPaddingRight() + " spacing=" + unicodeFont.getPaddingAdvanceX() + "," + unicodeFont.getPaddingAdvanceY()); out.println("common lineHeight=" + unicodeFont.getLineHeight() + " base=" + unicodeFont.getAscent() + " scaleW=" + pageWidth + " scaleH=" + pageHeight + " pages=" + unicodeFont.getGlyphPages().size() + " packed=0"); int pageIndex = 0, glyphCount = 0; for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext();) { GlyphPage page = (GlyphPage) pageIter.next(); String fileName; if (pageIndex == 0 && !pageIter.hasNext()) fileName = outputName + ".png"; else fileName = outputName + (pageIndex + 1) + ".png"; out.println("page id=" + pageIndex + " file=\"" + fileName + "\""); glyphCount += page.getGlyphs().size(); pageIndex++; } out.println("chars count=" + glyphCount); // Always output space entry (codepoint 32). int[] glyphMetrics = getGlyphMetrics(font, 32); int xAdvance = glyphMetrics[1]; out.println("char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=" + unicodeFont.getAscent() + " xadvance=" + xAdvance + " page=0 chnl=0 "); pageIndex = 0; List allGlyphs = new ArrayList(512); for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext();) { GlyphPage page = (GlyphPage) pageIter.next(); for (Iterator glyphIter = page.getGlyphs().iterator(); glyphIter.hasNext();) { Glyph glyph = (Glyph) glyphIter.next(); glyphMetrics = getGlyphMetrics(font, glyph.getCodePoint()); int xOffset = glyphMetrics[0]; xAdvance = glyphMetrics[1]; out.println("char id=" + glyph.getCodePoint() + " " + "x=" + (int) (glyph.getU() * pageWidth) + " y=" + (int) (glyph.getV() * pageHeight) + " width=" + glyph.getWidth() + " height=" + glyph.getHeight() + " xoffset=" + xOffset + " yoffset=" + glyph.getYOffset() + " xadvance=" + xAdvance + " page=" + pageIndex + " chnl=0 "); } allGlyphs.addAll(page.getGlyphs()); pageIndex++; } String ttfFileRef = unicodeFont.getFontFile(); if (ttfFileRef == null) System.out .println("Kerning information could not be output because a TTF font file was not specified."); else { Kerning kerning = new Kerning(); try { kerning.load(Gdx.files.internal(ttfFileRef).read(), font.getSize()); } catch (IOException ex) { System.out.println("Unable to read kerning information from font: " + ttfFileRef); } Map glyphCodeToCodePoint = new HashMap(); for (Iterator iter = allGlyphs.iterator(); iter.hasNext();) { Glyph glyph = (Glyph) iter.next(); glyphCodeToCodePoint.put(new Integer(getGlyphCode(font, glyph.getCodePoint())), new Integer(glyph.getCodePoint())); } List kernings = new ArrayList(256); class KerningPair { public int firstCodePoint, secondCodePoint, offset; } for (Iterator iter1 = allGlyphs.iterator(); iter1.hasNext();) { Glyph firstGlyph = (Glyph) iter1.next(); int firstGlyphCode = getGlyphCode(font, firstGlyph.getCodePoint()); int[] values = kerning.getValues(firstGlyphCode); if (values == null) continue; for (int i = 0; i < values.length; i++) { Integer secondCodePoint = (Integer) glyphCodeToCodePoint.get(new Integer(values[i] & 0xffff)); if (secondCodePoint == null) continue; // We may not be outputting the second character. int offset = values[i] >> 16; KerningPair pair = new KerningPair(); pair.firstCodePoint = firstGlyph.getCodePoint(); pair.secondCodePoint = secondCodePoint.intValue(); pair.offset = offset; kernings.add(pair); } } out.println("kernings count=" + kerning.getCount()); for (Iterator iter = kernings.iterator(); iter.hasNext();) { KerningPair pair = (KerningPair) iter.next(); out.println("kerning first=" + pair.firstCodePoint + " second=" + pair.secondCodePoint + " amount=" + pair.offset); } } out.close(); int width = unicodeFont.getGlyphPageWidth(); int height = unicodeFont.getGlyphPageHeight(); IntBuffer buffer = BufferUtils.createIntBuffer(width * height); BufferedImage pageImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); int[] row = new int[width]; pageIndex = 0; for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext();) { GlyphPage page = (GlyphPage) pageIter.next(); String fileName; if (pageIndex == 0 && !pageIter.hasNext()) fileName = outputName + ".png"; else fileName = outputName + (pageIndex + 1) + ".png"; page.getTexture().bind(); buffer.clear(); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, buffer); WritableRaster raster = pageImage.getRaster(); for (int y = 0; y < height; y++) { buffer.get(row); raster.setDataElements(0, y, width, 1, row); } File imageOutputFile = new File(outputDir, fileName); ImageIO.write(pageImage, "png", imageOutputFile); pageIndex++; } }
From source file:com.dinasgames.engine.graphics.Texture.java
public Image copyToImage() { if (mTexture <= 0) { return null; }/*from ww w . jav a 2s. c o m*/ ByteBuffer pixels = BufferUtils.createByteBuffer(mWidth * mHeight * 4); if ((mWidth == mActualWidth && mHeight == mActualHeight) && !mPixelsFlipped) { // Direct copy GL11.glBindTexture(GL11.GL_TEXTURE_2D, mTexture); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixels); } else { ByteBuffer allPixels = BufferUtils.createByteBuffer(mActualWidth * mActualHeight * 4); GL11.glBindTexture(GL11.GL_TEXTURE_2D, mTexture); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, allPixels); byte[] src = allPixels.array(); byte[] dst = pixels.array(); int srcPitch = mActualWidth * 4; int dstPitch = mActualHeight * 4; int srcI = 0; int dstI = 0; if (mPixelsFlipped) { srcI += srcPitch * (mHeight - 1); srcPitch = -srcPitch; } int k = 0; for (int i = 0; i < mHeight; i++) { for (int j = 0; j < dstPitch; j++) { dst[k++] = src[i + j]; } srcI += srcPitch; dstI += dstPitch; } } // Create the image Image image = new Image(); image.create(mWidth, mHeight, pixels.array()); return image; }
From source file:com.flowpowered.caustic.lwjgl.gl20.GL20Texture.java
License:MIT License
@Override public ByteBuffer getImageData(InternalFormat format) { checkCreated();//from ww w . j a v a 2 s.c om // Bind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // Create the image buffer final boolean formatNotNull = format != null; final ByteBuffer imageData = CausticUtil .createByteBuffer(width * height * (formatNotNull ? format.getBytes() : this.format.getComponentCount() * DataType.UNSIGNED_BYTE.getByteSize())); // Use byte alignment GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); // Get the image data GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, formatNotNull ? format.getFormat().getGLConstant() : this.format.getGLConstant(), formatNotNull ? format.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); // Unbind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); // Check for errors LWJGLUtil.checkForGLError(); return imageData; }
From source file:com.golemgame.states.StateManager.java
License:Open Source License
public static BufferedImage captureScreenRender() { int size = 256; Renderer r = DisplaySystem.getDisplaySystem().getRenderer(); TextureRenderer tRenderer = DisplaySystem.getDisplaySystem().createTextureRenderer(size, size, TextureRenderer.RENDER_TEXTURE_2D); // set the texture renderers camera to match the worlds camera tRenderer.getCamera().setLocation(r.getCamera().getLocation()); tRenderer.getCamera().setAxes(r.getCamera().getLeft(), r.getCamera().getUp(), r.getCamera().getDirection()); tRenderer.getCamera().update();/*from www . j ava2 s . c o m*/ Texture texture = new Texture(); texture.setMipmapState(Texture.MM_LINEAR); texture.setFilter(Texture.FM_NEAREST); tRenderer.setupTexture(texture); // tRenderer.render(StateManager.getMachineSpace().getSpatial(),texture); if (StateManager.getCameraManager().getSkyBoxManager().isEnabled()) { boolean overlayenabled = StateManager.getCameraManager().getSkyBoxManager().isOverlayEnabled(); StateManager.getCameraManager().getSkyBoxManager().setTextureRenderMode(true); StateManager.getCameraManager().getSkyBoxManager().setOverlayEnabled(false); // StateManager.getCameraManager().getSkyBoxManager(). // something magical has to happen after the sky box has its texture // reset before the render will succeed. // StateManager.getCameraManager().getSkyBoxManager().getSkyBoxSpatial().updateGeometricState(0, // true); // StateManager.getCameraManager().getCameraLocationNode().updateRenderState(); // StateManager.getDesignState().getRootNode().updateRenderState(); // StateManager.getCameraManager().getSkyBoxManager().setOverlayEnabled(true); // StateManager.getDesignState().getRootNode().updateRenderState(); // tRenderer.render(StateManager.getCameraManager().getSkyBoxManager().getSkyBoxSpatial(),texture); tRenderer.render(StateManager.getDesignState().getRootNode(), texture, true); StateManager.getCameraManager().getSkyBoxManager().setTextureRenderMode(false); StateManager.getCameraManager().getSkyBoxManager().setOverlayEnabled(overlayenabled); } IntBuffer buff = ByteBuffer.allocateDirect(tRenderer.getWidth() * tRenderer.getHeight() * 4) .order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); LWJGLTextureState.doTextureBind(texture.getTextureId(), 0); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff); int[] data = new int[size * size]; buff.get(data); BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_BGR);// bgr // is // important // - // thats // the // order // that // matches // the // gl img.getRaster().setDataElements(0, 0, size, size, data); BufferedImage img2 = new BufferedImage(size, size, BufferedImage.TYPE_INT_BGR); Graphics2D g = img2.createGraphics(); g.drawImage(img, 0, size, size, 0, 0, 0, size, size, null); return img2; }
From source file:com.microsoft.Malmo.MissionHandlers.LuminanceProducerImplementation.java
License:Open Source License
@Override public void getFrame(MissionInit missionInit, ByteBuffer buffer) { final int width = getWidth(); final int height = getHeight(); // Render the Minecraft frame into our own FBO, at the desired size: OpenGlHelper.glUseProgram(shaderID); this.fbo.bindFramebuffer(true); Minecraft.getMinecraft().getFramebuffer().framebufferRenderExt(width, height, true); GlStateManager.bindTexture(this.fbo.framebufferTexture); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL_RED, GL_UNSIGNED_BYTE, buffer); this.fbo.unbindFramebuffer(); OpenGlHelper.glUseProgram(0);/*from w w w . jav a 2 s. c o m*/ }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLTexture.java
License:Open Source License
public float[][] toHeightMap(int samplesX, int samplesY) { float[][] height = new float[samplesX][samplesY]; ML.d(String.format("Loading texture for height map \"%s\"...", getName())); // check size int texSizeX = getSizeX(); int texSizeY = getSizeY(); if (texSizeX != samplesX | texSizeY != samplesY) ML.f(String.format("Texture size doesn't match height map size! (%d x %d) vs. (%d x %d)", texSizeX, texSizeY, samplesX, samplesY)); // create buffer ShortBuffer byteBuffer = BufferUtils.createShortBuffer(texSizeX * texSizeY); // and go//from w ww .j ava 2 s. c o m GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RED, GL11.GL_UNSIGNED_SHORT, byteBuffer); int error = GL11.glGetError(); if (error != GL11.GL_NO_ERROR) ML.f(String.format("Cannot load height map from texture (GL error %x)", error)); // read samples for (int x = 0; x < texSizeX; x++) for (int y = 0; y < texSizeY; y++) { short sValue = byteBuffer.get((samplesX * y + x)); int value = fromShort(sValue); height[x][y] = value / 65535.0f; } return height; }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLTexture.java
License:Open Source License
public TerrainType[][] toTerrainMap(int samplesX, int samplesY) { TerrainType[][] height = new TerrainType[samplesX][samplesY]; ML.d(String.format("Loading texture for terrain map \"%s\"...", getName())); // check size int texSizeX = getSizeX(); int texSizeY = getSizeY(); if (texSizeX != samplesX | texSizeY != samplesY) ML.f(String.format("Texture size doesn't match terrain map size! (%d x %d) vs. (%d x %d)", texSizeX, texSizeY, samplesX, samplesY)); // create buffer ByteBuffer byteBuffer = BufferUtils.createByteBuffer(texSizeX * texSizeY * 4); // and go//from www . ja v a2s. com GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, byteBuffer); int error = GL11.glGetError(); if (error != GL11.GL_NO_ERROR) ML.f(String.format("Cannot load terrain map from texture (GL error %x)", error)); // read samples for (int x = 0; x < texSizeX; x++) for (int y = 0; y < texSizeY; y++) { float r = fromByte(byteBuffer.get(4 * (samplesX * y + x))) / 255.0f; float g = fromByte(byteBuffer.get(4 * (samplesX * y + x) + 1)) / 255.0f; float b = fromByte(byteBuffer.get(4 * (samplesX * y + x) + 2)) / 255.0f; height[x][y] = TerrainType.fromColor(r, g, b); } return height; }
From source file:io.root.gfx.glutils.GL.java
License:Apache License
public static void glGetTexImage(int target, int level, int format, int type, ByteBuffer pixels) { GL11.glGetTexImage(target, level, format, type, pixels); }
From source file:itemrender.client.rendering.FBOHelper.java
License:MIT License
public void saveToFile(File file) { // Bind framebuffer texture GlStateManager.bindTexture(textureID); GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH); int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT); IntBuffer texture = BufferUtils.createIntBuffer(width * height); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, texture); int[] texture_array = new int[width * height]; texture.get(texture_array);//from w ww . j a v a 2 s. c o m BufferedImage image = new BufferedImage(renderTextureSize, renderTextureSize, BufferedImage.TYPE_INT_ARGB); image.setRGB(0, 0, renderTextureSize, renderTextureSize, texture_array, 0, width); file.mkdirs(); try { ImageIO.write(image, "png", file); } catch (Exception e) { // Do nothing } }
From source file:itemrender.client.rendering.FBOHelper.java
License:MIT License
public String getBase64() { // Bind framebuffer texture GlStateManager.bindTexture(textureID); GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH); int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT); IntBuffer texture = BufferUtils.createIntBuffer(width * height); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, texture); int[] texture_array = new int[width * height]; texture.get(texture_array);/* ww w .j a v a 2s . co m*/ BufferedImage image = new BufferedImage(renderTextureSize, renderTextureSize, BufferedImage.TYPE_INT_ARGB); image.setRGB(0, 0, renderTextureSize, renderTextureSize, texture_array, 0, width); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(image, "PNG", out); } catch (IOException e) { // Do nothing } return Base64.encodeBase64String(out.toByteArray()); }