1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.tests; 18 19 import com.badlogic.gdx.Gdx; 20 import com.badlogic.gdx.Graphics.DisplayMode; 21 import com.badlogic.gdx.graphics.GL20; 22 import com.badlogic.gdx.graphics.Texture; 23 import com.badlogic.gdx.graphics.g2d.BitmapFont; 24 import com.badlogic.gdx.graphics.g2d.SpriteBatch; 25 import com.badlogic.gdx.tests.utils.GdxTest; 26 27 public class FullscreenTest extends GdxTest { 28 SpriteBatch batch; 29 Texture tex; 30 boolean fullscreen = false; 31 BitmapFont font; 32 33 @Override create()34 public void create () { 35 batch = new SpriteBatch(); 36 font = new BitmapFont(); 37 tex = new Texture(Gdx.files.internal("data/badlogic.jpg")); 38 DisplayMode[] modes = Gdx.graphics.getDisplayModes(); 39 for (DisplayMode mode : modes) { 40 System.out.println(mode); 41 } 42 Gdx.app.log("FullscreenTest", Gdx.graphics.getBufferFormat().toString()); 43 } 44 45 @Override resume()46 public void resume () { 47 48 } 49 50 @Override render()51 public void render () { 52 Gdx.gl.glClearColor(0, 0, 0, 1); 53 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 54 55 batch.begin(); 56 batch.draw(tex, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY()); 57 font.draw(batch, "" + Gdx.graphics.getWidth() + ", " + Gdx.graphics.getHeight(), 0, 20); 58 batch.end(); 59 60 if (Gdx.input.justTouched()) { 61 if (fullscreen) { 62 Gdx.graphics.setWindowedMode(480, 320); 63 batch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 64 Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); 65 fullscreen = false; 66 } else { 67 DisplayMode m = null; 68 for(DisplayMode mode: Gdx.graphics.getDisplayModes()) { 69 if(m == null) { 70 m = mode; 71 } else { 72 if(m.width < mode.width) { 73 m = mode; 74 } 75 } 76 } 77 78 Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); 79 batch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 80 Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); 81 fullscreen = true; 82 } 83 } 84 } 85 86 @Override resize(int width, int height)87 public void resize (int width, int height) { 88 Gdx.app.log("FullscreenTest", "resized: " + width + ", " + height); 89 batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height); 90 } 91 92 @Override pause()93 public void pause () { 94 Gdx.app.log("FullscreenTest", "paused"); 95 } 96 97 @Override dispose()98 public void dispose () { 99 Gdx.app.log("FullscreenTest", "disposed"); 100 } 101 } 102