com.badlogic.gdx.graphics.Pixmap Java Examples
The following examples show how to use
com.badlogic.gdx.graphics.Pixmap.
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: TextureCache.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
public synchronized static SmartTexture createSolid( int color ) { final String key = "1x1:" + color; if (all.containsKey( key )) { return all.get( key ); } else { Pixmap pixmap =new Pixmap( 1, 1, Pixmap.Format.RGBA8888 ); // In the rest of the code ARGB is used pixmap.setColor( (color << 8) | (color >>> 24) ); pixmap.fill(); SmartTexture tx = new SmartTexture( pixmap ); all.put( key, tx ); return tx; } }
Example #2
Source File: ToolHandlePicker.java From Mundus with Apache License 2.0 | 6 votes |
public ToolHandle pick(ToolHandle[] handles, EditorScene scene, int screenX, int screenY) { begin(scene.viewport); renderPickableScene(handles, scene.sceneGraph.batch, scene.cam); end(); Pixmap pm = getFrameBufferPixmap(scene.viewport); int x = screenX - scene.viewport.getScreenX(); int y = screenY - (Gdx.graphics.getHeight() - (scene.viewport.getScreenY() + scene.viewport.getScreenHeight())); int id = PickerColorEncoder.decode(pm.getPixel(x, y)); Log.trace("ToolHandlePicker", "Picking handle with id {}", id); for (ToolHandle handle : handles) { if (handle.getId() == id) { return handle; } } return null; }
Example #3
Source File: MapLoader.java From Bomberman_libGdx with MIT License | 6 votes |
public MapLoader(World b2dWorld, com.artemis.World world, int level) { this.b2dWorld = b2dWorld; this.world = world; this.level = level; assetManager = GameManager.getInstance().getAssetManager(); pixmap = assetManager.get("maps/level_" + level + ".png", Pixmap.class); switch (level) { case 5: tileTextureAtlas = assetManager.get("maps/area_3_tiles.pack", TextureAtlas.class); break; case 4: case 3: tileTextureAtlas = assetManager.get("maps/area_2_tiles.pack", TextureAtlas.class); break; case 2: case 1: default: tileTextureAtlas = assetManager.get("maps/area_1_tiles.pack", TextureAtlas.class); break; } mapWidth = pixmap.getWidth(); mapHeight = pixmap.getHeight(); }
Example #4
Source File: NoiseImage.java From talos with Apache License 2.0 | 6 votes |
/** * @deprecated * * WARNING THIS IS FOR TESTING PURPOSES ONLY, * DO NOT USE AS THIS HAS HORRIBLE PERFORMANCE * * @param batch * @param parentAlpha */ public void drawPixmap(Batch batch, float parentAlpha) { SimplexNoise simplexNoise = new SimplexNoise(); pixmap.setColor(0, 0, 0, 1f); pixmap.fill(); for(int x = 0; x < 165; x++) { for(int y = 0; y < 100; y++) { float v = simplexNoise.query(x/165f, y/100f, frequency) *0.5f + 0.5f; pixmap.setColor(v, v, v, 1f); pixmap.drawPixel(x, y); } } Texture texture = new Texture(pixmap, Pixmap.Format.RGB888, false); batch.draw(texture, getX(), getY()); }
Example #5
Source File: FacedMultiCubemapData.java From gdx-gltf with Apache License 2.0 | 6 votes |
@Override public void consumeCubemapData () { for(int level = 0 ; level<levels ; level++){ for (int i = 0; i < 6; i++) { int index = level * 6 + i; if (data[index].getType() == TextureData.TextureDataType.Custom) { data[index].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i); } else { Pixmap pixmap = data[index].consumePixmap(); boolean disposePixmap = data[index].disposePixmap(); if (data[index].getFormat() != pixmap.getFormat()) { Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data[index].getFormat()); tmp.setBlending(Blending.None); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); if (data[index].disposePixmap()) pixmap.dispose(); pixmap = tmp; disposePixmap = true; } Gdx.gl.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1); Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, level, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); if (disposePixmap) pixmap.dispose(); } } } }
Example #6
Source File: SeparatedDataFileResolver.java From gdx-gltf with Apache License 2.0 | 6 votes |
@Override public Pixmap load(GLTFImage glImage) { if(glImage.uri == null){ throw new GLTFIllegalException("GLTF image URI cannot be null"); }else if(glImage.uri.startsWith("data:")){ // data:application/octet-stream;base64, String [] headerBody = glImage.uri.split(",", 2); String header = headerBody[0]; System.out.println(header); String body = headerBody[1]; byte [] data = Base64Coder.decode(body); return PixmapBinaryLoaderHack.load(data, 0, data.length); }else{ return new Pixmap(path.child(glImage.uri)); } }
Example #7
Source File: PL2.java From riiablo with Apache License 2.0 | 6 votes |
public Texture render() { Pixmap pl2Pixmap = new Pixmap(Palette.COLORS, size, Pixmap.Format.RGBA8888); ByteBuffer buffer = pl2Pixmap.getPixels(); for (int i = 0, j = 0; i < size; i++) { //buffer.put(colormaps[i]); for (int k = 0; k < Palette.COLORS; k++, j += 4) { buffer.put(j, colormaps[i][k]); } } buffer.rewind(); Texture texture = new Texture(pl2Pixmap); //texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge); pl2Pixmap.dispose(); return texture; }
Example #8
Source File: TextureUtil.java From seventh with GNU General Public License v2.0 | 6 votes |
/** * Splits the image * @param image * @param width * @param height * @param row * @param col * @return */ public static Pixmap[] splitPixmap(Pixmap image, int width, int height, int row, int col) { int total = col * row; // total returned images int frame = 0; // frame counter int w = width / col; int h = height / row; Pixmap[] images = new Pixmap[total]; for (int j = 0; j < row; j++) { for (int i = 0; i < col; i++) { Pixmap region = new Pixmap(w, h, image.getFormat()); region.drawPixmap(image, 0, 0, i * w, j * h, w, h); images[frame++] = region; } } return images; }
Example #9
Source File: DC6.java From riiablo with Apache License 2.0 | 6 votes |
@Override public void loadDirection(int d, boolean combineFrames) { if (textures == null) textures = new Texture[header.directions][]; else if (textures[d] != null) return; preloadDirection(d, combineFrames); Pixmap[] pixmaps = this.pixmaps[d]; textures[d] = new Texture[pixmaps.length]; for (int p = 0; p < pixmaps.length; p++) { Pixmap pixmap = pixmaps[p]; Texture texture = new Texture(new PixmapTextureData(pixmap, null, false, false, false)); //texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge); textures[d][p] = texture; } regions[d] = new TextureRegion[pixmaps.length]; for (int p = 0; p < pixmaps.length; p++) { regions[d][p] = new TextureRegion(textures[d][p]); } }
Example #10
Source File: BGImageProcessor.java From beatoraja with GNU General Public License v3.0 | 6 votes |
public BGImageProcessor(int size, int maxgen) { bgacache = new Texture[size]; bgacacheid = new int[size]; cache = new PixmapResourcePool(maxgen) { protected Pixmap convert(Pixmap pixmap) { int bgasize = Math.max(pixmap.getHeight(), pixmap.getWidth()); if ( bgasize <=256 ){ final int fixx = (256 - pixmap.getWidth()) / 2; Pixmap fixpixmap = new Pixmap(256, 256, pixmap.getFormat()); fixpixmap.drawPixmap(pixmap, 0, 0, pixmap.getWidth(), pixmap.getHeight(), fixx, 0, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); return fixpixmap; } return pixmap; } }; }
Example #11
Source File: PixmapTransform.java From libgdx-snippets with MIT License | 6 votes |
public static int getPixelMirrored(Pixmap pixmap, int x, int y, Mirror mirror) { int widthMinusOne = pixmap.getWidth() - 1; int heightMinusOne = pixmap.getHeight() - 1; int px = x, py = y; if (mirror == Mirror.X || mirror == Mirror.XY) { px = widthMinusOne - x; } if (mirror == Mirror.Y || mirror == Mirror.XY) { py = heightMinusOne - y; } return pixmap.getPixel(px, py); }
Example #12
Source File: Cursor.java From riiablo with Apache License 2.0 | 6 votes |
public void setCursor(DC dc, Index colormap, int id) { if (cursor == null) { Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888); cursor = Gdx.graphics.newCursor(pixmap, 0, 0); Gdx.graphics.setCursor(cursor); } this.dc = dc; if (colormap != null) { transform = colormap; transformColor = id; } else { transform = null; transformColor = 0; } }
Example #13
Source File: Crosshair.java From gdx-proto with Apache License 2.0 | 5 votes |
public static Sprite create() { int w = View.width() / 100; int h = w; Pixmap pix = new Pixmap(w, h, Pixmap.Format.RGBA8888); pix.setColor(1f, 1f, 1f, 0.8f); pix.drawLine(w/2, 0, w/2, h); pix.drawLine(0, h/2, w, h/2); pix.setColor(0f, 0f, 0f, 0f); pix.drawPixel(w/2, h/2); Texture tex = new Texture(pix); Sprite sprite = new Sprite(tex); return sprite; // TODO we don't dispose anything, this is just a temporary crosshair }
Example #14
Source File: MotionBlurEffect.java From gdx-vfx with Apache License 2.0 | 5 votes |
public MotionBlurEffect(Pixmap.Format pixelFormat, MixEffect.Method mixMethod, float blurFactor) { mixFilter = register(new MixEffect(mixMethod)); mixFilter.setMixFactor(blurFactor); copyFilter = register(new CopyEffect()); localBuffer = new VfxFrameBufferQueue(pixelFormat, // On WebGL (GWT) we cannot render from/into the same texture simultaneously. // Will use ping-pong approach to avoid "writing into itself". Gdx.app.getType() == Application.ApplicationType.WebGL ? 2 : 1 ); }
Example #15
Source File: AOTextureGenerator.java From Cubes with MIT License | 5 votes |
private static void gaussianPixmap(Pixmap in, double[][] doubleOut) { double[][] doubleIn = new double[in.getWidth()][in.getHeight()]; pixmapToDouble(in, doubleIn); for (int i = 0; i < doubleOut.length; i++) { for (int j = 0; j < doubleOut[i].length; j++) { doubleOut[i][j] = 0; } } Pixmap out = gaussianLocal.get(); int offsetX = (in.getWidth() - out.getWidth()) / 2; int offsetY = (in.getHeight() - out.getHeight()) / 2; for (int x = 0; x < out.getWidth(); x++) { for (int y = 0; y < out.getHeight(); y++) { double d = 0; for (int ox = -gaussianRadius; ox <= gaussianRadius; ox++) { for (int oy = -gaussianRadius; oy <= gaussianRadius; oy++) { d += doubleIn[x + ox + offsetX][y + oy + offsetY] * gwm[ox + gaussianRadius][oy + gaussianRadius]; } } doubleOut[x][y] = d; } } }
Example #16
Source File: VfxRenderContext.java From gdx-vfx with Apache License 2.0 | 5 votes |
public VfxRenderContext(Pixmap.Format pixelFormat, int bufferWidth, int bufferHeight) { this.bufferPool = new VfxFrameBufferPool(pixelFormat, bufferWidth, bufferHeight, 8); this.bufferRenderer = new VfxFrameBufferRenderer(); this.pixelFormat = pixelFormat; this.bufferWidth = bufferWidth; this.bufferHeight = bufferHeight; }
Example #17
Source File: JpegFileTypeModel.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
public void setEncoding(Pixmap.Format encoding) { if (this.encoding == encoding) return; this.encoding = encoding; if (eventDispatcher != null) { eventDispatcher.postEvent(new FileTypePropertyChangedEvent(this, FileTypePropertyChangedEvent.Property.JPEG_ENCODING)); } }
Example #18
Source File: GLTFDemo.java From gdx-gltf with Apache License 2.0 | 5 votes |
protected void setImage(ModelEntry entry) { if(entry.screenshot != null){ if(entry.url != null){ HttpRequest httpRequest = new HttpRequest(HttpMethods.GET); httpRequest.setUrl(entry.url + entry.screenshot); Gdx.net.sendHttpRequest(httpRequest, new SafeHttpResponseListener(){ @Override protected void handleData(byte[] bytes) { Pixmap pixmap = PixmapBinaryLoaderHack.load(bytes, 0, bytes.length); ui.setImage(new Texture(pixmap)); pixmap.dispose(); } @Override protected void handleError(Throwable t) { Gdx.app.error(TAG, "request error", t); } @Override protected void handleEnd() { } }); }else{ FileHandle file = rootFolder.child(entry.name).child(entry.screenshot); if(file.exists()){ ui.setImage(new Texture(file)); }else{ Gdx.app.error("DEMO UI", "file not found " + file.path()); } } } }
Example #19
Source File: FacedMultiCubemapData.java From gdx-gltf with Apache License 2.0 | 5 votes |
/** * Construct Cubemap data for MipMap cubemap. * @param files texture files in following order : * level 0 (positive X, negative X, positive Y, negative Y, positive Z, negative Z) * level 1 (positive X, negative X, positive Y, negative Y, positive Z, negative Z) * and so on. Where level 0 is the biggest texture. Expected levels x 6 files. * @param levels mipmap levels */ public FacedMultiCubemapData(FileHandle[] files, int levels) { this.levels = levels; data = new TextureData[6 * levels]; for(int level = 0 ; level<levels ; level++){ for(int face = 0 ; face < 6 ; face++){ int index = level*6+face; FileHandle file = files[index]; data[index] = new PixmapTextureData(new Pixmap(file), null, false, true); } } }
Example #20
Source File: IBLBuilder.java From gdx-gltf with Apache License 2.0 | 5 votes |
/** * Creates an radiance map, to be used with {@link net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute#SpecularEnv} * generated cubemap contains mipmaps in order to perform roughness in PBR shading * @param levels mipMapLevels how many mipmaps level, eg. 10 levels produce a 1024x1024 cubemap with mipmaps. * @return generated cubemap, caller is responsible to dispose it when no longer used. */ public Cubemap buildRadianceMap(final int mipMapLevels){ Pixmap[] maps = new Pixmap[mipMapLevels * 6]; int index = 0; for(int level=0 ; level<mipMapLevels ; level++){ int size = 1 << (mipMapLevels - level - 1); FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, size, size, false); fbo.begin(); for(int s=0 ; s<6 ; s++){ Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); CubemapSide side = CubemapSide.values()[s]; float blur = (float)level / (float)mipMapLevels; renderGradient(side, blur); renderLights(side, false); maps[index] = ScreenUtils.getFrameBufferPixmap(0, 0, size, size); index++; } fbo.end(); fbo.dispose(); } FacedMultiCubemapData data = new FacedMultiCubemapData(maps, mipMapLevels); Cubemap map = new Cubemap(data); map.setFilter(TextureFilter.MipMap, TextureFilter.Linear); return map; }
Example #21
Source File: PixmapBinaryLoaderHack.java From gdx-gltf with Apache License 2.0 | 5 votes |
public static Pixmap load(byte [] encodedData, int offset, int len){ if(Gdx.app.getType() == ApplicationType.WebGL){ throw new GdxRuntimeException("load pixmap from bytes not supported for WebGL"); }else{ // call new Pixmap(encodedData, offset, len); via reflection to // avoid compilation error with GWT. try { return (Pixmap)ClassReflection.getConstructor(Pixmap.class, byte[].class, int.class, int.class).newInstance(encodedData, offset, len); } catch (ReflectionException e) { throw new GdxRuntimeException(e); } } }
Example #22
Source File: ImageResolver.java From gdx-gltf with Apache License 2.0 | 5 votes |
public void load(Array<GLTFImage> glImages) { if(glImages != null){ for(int i=0 ; i<glImages.size ; i++){ GLTFImage glImage = glImages.get(i); Pixmap pixmap = dataFileResolver.load(glImage); pixmaps.add(pixmap); } } }
Example #23
Source File: ImageResolver.java From gdx-gltf with Apache License 2.0 | 5 votes |
@Override public void dispose() { for(Pixmap pixmap : pixmaps){ pixmap.dispose(); } pixmaps.clear(); }
Example #24
Source File: Textures.java From riiablo with Apache License 2.0 | 5 votes |
public Texture createTexture(Color color) { Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888); pixmap.setColor(color); pixmap.fill(); Texture texture = new Texture(pixmap); pixmap.dispose(); return texture; }
Example #25
Source File: RenderTransition.java From Entitas-Java with MIT License | 5 votes |
@Override public void loadResources() { int w = Gdx.graphics.getWidth(); int h = Gdx.graphics.getHeight(); nextFbo = new FrameBuffer(Pixmap.Format.RGBA8888, w, h, true); currFbo = new FrameBuffer(Pixmap.Format.RGBA8888, w, h, true); }
Example #26
Source File: Halo.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
public Halo() { super(); if (!TextureCache.contains( CACHE_KEY )) { Pixmap pixmap = new Pixmap(RADIUS * 2, RADIUS * 2, Pixmap.Format.RGBA8888); pixmap.setColor( 0xFFFFFF0A ); for (int i = 0; i < 50; i++) { pixmap.fillCircle(RADIUS, RADIUS, (int)(RADIUS * (i+1)/50f)); } TextureCache.add( CACHE_KEY, new SmartTexture( pixmap ) ); } texture( CACHE_KEY ); }
Example #27
Source File: Screenshot.java From Cubes with MIT License | 5 votes |
@Override public void frameEnd() { if (!state.compareAndSet(1, 2)) return; Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, screenshotWidth, screenshotHeight); frameBuffer.end(); Adapter.getInterface().resize(oldWidth, oldHeight); writeScreenshot(pixmap); }
Example #28
Source File: GifDecoder.java From Norii with Apache License 2.0 | 5 votes |
DixieMap(final int[] data, final int w, final int h, final Pixmap.Format f) { super(w, h, f); int x, y; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { final int pxl_ARGB8888 = data[x + y * w]; final int pxl_RGBA8888 = ((pxl_ARGB8888 >> 24) & 0x000000ff) | ((pxl_ARGB8888 << 8) & 0xffffff00); // convert ARGB8888 > RGBA8888 drawPixel(x, y, pxl_RGBA8888); } } }
Example #29
Source File: ImageHelper.java From gdx-fireapp with Apache License 2.0 | 5 votes |
/** * Creates texture region from byte[]. * <p> * GWT platform requires additional step (as far as i know) to deal with Pixmap. It is need to load Image element * and wait until it is loaded. * * @param bytes Image byte[] representation, not null * @param consumer Consumer where you should deal with region, not null */ public static void createTextureFromBytes(byte[] bytes, final Consumer<TextureRegion> consumer) { String base64 = "data:image/png;base64," + new String(Base64Coder.encode(bytes)); final Image image = new Image(); image.setVisible(false); image.addLoadHandler(new LoadHandler() { @Override public void onLoad(LoadEvent event) { ImageElement imageElement = image.getElement().cast(); Pixmap pixmap = new Pixmap(imageElement); GdxFIRLogger.log("Image loaded"); final int orgWidth = pixmap.getWidth(); final int orgHeight = pixmap.getHeight(); int width = MathUtils.nextPowerOfTwo(orgWidth); int height = MathUtils.nextPowerOfTwo(orgHeight); final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat()); potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); TextureRegion region = new TextureRegion(new Texture(potPixmap), 0, 0, orgWidth, orgHeight); potPixmap.dispose(); RootPanel.get().remove(image); consumer.accept(region); } }); image.setUrl(base64); RootPanel.get().add(image); }
Example #30
Source File: ImageHelper.java From gdx-fireapp with Apache License 2.0 | 5 votes |
/** * Transforms byte[] to Texture Region. * <p> * If you are going to call this method inside firebase callback remember to wrap it<p> * into {@code Gdx.app.postRunnable(Runnable)}. * The texture will be changed so that it has sides with length of power of 2. * * @param bytes Byte array with image description * @return Texture region representation of given byte array */ public TextureRegion createTextureFromBytes(byte[] bytes) { Pixmap pixmap = new Pixmap(bytes, 0, bytes.length); final int orgWidth = pixmap.getWidth(); final int orgHeight = pixmap.getHeight(); int width = MathUtils.nextPowerOfTwo(orgWidth); int height = MathUtils.nextPowerOfTwo(orgHeight); final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat()); potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); TextureRegion region = new TextureRegion(new Texture(potPixmap), 0, 0, orgWidth, orgHeight); potPixmap.dispose(); return region; }