List of usage examples for com.badlogic.gdx.graphics.glutils FrameBuffer FrameBuffer
public FrameBuffer(Pixmap.Format format, int width, int height, boolean hasDepth)
From source file:CB_UI_Base.graphics.Images.VectorDrawable.java
License:Open Source License
private void drawFbo(Batch batch, float x, float y, final float width, final float height, final Matrix4 oriMatrix, Matrix4 thisDrawMatrix) { final int fboScalerWidth = (int) (this.DEFAULT_WIDTH * FBO_SCALER); final int fboScalerHeight = (int) (this.DEFAULT_HEIGHT * FBO_SCALER); if (!RunOnGlSetted && m_fboEnabled && m_fboRegion == null) { RunOnGlSetted = true;/*www . ja v a 2 s . co m*/ GL.that.RunOnGL(new IRenderFBO() { @Override public void run() { synchronized (isDisposed) { if (isDisposed.get()) { return; } try { Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST); long start = System.currentTimeMillis(); m_fbo = new FrameBuffer(Format.RGBA8888, fboScalerWidth, fboScalerHeight, false); m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture()); m_fboRegion.flip(flipX, flipY); m_fbo.begin(); // clear screen Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); GL.batch.setColor(new Color(Color.WHITE)); GL.batch.begin(); Matrix4 matrix = new Matrix4().setToOrtho2D(0, 0, width, height); matrix.scale(FBO_SCALER, FBO_SCALER, 1); GL.batch.setProjectionMatrix(matrix); // draw Background GL.batch.disableBlending(); background.draw(GL.batch, 0, 0, fboScalerWidth, fboScalerHeight); GL.batch.enableBlending(); int count = 0; for (int i = 0, n = drawableList.size(); i < n; i++) { MatrixDrawable drw = drawableList.get(i); if (count++ > 2500) { GL.batch.flush(); count = 0; } matrix = new Matrix4().setToOrtho2D(0, 0, width, height); if (drw.matrix != null) { matrix.mul(drw.matrix.getMatrix4()); } GL.batch.setProjectionMatrix(matrix); drw.drawable.draw(GL.batch, 0, 0, width, height, 0); } if (m_fbo != null) { GL.batch.end(); m_fbo.end(); m_fboEnabled = false; } FBOisDrawed = true; FBO_DrawingTime = System.currentTimeMillis() - start; Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST); GL.batch.setProjectionMatrix(oriMatrix); m_fboEnabled = false; } catch (Exception e) { e.printStackTrace(); } } } }); } if (m_fboRegion != null) { // TODO clear and release the drawables that drawed on m_fboRegion // if first drawing of m_fboRegion batch.draw(m_fboRegion, x, y, width, height); } else { int count = 0; for (int i = 0, n = drawableList.size(); i < n; i++) { MatrixDrawable drw = drawableList.get(i); if (!drw.reaelDraw) continue; if (count++ > 2500) { GL.batch.flush(); count = 0; } Matrix4 matrix = thisDrawMatrix.cpy(); if (drw.matrix != null) matrix.mul(drw.matrix.getMatrix4()); GL.batch.setProjectionMatrix(matrix); drw.drawable.draw(GL.batch, 0, 0, width, height, 0); } } }
From source file:com.agateau.pixelwheels.racescreen.Helicopter.java
License:Open Source License
public static Helicopter create(Assets assets, AudioManager audioManager, Track track, Vector2 vehiclePosition, float vehicleAngle) { Helicopter object = sPool.obtain();/* w w w . j a v a 2 s. com*/ object.setFinished(false); float height = Constants.UNIT_FOR_PIXEL * assets.helicopterBody.getRegionHeight(); float mapHeight = track.getMapHeight() * track.getTileHeight(); if (object.mSoundPlayer == null) { object.mSoundPlayer = audioManager.createSoundPlayer(assets.soundAtlas.get("helicopter")); } object.mBodyRegion = assets.helicopterBody; object.mPropellerRegion = assets.helicopterPropeller; object.mPropellerTopRegion = assets.helicopterPropellerTop; object.mPosition.set(vehiclePosition.x, -height); object.mAngle = 0; object.mStartPosition.set(object.mPosition); object.mStartAngle = 90; object.mEndPosition.set(vehiclePosition); object.mEndAngle = vehicleAngle; object.mLeavePosition.set(vehiclePosition.x, mapHeight); object.mTime = 0; object.mState = State.ARRIVING; if (object.mFrameBuffer == null) { int bufferWidth = object.mPropellerRegion.getRegionWidth(); int bufferHeight = object.mPropellerRegion.getRegionHeight() / 2 + (int) BODY_CENTER.y; object.mFrameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, bufferWidth, bufferHeight, false /* hasDepth */); object.mFrameBufferBatch = new SpriteBatch(); object.mFrameBufferBatch .setProjectionMatrix(new Matrix4().setToOrtho2D(0, 0, bufferWidth, bufferHeight)); } return object; }
From source file:com.agateau.pixelwheels.tools.MapScreenshotGenerator.java
License:Apache License
private static Pixmap generateScreenshot(FileHandle tmxFile) { TiledMap map = new TmxMapLoader().load(tmxFile.path()); TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0); int mapWidth = (int) (layer.getWidth() * layer.getTileWidth()); int mapHeight = (int) (layer.getHeight() * layer.getTileHeight()); FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGB888, mapWidth, mapHeight, false /* hasDepth */); OrthogonalTiledMapRenderer renderer = new OrthogonalTiledMapRenderer(map); OrthographicCamera camera = new OrthographicCamera(); camera.setToOrtho(true /* yDown */, mapWidth, mapHeight); renderer.setView(camera);/*from w w w. j a va2 s . co m*/ fbo.begin(); renderer.render(); return ScreenUtils.getFrameBufferPixmap(0, 0, mapWidth, mapHeight); }
From source file:com.badlogic.gdx.tests.g3d.shadows.system.classical.ClassicalShadowSystem.java
License:Apache License
protected void init2() { frameBuffers[SECOND_PASS] = new FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true); passShaderProviders[SECOND_PASS] = new Pass2ShaderProvider(new Pass2Shader.Config(this)); }
From source file:com.badlogic.gdx.tests.g3d.shadows.system.FirstPassBaseShadowSystem.java
License:Apache License
protected void init1() { frameBuffers[FIRST_PASS] = new FrameBuffer(Pixmap.Format.RGBA8888, allocator.getWidth(), allocator.getHeight(), true); }
From source file:com.badlogic.gdx.tests.PremultiplyAlpha.java
private void gpuPremultiplyAlpha(String in, String out) { Texture texture = new Texture(Gdx.files.absolute(in)); texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest); FrameBuffer buffer = new FrameBuffer(Format.RGBA8888, texture.getWidth(), texture.getHeight(), false); buffer.getColorBufferTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest); ShaderProgram shader = new ShaderProgram(VERTEX_SHADER, FRAG_SHADER); Gdx.app.log("Log", shader.getLog()); SpriteBatch batch = new SpriteBatch(10); batch.getProjectionMatrix().setToOrtho2D(0, 0, texture.getWidth(), texture.getHeight()); batch.disableBlending();/*w w w .jav a 2 s . c o m*/ batch.setShader(shader); //Premultiply buffer.begin(); Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(texture, 0, 0); batch.end(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight()); buffer.end(); //Save PixmapIO.writePNG(Gdx.files.absolute(out), pixmap); buffer.dispose(); texture.dispose(); pixmap.dispose(); Gdx.app.exit(); }
From source file:com.bitfire.postprocessing.effects.CrtMonitor.java
License:Apache License
public CrtMonitor(boolean barrelDistortion, boolean performBlur) { // the effect is designed to work on the whole screen area, no small/mid size tricks! int w = Gdx.graphics.getWidth(); int h = Gdx.graphics.getHeight(); doblur = performBlur;/* w ww. j ava 2 s. c o m*/ if (doblur) { pingPongBuffer = PostProcessor.newPingPongBuffer(w, h, PostProcessor.getFramebufferFormat(), false); blur = new Blur(w, h); blur.setPasses(1); blur.setAmount(1f); // blur.setType( BlurType.Gaussian3x3b ); // high defocus blur.setType(BlurType.Gaussian3x3); // modern machines defocus } else { buffer = new FrameBuffer(PostProcessor.getFramebufferFormat(), w, h, false); } combine = new Combine(); combine.setSource1Intensity(barrelDistortion ? 0f : 0.15f); combine.setSource2Intensity(barrelDistortion ? 1.2f : 1.1f); combine.setSource1Saturation(1f); combine.setSource2Saturation(0.8f); crt = new CrtScreen(barrelDistortion); }
From source file:com.bitfire.postprocessing.utils.PingPongBuffer.java
License:Apache License
/** Creates a new ping-pong buffer and owns the resources. */ public PingPongBuffer(int width, int height, Format frameBufferFormat, boolean hasDepth) { ownResources = true;// w w w. j a va 2 s. c o m owned1 = new FrameBuffer(frameBufferFormat, width, height, hasDepth); owned2 = new FrameBuffer(frameBufferFormat, width, height, hasDepth); set(owned1, owned2); }
From source file:com.bladecoder.engine.model.Sprite3DRenderer.java
License:Apache License
@Override public void retrieveAssets() { // create STATIC BATCHS if not created yet if (modelBatch == null) createBatchs();/*from w w w. ja va2 s. c om*/ createEnvirontment(); for (String key : sourceCache.keySet()) { if (sourceCache.get(key).refCounter > 0) retrieveSource(key); } if (currentAnimation != null) { // RESTORE FA ModelCacheEntry entry = sourceCache.get(currentAnimation.source); currentSource = entry; float speed = currentAnimation.duration; if (currentAnimationType == Tween.Type.REVERSE || currentAnimationType == Tween.Type.REVERSE_REPEAT) speed *= -1; currentSource.controller.setAnimation(currentAnimation.id, currentCount, speed, animationListener); update(lastAnimationTime); } else if (initAnimation != null) { startAnimation(initAnimation, Tween.Type.SPRITE_DEFINED, 1, null); if (currentAnimation != null) lookat(modelRotation); } if (currentSource != null && renderShadow) genShadowMap(); if (USE_FBO) { fb = new FrameBuffer(FRAMEBUFFER_FORMAT, width, height, true); tex = new TextureRegion(fb.getColorBufferTexture()); tex.flip(false, true); renderTex(); } computeBbox(); }
From source file:com.bladecoder.engine.model.World.java
License:Apache License
public void takeScreenshot(String filename, int w) { int h = (int) (w * getSceneCamera().viewportHeight / getSceneCamera().viewportWidth); FrameBuffer fbo = new FrameBuffer(Format.RGB565, w, h, false); fbo.begin();//from w ww.j a v a 2 s . c om draw(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, w, h); fbo.end(); // 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); }