/** Disposes any pixmap pages which don't have a texture. Page pixmaps that have a texture will not be disposed until their * texture is disposed. */ public synchronized void dispose () { for (Page page : pages) { if (page.texture == null) { page.image.dispose(); } } disposed = true; }
/** Disposes any pixmap pages which don't have a texture. Page pixmaps that have a texture will not be disposed until their * texture is disposed. */ public synchronized void dispose () { for (Page page : pages) { if (page.texture == null) { page.image.dispose(); } } disposed = true; }
@Override public void dispose () { super.dispose(); image.dispose(); } };
@Override public void dispose () { if (debugPixmap != null) { debugPixmap.dispose(); debugTexture.dispose(); debugPixmap = null; debugTexture = null; } }
@Override public void dispose () { super.dispose(); image.dispose(); } };
static void setIcon(long windowHandle, String[] imagePaths, Files.FileType imageFileType) { if (SharedLibraryLoader.isMac) return; Pixmap[] pixmaps = new Pixmap[imagePaths.length]; for (int i = 0; i < imagePaths.length; i++) { pixmaps[i] = new Pixmap(Gdx.files.getFileHandle(imagePaths[i], imageFileType)); } setIcon(windowHandle, pixmaps); for (Pixmap pixmap : pixmaps) { pixmap.dispose(); } }
static void setIcon(long windowHandle, String[] imagePaths, Files.FileType imageFileType) { if (SharedLibraryLoader.isMac) return; Pixmap[] pixmaps = new Pixmap[imagePaths.length]; for (int i = 0; i < imagePaths.length; i++) { pixmaps[i] = new Pixmap(Gdx.files.getFileHandle(imagePaths[i], imageFileType)); } setIcon(windowHandle, pixmaps); for (Pixmap pixmap : pixmaps) { pixmap.dispose(); } }
@Override public void dispose() { if (pixmapCopy == null) { throw new GdxRuntimeException("Cursor already disposed"); } cursors.removeValue(this, true); pixmapCopy.dispose(); pixmapCopy = null; glfwImage.free(); GLFW.glfwDestroyCursor(glfwCursor); }
@Override public void dispose() { if (pixmapCopy == null) { throw new GdxRuntimeException("Cursor already disposed"); } cursors.removeValue(this, true); pixmapCopy.dispose(); pixmapCopy = null; glfwImage.free(); GLFW.glfwDestroyCursor(glfwCursor); }
@Override public void create () { spriteBatch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); Pixmap pixmap = new Pixmap(32, 32, Format.RGB565); pixmap.setColor(1, 1, 0, 0.7f); pixmap.fill(); texture2 = new Texture(pixmap); pixmap.dispose(); for (int i = 0; i < coords.length; i += 2) { coords[i] = (int)(Math.random() * Gdx.graphics.getWidth()); coords[i + 1] = (int)(Math.random() * Gdx.graphics.getHeight()); coords2[i] = (int)(Math.random() * Gdx.graphics.getWidth()); coords2[i + 1] = (int)(Math.random() * Gdx.graphics.getHeight()); } }
@Override protected void processFile (Entry entry) throws Exception { System.out.println("Processing " + entry.inputFile); Pixmap pixmap = new Pixmap(new FileHandle(entry.inputFile)); if (pixmap.getFormat() != Format.RGB888 && pixmap.getFormat() != Format.RGB565) { System.out.println("Converting from " + pixmap.getFormat() + " to RGB888!"); Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Format.RGB888); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); pixmap = tmp; } ETC1.encodeImagePKM(pixmap).write(new FileHandle(entry.outputFile)); pixmap.dispose(); }
@Override protected void processFile (Entry entry) throws Exception { System.out.println("Processing " + entry.inputFile); Pixmap pixmap = new Pixmap(new FileHandle(entry.inputFile)); if (pixmap.getFormat() != Format.RGB888 && pixmap.getFormat() != Format.RGB565) { System.out.println("Converting from " + pixmap.getFormat() + " to RGB888!"); Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Format.RGB888); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); pixmap = tmp; } ETC1.encodeImagePKM(pixmap).write(new FileHandle(entry.outputFile)); pixmap.dispose(); }
@Override public void create () { Pixmap pixmap = new Pixmap(256, 256, Format.RGBA8888); pixmap.setColor(1, 0, 0, 1); pixmap.fill(); texture = new Texture(pixmap, false); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); batch = new SpriteBatch(); pixmap.dispose(); }
private void createTexture () { Pixmap pixmap = new Pixmap(256, 256, Format.RGBA8888); pixmap.setColor(1, 1, 1, 1); pixmap.fill(); pixmap.setColor(0, 0, 0, 1); pixmap.drawLine(0, 0, 256, 256); pixmap.drawLine(256, 0, 0, 256); texture = new Texture(pixmap); pixmap.dispose(); pixmap = new Pixmap(256, 256, Format.RGBA8888); pixmap.setColor(1, 1, 1, 1); pixmap.fill(); pixmap.setColor(0, 0, 0, 1); pixmap.drawLine(128, 0, 128, 256); texture2 = new Texture(pixmap); pixmap.dispose(); }
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(texture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.end(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); int color = pixmap.getPixel(0, pixmap.getHeight() - 1); Gdx.app.log("AlphaTest", Integer.toHexString(color)); pixmap.dispose(); }
@Override public void create () { if (spriteBatch != null) return; spriteBatch = new SpriteBatch(); Matrix4 transform = new Matrix4(); transform.setToTranslation(0, Gdx.graphics.getHeight(), 0); transform.mul(new Matrix4().setToScaling(1, -1, 1)); spriteBatch.setTransformMatrix(transform); pixS1 = new Pixmap(Gdx.files.getFileHandle("data/test4.png", Files.FileType.Internal)); pixS2 = new Pixmap(Gdx.files.getFileHandle("data/test3.png", Files.FileType.Internal)); pixD = new Pixmap(512, 1024, Pixmap.Format.RGBA8888); pixD.setBlending(Pixmap.Blending.SourceOver); pixD.setFilter(Pixmap.Filter.NearestNeighbour); pixD.drawPixmap(pixS1, 0, 0, 38, 76, 0, 0, 512, 1024); pixD.drawPixmap(pixS2, 0, 0, 38, 76, 0, 0, 512, 1024); logoSprite = new Sprite(new Texture(pixD)); logoSprite.flip(false, true); pixS1.dispose(); pixS2.dispose(); pixD.dispose(); }
@Override public void create () { font = new BitmapFont(); camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); controller = new OrthoCamController(camera); Gdx.input.setInputProcessor(controller); Pixmap pixmap = new Pixmap(32, 32, Format.RGB565); pixmap.setColor(1, 0, 0, 1); pixmap.fill(); pixmap.setColor(0, 1, 0, 1); pixmap.drawLine(0, 0, 32, 32); pixmap.drawLine(0, 32, 32, 0); ETC1Data encodedImage = ETC1.encodeImagePKM(pixmap); pixmap.dispose(); pixmap = ETC1.decodeImage(encodedImage, Format.RGB565); encodedImage.dispose(); img1 = new Texture(pixmap); img2 = new Texture("data/test.etc1"); batch = new SpriteBatch(); pixmap.dispose(); }
@Override public void consumeCustomData (int target) { if (!isPrepared) throw new GdxRuntimeException("Call prepare() before calling consumeCompressedData()"); if (!Gdx.graphics.supportsExtension("GL_OES_compressed_ETC1_RGB8_texture")) { Pixmap pixmap = ETC1.decodeImage(data, Format.RGB565); Gdx.gl.glTexImage2D(target, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); if (useMipMaps) MipMapGenerator.generateMipMap(target, pixmap, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); useMipMaps = false; } else { Gdx.gl.glCompressedTexImage2D(target, 0, ETC1.ETC1_RGB8_OES, width, height, 0, data.compressedData.capacity() - data.dataOffset, data.compressedData); if (useMipMaps()) Gdx.gl20.glGenerateMipmap(GL20.GL_TEXTURE_2D); } data.dispose(); data = null; isPrepared = false; }
@Override public void consumeCustomData (int target) { if (!isPrepared) throw new GdxRuntimeException("Call prepare() before calling consumeCompressedData()"); if (!Gdx.graphics.supportsExtension("GL_OES_compressed_ETC1_RGB8_texture")) { Pixmap pixmap = ETC1.decodeImage(data, Format.RGB565); Gdx.gl.glTexImage2D(target, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); if (useMipMaps) MipMapGenerator.generateMipMap(target, pixmap, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); useMipMaps = false; } else { Gdx.gl.glCompressedTexImage2D(target, 0, ETC1.ETC1_RGB8_OES, width, height, 0, data.compressedData.capacity() - data.dataOffset, data.compressedData); if (useMipMaps()) Gdx.gl20.glGenerateMipmap(GL20.GL_TEXTURE_2D); } data.dispose(); data = null; isPrepared = false; }
private static void generateMipMapCPU (int target, Pixmap pixmap, int textureWidth, int textureHeight) { Gdx.gl.glTexImage2D(target, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); if ((Gdx.gl20 == null) && textureWidth != textureHeight) throw new GdxRuntimeException("texture width and height must be square when using mipmapping."); int width = pixmap.getWidth() / 2; int height = pixmap.getHeight() / 2; int level = 1; while (width > 0 && height > 0) { Pixmap tmp = new Pixmap(width, height, pixmap.getFormat()); tmp.setBlending(Blending.None); tmp.drawPixmap(pixmap, 0, 0, pixmap.getWidth(), pixmap.getHeight(), 0, 0, width, height); if (level > 1) pixmap.dispose(); pixmap = tmp; Gdx.gl.glTexImage2D(target, level, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); width = pixmap.getWidth() / 2; height = pixmap.getHeight() / 2; level++; } } }