Search in sources :

Example 36 with OrthographicCamera

use of com.badlogic.gdx.graphics.OrthographicCamera in project libgdx by libgdx.

the class FloatTextureTest method create.

@Override
public void create() {
    fb = new FrameBuffer(Format.RGBA8888, 200, 100, false);
    ffb = new FloatFrameBuffer(200, 100, false);
    // @off
    String vertexShader = "attribute vec4 a_position; " + "varying vec2 v_position; " + "void main(){ " + "    v_position = a_position.xy; " + "    gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); " + "}";
    String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "uniform vec3 u_color;" + "uniform vec2 u_viewport; " + "void main(void){ " + "    vec2 uv = gl_FragCoord.xy/u_viewport; " + // <--- // regular (non-float) texture loses precision here, res == 0 for every fragment
    "    float res = mix(0.0, 0.0001, uv.x); " + "    gl_FragColor = vec4(u_color, res); " + "}";
    fbshader = new ShaderProgram(vertexShader, fragmentShader);
    vertexShader = "attribute vec4 a_position; " + "attribute vec4 a_color; " + "attribute vec2 a_texCoords; " + "uniform mat4 u_worldView; " + "varying vec4 v_color; " + "varying vec2 v_texCoords; " + "void main() " + "{ " + "    v_color = a_color; " + "    v_texCoords = a_texCoords; " + "    gl_Position =  u_worldView * a_position; " + "}";
    fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec2 v_texCoords; " + "uniform sampler2D u_fbtex, u_ffbtex; " + "vec4 getValue(vec4 col) {" + "    if (col.a > 0.00005)" + "        return vec4(col.rgb, 1.0);" + "    else" + "        return vec4(0.0, 0.0, 0.0, 1.0);" + "}" + "void main() " + "{ " + "    if (v_texCoords.y < 0.45)" + "        gl_FragColor = getValue(texture2D(u_fbtex, v_texCoords)); " + "    else if (v_texCoords.y > 0.55)" + "        gl_FragColor = getValue(texture2D(u_ffbtex, v_texCoords)); " + "}";
    // @on
    shader = new ShaderProgram(vertexShader, fragmentShader);
    createQuad();
    screenCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    createScreenQuad();
}
Also used : FloatFrameBuffer(com.badlogic.gdx.graphics.glutils.FloatFrameBuffer) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) FloatFrameBuffer(com.badlogic.gdx.graphics.glutils.FloatFrameBuffer) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer)

Example 37 with OrthographicCamera

use of com.badlogic.gdx.graphics.OrthographicCamera in project libgdx by libgdx.

the class Vector2dTest method resize.

@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);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera)

Example 38 with OrthographicCamera

use of com.badlogic.gdx.graphics.OrthographicCamera in project libgdx by libgdx.

