Refine search
/** Disposes the texture used by this BitmapFont's region IF this BitmapFont created the texture. */ public void dispose () { if (ownsTexture) { for (int i = 0; i < regions.size; i++) regions.get(i).getTexture().dispose(); } }
@Override public Texture loadSync (AssetManager manager, String fileName, FileHandle file, TextureParameter parameter) { if (info == null) return null; Texture texture = info.texture; if (texture != null) { texture.load(info.data); } else { texture = new Texture(info.data); } if (parameter != null) { texture.setFilter(parameter.minFilter, parameter.magFilter); texture.setWrap(parameter.wrapU, parameter.wrapV); } return texture; }
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(); }
@Override public void create () { texture = new Texture(Gdx.files.internal("data/walkanim.png")); TextureRegion[] leftWalkFrames = TextureRegion.split(texture, 64, 64)[0]; Array<TextureRegion> rightWalkFrames = new Array(TextureRegion.class); for (int i = 0; i < leftWalkFrames.length; i++) { TextureRegion frame = new TextureRegion(leftWalkFrames[i]); frame.flip(true, false); rightWalkFrames.add(frame); } leftWalk = new Animation<TextureRegion>(0.25f, leftWalkFrames); rightWalk = new Animation<TextureRegion>(0.25f, rightWalkFrames); TextureRegion[] rightRegions = rightWalk.getKeyFrames(); // testing backing array type TextureRegion firstRightRegion = rightRegions[0]; Gdx.app.log("AnimationTest", "First right walk region is " + firstRightRegion.getRegionWidth() + "x" + firstRightRegion.getRegionHeight()); cavemen = new Caveman[100]; for (int i = 0; i < 100; i++) { cavemen[i] = new Caveman((float)Math.random() * Gdx.graphics.getWidth(), (float)Math.random() * Gdx.graphics.getHeight(), Math.random() > 0.5 ? true : false); } batch = new SpriteBatch(); fpsLog = new FPSLogger(); }
Texture texture = null; if (page.texture == null) { texture = new Texture(page.textureFile, page.format, page.useMipMaps); texture.setFilter(page.minFilter, page.magFilter); texture.setWrap(page.uWrap, page.vWrap); } else { texture = page.texture; texture.setFilter(page.minFilter, page.magFilter); texture.setWrap(page.uWrap, page.vWrap); atlasRegion.pads = region.pads; if (region.flip) atlasRegion.flip(false, true); regions.add(atlasRegion);
static TextureRegion newPatchPix (int patchSize, int pixmapSize) { final int pixmapDim = MathUtils.nextPowerOfTwo(pixmapSize); Pixmap p = new Pixmap(pixmapDim, pixmapDim, Pixmap.Format.RGBA8888); p.setColor(1, 1, 1, 0); p.fill(); for (int x = 0; x < pixmapSize; x += patchSize) { for (int y = 0; y < pixmapSize; y += patchSize) { p.setColor(x / (float)pixmapSize, y / (float)pixmapSize, 1.0f, 1.0f); p.fillRectangle(x, y, patchSize, patchSize); } } return new TextureRegion(new Texture(p), pixmapSize, pixmapSize); }
void generateRegions(GenerationMode mode){ //generate regions texturePanel.clear(); Texture texture = texturePanel.getTexture(); int rows = (int)rowSlider.getValue(), columns = (int)columnSlider.getValue(), yOffset = texture.getHeight()/rows, xOffset = texture.getWidth()/columns; if(mode == GenerationMode.ByRows){ for(int j=0; j < rows; ++j){ int rowOffset = j*yOffset; for(int i=0; i < columns; ++i){ texturePanel.unselectedRegions.add(new TextureRegion(texture, i*xOffset, rowOffset, xOffset, yOffset) ); } } } else if(mode == GenerationMode.ByColumns){ for(int i=0; i < columns; ++i){ int columnOffset = i*xOffset; for(int j=0; j <rows; ++j){ texturePanel.unselectedRegions.add(new TextureRegion(texture, columnOffset, j*yOffset, xOffset, yOffset) ); } } } }
@Override public void create () { ObjLoader objLoader = new ObjLoader(); sphere = objLoader.loadModel(Gdx.files.internal("data/sphere.obj")); sphere.materials.get(0).set(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)); cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.far = 200; Random rand = new Random(); for (int i = 0; i < instances.length; i++) { instances[i] = new ModelInstance(sphere, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * -100 - 3); } batch = new SpriteBatch(); font = new BitmapFont(); logo = new TextureRegion(new Texture(Gdx.files.internal("data/badlogicsmall.jpg"))); modelBatch = new ModelBatch(); }
@Override public void create () { texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true); texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); ObjLoader objLoader = new ObjLoader(); mesh = objLoader.loadModel(Gdx.files.internal("data/cube.obj")); mesh.materials.get(0).set(new TextureAttribute(TextureAttribute.Diffuse, texture)); modelInstance = new ModelInstance(mesh); modelBatch = new ModelBatch(); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(3, 3, 3); cam.direction.set(-1, -1, -1); batch = new SpriteBatch(); font = new BitmapFont(); }
/** @param pageWidth The width of the backing texture. * @param pageHeight The height of the backing texture. */ GlyphPage (UnicodeFont unicodeFont, int pageWidth, int pageHeight) { this.unicodeFont = unicodeFont; this.pageWidth = pageWidth; this.pageHeight = pageHeight; texture = new Texture(pageWidth, pageHeight, Format.RGBA8888); rows.add(new Row()); }
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 () { Pixmap pixmap = new Pixmap(16, 16, Pixmap.Format.RGBA8888); pixmap.setColor(Color.BLUE); pixmap.fill(); pixmap.setColor(Color.RED); pixmap.drawLine(0, 0, 15, 15); pixmap.drawLine(0, 15, 15, 0); tex = new Texture(pixmap); batch = new SpriteBatch(); cam = new OrthographicCamera(); cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); }
/** Draws all the images defined for the specified cache ID. */ public void draw (int cacheID) { if (!drawing) throw new IllegalStateException("SpriteCache.begin must be called before draw."); Cache cache = caches.get(cacheID); int verticesPerImage = mesh.getNumIndices() > 0 ? 4 : 6; int offset = cache.offset / (verticesPerImage * VERTEX_SIZE) * 6; Texture[] textures = cache.textures; int[] counts = cache.counts; int textureCount = cache.textureCount; for (int i = 0; i < textureCount; i++) { int count = counts[i]; textures[i].bind(); if (customShader != null) mesh.render(customShader, GL20.GL_TRIANGLES, offset, count); else mesh.render(shader, GL20.GL_TRIANGLES, offset, count); offset += count; } renderCalls += textureCount; totalRenderCalls += textureCount; }
@Override public void create () { Pixmap pixmap = new Pixmap(512, 512, Format.RGBA8888); pixmap.setColor(Color.WHITE); Bresenham2 bresenham = new Bresenham2(); for (GridPoint2 point : bresenham.line(0, 0, 512, 512)) pixmap.drawPixel(point.x, point.y); for (GridPoint2 point : bresenham.line(512, 0, 0, 512)) pixmap.drawPixel(point.x, point.y); for (GridPoint2 point : bresenham.line(0, 0, 512, 256)) pixmap.drawPixel(point.x, point.y); for (GridPoint2 point : bresenham.line(512, 0, 0, 256)) pixmap.drawPixel(point.x, point.y); result = new Texture(pixmap); batch = new SpriteBatch(); }
/** 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()); }
@Override public void create () { texture = new Texture(Gdx.files.internal("data/tree.png")); PolygonRegionLoader loader = new PolygonRegionLoader(); region = loader.load(new TextureRegion(texture), Gdx.files.internal("data/tree.psh")); renderer = new ShapeRenderer(); camera = new OrthographicCamera(480, 320); camera.position.x = 240; camera.position.y = 160; camera.update(); batch = new PolygonSpriteBatch(); for (int i = 0; i < 50; i++) { PolygonSprite sprite = new PolygonSprite(region); sprite.setPosition(MathUtils.random(-30, 440), MathUtils.random(-30, 290)); sprite.setColor(MathUtils.random(), MathUtils.random(), MathUtils.random(), 1.0f); sprite.setScale(MathUtils.random(0.5f, 1.5f), MathUtils.random(0.5f, 1.5f)); sprites.add(sprite); } }