Java Code Examples for com.badlogic.gdx.graphics.glutils.FrameBuffer#dispose()

The following examples show how to use com.badlogic.gdx.graphics.glutils.FrameBuffer#dispose() . 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: GLTFBinaryExporter.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
public void export(GLTFImage image, Texture texture, String baseName) {
	String fileName = baseName + ".png";
	image.uri = fileName;
	FileHandle file = folder.child(fileName);
	FrameBuffer fbo = new FrameBuffer(texture.getTextureData().getFormat(), texture.getWidth(), texture.getHeight(), false);
	fbo.begin();
	Gdx.gl.glClearColor(0, 0, 0, 0);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
	SpriteBatch batch = new SpriteBatch();
	batch.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1);
	batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
	batch.begin();
	batch.draw(texture, 0, 0, 1, 1, 0, 0, 1, 1);
	batch.end();
	Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight());
	fbo.end();
	batch.dispose();
	fbo.dispose();
	savePNG(file, pixmap);
	pixmap.dispose();
}
 
Example 2
Source File: IBLBuilder.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
/**
 * 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 3
Source File: World.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public void takeScreenshot(String filename, int w) {

		// get viewport
		IntBuffer results = BufferUtils.newIntBuffer(16);
		Gdx.gl20.glGetIntegerv(GL20.GL_VIEWPORT, results);

		int h = (int) (w * getSceneCamera().viewportHeight / getSceneCamera().viewportWidth);

		FrameBuffer fbo = new FrameBuffer(Format.RGB565, w, h, false);

		fbo.begin();
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		draw();
		Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, w, h);

		// restore viewport
		fbo.end(results.get(0), results.get(1), results.get(2), results.get(3));

		// Flip the pixmap upside down
		ByteBuffer pixels = pixmap.getPixels();
		int numBytes = w * h * 4;
		byte[] lines = new byte[numBytes];
		int numBytesPerLine = w * 4;
		for (int i = 0; i < h; i++) {
			pixels.position((h - i - 1) * numBytesPerLine);
			pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
		}
		pixels.clear();
		pixels.put(lines);

		PixmapIO.writePNG(EngineAssetManager.getInstance().getUserFile(filename), pixmap);

		fbo.dispose();
	}
 
Example 4
Source File: SceneList.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
private TextureRegion createBgIcon(String atlas, String region) {
	TextureAtlas a = new TextureAtlas(
			Gdx.files.absolute(Ctx.project.getAssetPath() + Project.ATLASES_PATH + "/1/" + atlas + ".atlas"));
	AtlasRegion r = a.findRegion(region);

	if (r == null) {
		a.dispose();
		return null;
	}

	GLFrameBuffer.FrameBufferBuilder frameBufferBuilder = new GLFrameBuffer.FrameBufferBuilder(200,
			(int) (r.getRegionHeight() * 200f / r.getRegionWidth()));

	frameBufferBuilder.addColorTextureAttachment(GL30.GL_RGBA8, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE);
	FrameBuffer fbo = frameBufferBuilder.build();

	SpriteBatch fboBatch = new SpriteBatch();
	fboBatch.setColor(Color.WHITE);
	OrthographicCamera camera = new OrthographicCamera();
	camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight());
	fboBatch.setProjectionMatrix(camera.combined);

	Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
	fbo.begin();
	fboBatch.begin();
	fboBatch.draw(r, 0, 0, fbo.getWidth(), fbo.getHeight());
	fboBatch.end();

	TextureRegion tex = ScreenUtils.getFrameBufferTexture(0, 0, fbo.getWidth(), fbo.getHeight());
	// tex.flip(false, true);

	fbo.end();
	Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);

	fbo.dispose();
	a.dispose();
	fboBatch.dispose();

	return tex;
}