Refine search
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++; } } }
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(); }
/** Draws an area from another Pixmap to this Pixmap. * * @param pixmap The other Pixmap * @param x The target x-coordinate (top left corner) * @param y The target y-coordinate (top left corner) */ public void drawPixmap (Pixmap pixmap, int x, int y) { drawPixmap(pixmap, x, y, 0, 0, pixmap.getWidth(), pixmap.getHeight()); }
public FileTextureData (FileHandle file, Pixmap preloadedPixmap, Format format, boolean useMipMaps) { this.file = file; this.pixmap = preloadedPixmap; this.format = format; this.useMipMaps = useMipMaps; if (pixmap != null) { width = pixmap.getWidth(); height = pixmap.getHeight(); if (format == null) this.format = pixmap.getFormat(); } }
Pixmap pixmapToDispose = null; if (isPatch) { rect = new PixmapPackerRectangle(0, 0, image.getWidth() - 2, image.getHeight() - 2); pixmapToDispose = new Pixmap(image.getWidth() - 2, image.getHeight() - 2, image.getFormat()); rect.splits = getSplits(image); rect.pads = getPads(image, rect.splits); pixmapToDispose.drawPixmap(image, 0, 0, 1, 1, image.getWidth() - 1, image.getHeight() - 1); image = pixmapToDispose; name = name.split("\\.")[0]; } else { if (stripWhitespaceX || stripWhitespaceY) { int originalWidth = image.getWidth(); int originalHeight = image.getHeight(); int bottom = image.getHeight(); if (stripWhitespaceY) { outer: for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int pixel = image.getPixel(x, y); int alpha = ((pixel & 0x000000ff)); if (alpha > alphaThreshold) break outer; for (int y = image.getHeight(); --y >= top;) { for (int x = 0; x < image.getWidth(); x++) { int pixel = image.getPixel(x, y); int alpha = ((pixel & 0x000000ff)); if (alpha > alphaThreshold) break outer;
texHeight = etc1.height; } else { facePixmap = new Pixmap(file); facePixmap.setBlending(Blending.None); facePixmap.setFilter(Filter.BiLinear); nLevels = 1; texWidth = facePixmap.getWidth(); texHeight = facePixmap.getHeight(); levelPixmap = new Pixmap(levelWidth, levelHeight, facePixmap.getFormat()); levelPixmap.setBlending(Blending.None); levelPixmap.setFilter(Filter.BiLinear); levelPixmap.drawPixmap(facePixmap, 0, 0, facePixmap.getWidth(), facePixmap.getHeight(), 0, 0, levelPixmap.getWidth(), levelPixmap.getHeight()); int w = levelPixmap.getWidth(), h = levelPixmap.getHeight(); Pixmap pm = new Pixmap(w, h * 2, levelPixmap.getFormat()); pm.setBlending(Blending.None); pm.setFilter(Filter.BiLinear); pm.drawPixmap(levelPixmap, 0, 0); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int alpha = (levelPixmap.getPixel(x, y)) & 0x0FF; pm.drawPixel(x, y + h, (alpha << 24) | (alpha << 16) | (alpha << 8) | 0x0FF); levelPixmap.dispose(); levelPixmap = pm; levelETCData = null;
public void set (final Pixmap map) { if (map.getWidth() != width || map.getHeight() != height) throw new GdxRuntimeException("Incorrect map size"); set(map.getPixels(), map.getFormat()); }
borderPixmap.drawPixmap(mainPixmap, offsetX, offsetY); mainPixmap.dispose(); mainGlyph.dispose(); mainPixmap = borderPixmap; int mainW = mainPixmap.getWidth(), mainH = mainPixmap.getHeight(); int shadowOffsetX = Math.max(parameter.shadowOffsetX, 0), shadowOffsetY = Math.max(parameter.shadowOffsetY, 0); int shadowW = mainW + Math.abs(parameter.shadowOffsetX), shadowH = mainH + Math.abs(parameter.shadowOffsetY); Pixmap shadowPixmap = new Pixmap(shadowW, shadowH, mainPixmap.getFormat()); if (a != 0) { byte r = (byte)(shadowColor.r * 255), g = (byte)(shadowColor.g * 255), b = (byte)(shadowColor.b * 255); ByteBuffer mainPixels = mainPixmap.getPixels(); ByteBuffer shadowPixels = shadowPixmap.getPixels(); for (int y = 0; y < mainH; y++) { int shadowRow = shadowW * (y + shadowOffsetY) + shadowOffsetX; shadowPixmap.drawPixmap(mainPixmap, Math.max(-parameter.shadowOffsetX, 0), Math.max(-parameter.shadowOffsetY, 0)); mainPixmap.dispose(); mainPixmap = shadowPixmap; } else if (parameter.borderWidth == 0) { mainPixmap.drawPixmap(mainPixmap, 0, 0); Pixmap padPixmap = new Pixmap(mainPixmap.getWidth() + parameter.padLeft + parameter.padRight, mainPixmap.getHeight() + parameter.padTop + parameter.padBottom, mainPixmap.getFormat()); padPixmap.drawPixmap(mainPixmap, parameter.padLeft, parameter.padTop); mainPixmap.dispose();
public void create () { // Create an empty dynamic pixmap pixmap = new Pixmap(800, 480, Pixmap.Format.RGBA8888); // Pixmap.Format.RGBA8888); // Create a texture to contain the pixmap texture = new Texture(1024, 1024, Pixmap.Format.RGBA8888); // Pixmap.Format.RGBA8888); texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Linear); texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge); pixmap.setColor(1.0f, 0.0f, 0.0f, 1.0f); // Red pixmap.drawLine(0, 0, 100, 100); pixmap.setColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue pixmap.drawLine(100, 100, 200, 0); pixmap.setColor(0.0f, 1.0f, 0.0f, 1.0f); // Green pixmap.drawLine(100, 0, 100, 100); pixmap.setColor(1.0f, 1.0f, 1.0f, 1.0f); // White pixmap.drawCircle(400, 300, 100); // Blit the composited overlay to a texture texture.draw(pixmap, 0, 0); region = new TextureRegion(texture, 0, 0, 800, 480); batch = new SpriteBatch(); Pixmap pixmap = new Pixmap(512, 1024, Pixmap.Format.RGBA8888); for (int y = 0; y < pixmap.getHeight(); y++) { // 1024 for (int x = 0; x < pixmap.getWidth(); x++) { // 512 pixmap.getPixel(x, y); } } pixmap.dispose(); }
Lwjgl3Cursor(Lwjgl3Window window, Pixmap pixmap, int xHotspot, int yHotspot) { this.window = window; if (pixmap.getFormat() != Pixmap.Format.RGBA8888) { throw new GdxRuntimeException("Cursor image pixmap is not in RGBA8888 format."); } if ((pixmap.getWidth() & (pixmap.getWidth() - 1)) != 0) { throw new GdxRuntimeException( "Cursor image pixmap width of " + pixmap.getWidth() + " is not a power-of-two greater than zero."); } if ((pixmap.getHeight() & (pixmap.getHeight() - 1)) != 0) { throw new GdxRuntimeException("Cursor image pixmap height of " + pixmap.getHeight() + " is not a power-of-two greater than zero."); } if (xHotspot < 0 || xHotspot >= pixmap.getWidth()) { throw new GdxRuntimeException("xHotspot coordinate of " + xHotspot + " is not within image width bounds: [0, " + pixmap.getWidth() + ")."); } if (yHotspot < 0 || yHotspot >= pixmap.getHeight()) { throw new GdxRuntimeException("yHotspot coordinate of " + yHotspot + " is not within image height bounds: [0, " + pixmap.getHeight() + ")."); } this.pixmapCopy = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Pixmap.Format.RGBA8888); this.pixmapCopy.drawPixmap(pixmap, 0, 0); glfwImage = GLFWImage.malloc(); glfwImage.width(pixmapCopy.getWidth()); glfwImage.height(pixmapCopy.getHeight()); glfwImage.pixels(pixmapCopy.getPixels()); glfwCursor = GLFW.glfwCreateCursor(glfwImage, xHotspot, yHotspot); cursors.add(this); }
@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(); }
public Pixmap flipPixmap(Pixmap src) { final int width = src.getWidth(); final int height = src.getHeight(); Pixmap flipped = new Pixmap(width, height, src.getFormat()); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { flipped.drawPixel(x, y, src.getPixel(width - x - 1, y)); } } return flipped; }
@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 prepare () { if (isPrepared) throw new GdxRuntimeException("Already prepared"); if (pixmap == null) { if (file.extension().equals("cim")) pixmap = PixmapIO.readCIM(file); else pixmap = new Pixmap(file); width = pixmap.getWidth(); height = pixmap.getHeight(); if (format == null) format = pixmap.getFormat(); } isPrepared = true; }
/** Draws the given {@link Pixmap} to the texture at position x, y. No clipping is performed so you have to make sure that you * draw only inside the texture region. Note that this will only draw to mipmap level 0! * * @param pixmap The Pixmap * @param x The x coordinate in pixels * @param y The y coordinate in pixels */ public void draw (Pixmap pixmap, int x, int y) { if (data.isManaged()) throw new GdxRuntimeException("can't draw to a managed texture"); bind(); Gdx.gl.glTexSubImage2D(glTarget, 0, x, y, pixmap.getWidth(), pixmap.getHeight(), pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); }
private static void generateMipMapGLES20 (int target, Pixmap pixmap) { Gdx.gl.glTexImage2D(target, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); Gdx.gl20.glGenerateMipmap(target); }
private void createTexture () { Pixmap pixmap = new Pixmap(256, 256, Format.RGB565); boolean useRed = true; for (int y = 0; y < 256; y += 8) { for (int x = 0; x < 256; x += 8) { pixmap.setColor(useRed ? 1 : 0, 0, useRed ? 0 : 1, 1); pixmap.fillRectangle(x, y, 8, 8); useRed = !useRed; } useRed = !useRed; } texture = new Texture(pixmap, true); texture.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear); }
@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(); }
/** Returns a portion of the default framebuffer contents specified by x, y, width and height as a {@link TextureRegion} with * the same dimensions. The base {@link Texture} always has {@link MathUtils#nextPowerOfTwo} dimensions and RGBA8888 * {@link Format}. It can be accessed via {@link TextureRegion#getTexture}. This texture is not managed and has to be reloaded * manually on a context loss. If the width and height specified are larger than the framebuffer dimensions, the Texture will * be padded accordingly. Pixels that fall outside of the current screen will have RGBA values of 0. * * @param x the x position of the framebuffer contents to capture * @param y the y position of the framebuffer contents to capture * @param w the width of the framebuffer contents to capture * @param h the height of the framebuffer contents to capture */ public static TextureRegion getFrameBufferTexture (int x, int y, int w, int h) { final int potW = MathUtils.nextPowerOfTwo(w); final int potH = MathUtils.nextPowerOfTwo(h); final Pixmap pixmap = getFrameBufferPixmap(x, y, w, h); final Pixmap potPixmap = new Pixmap(potW, potH, Format.RGBA8888); potPixmap.drawPixmap(pixmap, 0, 0); Texture texture = new Texture(potPixmap); TextureRegion textureRegion = new TextureRegion(texture, 0, h, w, -h); potPixmap.dispose(); pixmap.dispose(); return textureRegion; }
static public Pixmap read (FileHandle file) { DataInputStream in = null; try { // long start = System.nanoTime(); in = new DataInputStream(new InflaterInputStream(new BufferedInputStream(file.read()))); int width = in.readInt(); int height = in.readInt(); Format format = Format.fromGdx2DPixmapFormat(in.readInt()); Pixmap pixmap = new Pixmap(width, height, format); ByteBuffer pixelBuf = pixmap.getPixels(); pixelBuf.position(0); pixelBuf.limit(pixelBuf.capacity()); synchronized (readBuffer) { int readBytes = 0; while ((readBytes = in.read(readBuffer)) > 0) { pixelBuf.put(readBuffer, 0, readBytes); } } pixelBuf.position(0); pixelBuf.limit(pixelBuf.capacity()); // Gdx.app.log("PixmapIO", "read:" + (System.nanoTime() - start) / 1000000000.0f); return pixmap; } catch (Exception e) { throw new GdxRuntimeException("Couldn't read Pixmap from file '" + file + "'", e); } finally { StreamUtils.closeQuietly(in); } } }