the class TiledMapAssetManagerTest method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 10, 10);
    camera.zoom = 2;
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    assetManager = new AssetManager();
    assetManager.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver()));
    assetManager.load("data/maps/tiled/isometric_grass_and_water.tmx", TiledMap.class);
    assetManager.finishLoading();
    map = assetManager.get("data/maps/tiled/isometric_grass_and_water.tmx");
    renderer = new IsometricTiledMapRenderer(map, 1f / 64f);
    String mapCustomValue = map.getProperties().get(MAP_PROPERTY_NAME, String.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + MAP_PROPERTY_NAME + ", Value : " + mapCustomValue);
    if (!MAP_PROPERTY_VALUE.equals(mapCustomValue)) {
        throw new RuntimeException("Failed to get map properties");
    }
    boolean boolCustomValue = map.getProperties().get(BOOL_PROPERTY_NAME, Boolean.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + BOOL_PROPERTY_NAME + ", Value : " + boolCustomValue);
    if (boolCustomValue != BOOL_PROPERTY_VALUE) {
        throw new RuntimeException("Failed to get boolean map properties");
    }
    int intCustomValue = map.getProperties().get(INT_PROPERTY_NAME, Integer.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + INT_PROPERTY_NAME + ", Value : " + intCustomValue);
    if (intCustomValue != INT_PROPERTY_VALUE) {
        throw new RuntimeException("Failed to get int map properties");
    }
    float floatCustomValue = map.getProperties().get(FLOAT_PROPERTY_NAME, Float.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + FLOAT_PROPERTY_NAME + ", Value : " + floatCustomValue);
    if (floatCustomValue != FLOAT_PROPERTY_VALUE) {
        throw new RuntimeException("Failed to get float map properties");
    }
    TiledMapTileSet tileset = map.getTileSets().getTileSet(0);
    String tilesetCustomValue = tileset.getProperties().get(TILESET_PROPERTY_NAME, String.class);
    if (!TILESET_PROPERTY_VALUE.equals(tilesetCustomValue)) {
        throw new RuntimeException("Failed to get tileset properties");
    }
    TiledMapTile tile = tileset.getTile(1);
    String tileCustomValue = tile.getProperties().get(TILE_PROPERTY_NAME, String.class);
    if (!TILE_PROPERTY_VALUE.equals(tileCustomValue)) {
        throw new RuntimeException("Failed to get tile properties");
    }
    MapLayer layer = map.getLayers().get(0);
    String layerCustomValue = layer.getProperties().get(LAYER_PROPERTY_NAME, String.class);
    if (!LAYER_PROPERTY_VALUE.equals(layerCustomValue)) {
        throw new RuntimeException("Failed to get layer properties");
    }
}
Also used : TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) AssetManager(com.badlogic.gdx.assets.AssetManager) TiledMapTileSet(com.badlogic.gdx.maps.tiled.TiledMapTileSet) MapLayer(com.badlogic.gdx.maps.MapLayer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) IsometricTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 39 with OrthographicCamera

use of com.badlogic.gdx.graphics.OrthographicCamera in project libgdx by libgdx.

the class TiledMapAtlasAssetManagerTest method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 10, 10);
    camera.zoom = 2;
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    AtlasTiledMapLoaderParameters params = new AtlasTiledMapLoaderParameters();
    params.forceTextureFilters = true;
    params.textureMinFilter = TextureFilter.Linear;
    params.textureMagFilter = TextureFilter.Linear;
    assetManager = new AssetManager();
    assetManager.setErrorListener(new AssetErrorListener() {

        @Override
        public void error(AssetDescriptor asset, Throwable throwable) {
            errorMessage = throwable.getMessage();
        }
    });
    assetManager.setLoader(TiledMap.class, new AtlasTmxMapLoader(new InternalFileHandleResolver()));
    assetManager.load(fileName, TiledMap.class);
}
Also used : AtlasTiledMapLoaderParameters(com.badlogic.gdx.maps.tiled.AtlasTmxMapLoader.AtlasTiledMapLoaderParameters) AssetManager(com.badlogic.gdx.assets.AssetManager) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) AssetErrorListener(com.badlogic.gdx.assets.AssetErrorListener) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) AtlasTmxMapLoader(com.badlogic.gdx.maps.tiled.AtlasTmxMapLoader) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 40 with OrthographicCamera

use of com.badlogic.gdx.graphics.OrthographicCamera in project libgdx by libgdx.

the class TiledMapAtlasDirectLoaderTest method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 10, 10);
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    map = new AtlasTmxMapLoader().load("data/maps/tiled-atlas-processed/test.tmx");
    renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
}
Also used : OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) AtlasTmxMapLoader(com.badlogic.gdx.maps.tiled.AtlasTmxMapLoader) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Aggregations

OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)50 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)32 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)21 Texture (com.badlogic.gdx.graphics.Texture)20 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)15 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)10 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)10 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)7 TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)6 Box2DDebugRenderer (com.badlogic.gdx.physics.box2d.Box2DDebugRenderer)6 AssetManager (com.badlogic.gdx.assets.AssetManager)5 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)4 Pixmap (com.badlogic.gdx.graphics.Pixmap)4 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 PolygonSpriteBatch (com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch)3 Vector2 (com.badlogic.gdx.math.Vector2)3 World (com.badlogic.gdx.physics.box2d.World)3 Stage (com.badlogic.gdx.scenes.scene2d.Stage)3 InputAdapter (com.badlogic.gdx.InputAdapter)2 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)2