/** * Convers an y-coordinate given in backbuffer coordinates to * logical screen coordinates */ public static int toLogicalY(int backBufferY) { return (int)(backBufferY * Gdx.graphics.getHeight() / (float)Gdx.graphics.getBackBufferHeight()); }
/** * Convers an y-coordinate given in backbuffer coordinates to * logical screen coordinates */ public static int toBackBufferY(int logicalY) { return (int)(logicalY * Gdx.graphics.getBackBufferHeight() / (float)Gdx.graphics.getHeight()); } }
/** * Convers an y-coordinate given in backbuffer coordinates to * logical screen coordinates */ public static int toLogicalY(int backBufferY) { return (int)(backBufferY * Gdx.graphics.getHeight() / (float)Gdx.graphics.getBackBufferHeight()); }
/** * Convers an y-coordinate given in backbuffer coordinates to * logical screen coordinates */ public static int toBackBufferY(int logicalY) { return (int)(logicalY * Gdx.graphics.getBackBufferHeight() / (float)Gdx.graphics.getHeight()); } }
/** Returns the default framebuffer contents as a {@link TextureRegion} with a width and height equal to the current screen * size. The base {@link Texture} always has {@link MathUtils#nextPowerOfTwo} dimensions and RGBA8888 {@link Format}. It can be * accessed via {@link TextureRegion#getTexture}. The texture is not managed and has to be reloaded manually on a context loss. * The returned TextureRegion is flipped along the Y axis by default. */ public static TextureRegion getFrameBufferTexture () { final int w = Gdx.graphics.getBackBufferWidth(); final int h = Gdx.graphics.getBackBufferHeight(); return getFrameBufferTexture(0, 0, w, h); }
/** Returns the default framebuffer contents as a {@link TextureRegion} with a width and height equal to the current screen * size. The base {@link Texture} always has {@link MathUtils#nextPowerOfTwo} dimensions and RGBA8888 {@link Format}. It can be * accessed via {@link TextureRegion#getTexture}. The texture is not managed and has to be reloaded manually on a context loss. * The returned TextureRegion is flipped along the Y axis by default. */ public static TextureRegion getFrameBufferTexture () { final int w = Gdx.graphics.getBackBufferWidth(); final int h = Gdx.graphics.getBackBufferHeight(); return getFrameBufferTexture(0, 0, w, h); }
/** Returns the default framebuffer contents as a byte[] array with a length equal to screen width * height * 4. The byte[] will * always contain RGBA8888 data. Because of differences in screen and image origins the framebuffer contents should be flipped * along the Y axis if you intend save them to disk as a bitmap. Flipping is not a cheap operation, so use this functionality * wisely. * * @param flipY whether to flip pixels along Y axis */ public static byte[] getFrameBufferPixels (boolean flipY) { final int w = Gdx.graphics.getBackBufferWidth(); final int h = Gdx.graphics.getBackBufferHeight(); return getFrameBufferPixels(0, 0, w, h, flipY); }
@Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { // Value must be float type to work ! shader.set(inputID, (float)Gdx.graphics.getBackBufferWidth(), (float)Gdx.graphics.getBackBufferHeight()); } };
/** Returns the default framebuffer contents as a byte[] array with a length equal to screen width * height * 4. The byte[] will * always contain RGBA8888 data. Because of differences in screen and image origins the framebuffer contents should be flipped * along the Y axis if you intend save them to disk as a bitmap. Flipping is not a cheap operation, so use this functionality * wisely. * * @param flipY whether to flip pixels along Y axis */ public static byte[] getFrameBufferPixels (boolean flipY) { final int w = Gdx.graphics.getBackBufferWidth(); final int h = Gdx.graphics.getBackBufferHeight(); return getFrameBufferPixels(0, 0, w, h, flipY); }
protected void beginRender (boolean lighting) { Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); camera.update(); }
@Override public void render () { counter = (counter + Gdx.graphics.getDeltaTime()) % 2.f; testAttribute1.value = Math.abs(1f - counter); testAttribute2.value = 1f - testAttribute1.value; camController.update(); Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); modelBatch.begin(cam); modelBatch.render(instances); modelBatch.end(); }
@Override public void render () { Gdx.gl20.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); shader.begin(); mesh.render(shader, GL20.GL_TRIANGLES); shader.end(); } }
@Override public void render () { counter = (counter + Gdx.graphics.getDeltaTime()) % 1.f; blendingAttribute.opacity = 0.25f + Math.abs(0.5f - counter); Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); modelInstance.transform.rotate(Vector3.Y, 30 * Gdx.graphics.getDeltaTime()); modelBatch.begin(camera); modelBatch.render(background); modelBatch.render(modelInstance); modelBatch.end(); }
@Override public void render () { inputController.update(); Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); modelBatch.begin(cam); modelBatch.render(instance, environment); modelBatch.end(); }
@Override public void render () { counter = (counter + Gdx.graphics.getDeltaTime()) % 1.f; blendingAttribute.opacity = 0.25f + Math.abs(0.5f - counter); Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); modelInstance.transform.rotate(Vector3.Y, 30 * Gdx.graphics.getDeltaTime()); modelBatch.begin(camera); modelBatch.render(background); modelBatch.render(modelInstance, environment); modelBatch.end(); }
/** Calls {@link GL20#glViewport(int, int, int, int)}, expecting the coordinates and sizes given in logical coordinates and * automatically converts them to backbuffer coordinates, which may be bigger on HDPI screens. */ public static void glViewport (int x, int y, int width, int height) { if (mode == HdpiMode.Logical && (Gdx.graphics.getWidth() != Gdx.graphics.getBackBufferWidth() || Gdx.graphics.getHeight() != Gdx.graphics.getBackBufferHeight())) { Gdx.gl.glViewport(toBackBufferX(x), toBackBufferY(y), toBackBufferX(width), toBackBufferY(height)); } else { Gdx.gl.glViewport(x, y, width, height); } }
/** Calls {@link GL20#glScissor(int, int, int, int)}, expecting the coordinates and sizes given in logical coordinates and * automatically converts them to backbuffer coordinates, which may be bigger on HDPI screens. */ public static void glScissor (int x, int y, int width, int height) { if (mode == HdpiMode.Logical && (Gdx.graphics.getWidth() != Gdx.graphics.getBackBufferWidth() || Gdx.graphics.getHeight() != Gdx.graphics.getBackBufferHeight())) { Gdx.gl.glScissor(toBackBufferX(x), toBackBufferY(y), toBackBufferX(width), toBackBufferY(height)); } else { Gdx.gl.glScissor(x, y, width, height); } }
/** Calls {@link GL20#glViewport(int, int, int, int)}, expecting the coordinates and sizes given in logical coordinates and * automatically converts them to backbuffer coordinates, which may be bigger on HDPI screens. */ public static void glViewport (int x, int y, int width, int height) { if (mode == HdpiMode.Logical && (Gdx.graphics.getWidth() != Gdx.graphics.getBackBufferWidth() || Gdx.graphics.getHeight() != Gdx.graphics.getBackBufferHeight())) { Gdx.gl.glViewport(toBackBufferX(x), toBackBufferY(y), toBackBufferX(width), toBackBufferY(height)); } else { Gdx.gl.glViewport(x, y, width, height); } }
@Override public void render () { animate(); inputController.update(); Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); Gdx.gl.glClearColor(0.13f, 0.13f, 0.13f, 1); modelBatch.begin(cam); modelBatch.render(instance, environment); modelBatch.end(); }
@Override public void render () { if (loading && assets.update()) doneLoading(); camController.update(); Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); modelBatch.begin(cam); for (ModelInstance instance : instances) modelBatch.render(instance, lights); if (space != null) modelBatch.render(space); modelBatch.end(); }