/** * Converts an x-coordinate given in logical screen coordinates to * backbuffer coordinates. */ public static int toBackBufferX(int logicalX) { return (int)(logicalX * Gdx.graphics.getBackBufferWidth() / (float)Gdx.graphics.getWidth()); }
@Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { shader.set(inputID, (float)Gdx.graphics.getWidth()); } };
/** * Converts an x-coordinate given in backbuffer coordinates to * logical screen coordinates. */ public static int toLogicalX(int backBufferX) { return (int)(backBufferX * Gdx.graphics.getWidth() / (float)Gdx.graphics.getBackBufferWidth()); }
/** Function to translate a point given in screen coordinates to world space. It's the same as GLU gluUnProject but does not * rely on OpenGL. The viewport is assumed to span the whole screen and is fetched from {@link Graphics#getWidth()} and * {@link Graphics#getHeight()}. The x- and y-coordinate of vec are assumed to be in screen coordinates (origin is the top left * corner, y pointing down, x pointing to the right) as reported by the touch methods in {@link Input}. A z-coordinate of 0 * will return a point on the near plane, a z-coordinate of 1 will return a point on the far plane. * @param screenCoords the point in screen coordinates * @return the mutated and unprojected screenCoords {@link Vector3} */ public Vector3 unproject (Vector3 screenCoords) { unproject(screenCoords, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); return screenCoords; }
@Override public void resize (int width, int height) { float ratio = ((float)Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight()); int h = 10; int w = (int)(h * ratio); camera = new OrthographicCamera(w, h); } }
/** Sets this camera to an orthographic projection using a viewport fitting the screen resolution, centered at * (Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2), with the y-axis pointing up or down. * @param yDown whether y should be pointing down */ public void setToOrtho (boolean yDown) { setToOrtho(yDown, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); }
private boolean isTouched (float startX, float endX) { // Check for touch inputs between startX and endX // startX/endX are given between 0 (left edge of the screen) and 1 (right edge of the screen) for (int i = 0; i < 2; i++) { float x = Gdx.input.getX(i) / (float)Gdx.graphics.getWidth(); if (Gdx.input.isTouched(i) && (x >= startX && x <= endX)) { return true; } } return false; }
@Override public boolean zoom (float initialDistance, float distance) { float newZoom = distance - initialDistance; float amount = newZoom - previousZoom; previousZoom = newZoom; float w = Gdx.graphics.getWidth(), h = Gdx.graphics.getHeight(); return controller.pinchZoom(amount / ((w > h) ? h : w)); }
/** Calculates a scissor rectangle using 0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight() as the viewport. * @see #calculateScissors(Camera, float, float, float, float, Matrix4, Rectangle, Rectangle) */ public static void calculateScissors (Camera camera, Matrix4 batchTransform, Rectangle area, Rectangle scissor) { calculateScissors(camera, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), batchTransform, area, scissor); }
/** Creates a picking {@link Ray} from the coordinates given in screen coordinates. It is assumed that the viewport spans the * whole screen. The screen coordinates origin is assumed to be in the top left corner, its y-axis pointing down, the x-axis * pointing to the right. The returned instance is not a new instance but an internal member only accessible via this function. * @return the picking Ray. */ public Ray getPickRay (float screenX, float screenY) { return getPickRay(screenX, screenY, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } }
@Override public void resize (int width, int height) { float ratio = ((float)Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight()); int h = 10; int w = (int)(h * ratio); camera = new OrthographicCamera(w, h); } }
/** Creates a stage with the specified viewport and batch. This can be used to avoid creating a new batch (which can be * somewhat slow) if multiple stages are used during an application's life time. * @param batch Will not be disposed if {@link #dispose()} is called, handle disposal yourself. */ public Stage (Viewport viewport, Batch batch) { if (viewport == null) throw new IllegalArgumentException("viewport cannot be null."); if (batch == null) throw new IllegalArgumentException("batch cannot be null."); this.viewport = viewport; this.batch = batch; root = new Group(); root.setStage(this); viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); }
@Override public boolean touchDragged (int screenX, int screenY, int pointer) { boolean result = super.touchDragged(screenX, screenY, pointer); if (result || this.button < 0) return result; final float deltaX = (screenX - startX) / Gdx.graphics.getWidth(); final float deltaY = (startY - screenY) / Gdx.graphics.getHeight(); startX = screenX; startY = screenY; return process(deltaX, deltaY, button); }
public ShapeRenderer (int maxVertices, ShaderProgram defaultShader) { if (defaultShader == null) { renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0); } else { renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0, defaultShader); } projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); matrixDirty = true; }
public ShapeRenderer (int maxVertices, ShaderProgram defaultShader) { if (defaultShader == null) { renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0); } else { renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0, defaultShader); } projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); matrixDirty = true; }
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(texture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.end(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); int color = pixmap.getPixel(0, pixmap.getHeight() - 1); Gdx.app.log("AlphaTest", Integer.toHexString(color)); pixmap.dispose(); }
@Override public void render() { Gdx.gl.glClearColor(0, 0, 0, 1f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(texture, 0, 0, Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f); batch.end(); }
public void create () { renderer = new ShapeRenderer(); cam = new PerspectiveCamera(47, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0, 0, 2); cam.near = 0.1f; controller = new PerspectiveCamController(cam); Gdx.input.setInputProcessor(controller); batch = new SpriteBatch(); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); }
@Override public void create () { float aspect = Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight(); camera = new OrthographicCamera(15 * aspect, 15); camera.update(); renderer = new ShapeRenderer(); renderer.setProjectionMatrix(camera.combined); bones = new Bone[] {new Bone("bone0", 0, 0, 0), new Bone("bone1", 0, 2, 2), new Bone("bone2", 0, 4, 2), new Bone("bone3", 0, 6, 2), new Bone("end", 0, 8, 2)}; globalCoords.set(bones[0].position); }