Search in sources :

Example 26 with OrthographicCamera

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

the class InternationalFontsTest method create.

@Override
public void create() {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/unbom.ttf"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 18;
    parameter.characters = "한국어/조선�?";
    koreanFont = generator.generateFont(parameter);
    generator.dispose();
    parameter.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
    generator = new FreeTypeFontGenerator(Gdx.files.internal("data/russkij.ttf"));
    cyrillicFont = generator.generateFont(parameter);
    generator.dispose();
    parameter.characters = "วรณยุ�?ต์";
    generator = new FreeTypeFontGenerator(Gdx.files.internal("data/garuda.ttf"));
    thaiFont = generator.generateFont(parameter);
    generator.dispose();
    batch = new SpriteBatch();
    cam = new OrthographicCamera();
    cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.update();
}
Also used : FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 27 with OrthographicCamera

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

the class FreeTypeAtlasTest method create.

@Override
public void create() {
    camera = new OrthographicCamera();
    batch = new SpriteBatch();
    long start = System.currentTimeMillis();
    int glyphCount = createFonts();
    long time = System.currentTimeMillis() - start;
    text = glyphCount + " glyphs packed in " + packer.getPages().size + " page(s) in " + time + " ms";
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 28 with OrthographicCamera

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

the class Window method keepWithinStage.

void keepWithinStage() {
    if (!keepWithinStage)
        return;
    Stage stage = getStage();
    Camera camera = stage.getCamera();
    if (camera instanceof OrthographicCamera) {
        OrthographicCamera orthographicCamera = (OrthographicCamera) camera;
        float parentWidth = stage.getWidth();
        float parentHeight = stage.getHeight();
        if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom)
            setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right);
        if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom)
            setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left);
        if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom)
            setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top);
        if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom)
            setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom);
    } else if (getParent() == stage.getRoot()) {
        float parentWidth = stage.getWidth();
        float parentHeight = stage.getHeight();
        if (getX() < 0)
            setX(0);
        if (getRight() > parentWidth)
            setX(parentWidth - getWidth());
        if (getY() < 0)
            setY(0);
        if (getTop() > parentHeight)
            setY(parentHeight - getHeight());
    }
}
Also used : Stage(com.badlogic.gdx.scenes.scene2d.Stage) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Camera(com.badlogic.gdx.graphics.Camera) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera)

Example 29 with OrthographicCamera

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

the class BitmapFontDistanceFieldTest method create.

@Override
public void create() {
    camera = new OrthographicCamera();
    spriteBatch = new SpriteBatch();
    descriptionFont = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), true);
    descriptionFont.setColor(Color.RED);
    regularTexture = new Texture(Gdx.files.internal("data/verdana39.png"), true);
    regularFont = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), new TextureRegion(regularTexture), true);
    regularFont.setColor(COLOR);
    distanceFieldTexture = new Texture(Gdx.files.internal("data/verdana39distancefield.png"), true);
    distanceFieldFont = new BitmapFont(Gdx.files.internal("data/verdana39distancefield.fnt"), new TextureRegion(distanceFieldTexture), true);
    distanceFieldFont.setColor(COLOR);
    distanceFieldShader = new DistanceFieldShader();
    // Useful when debugging this test
    ShaderProgram.pedantic = false;
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 30 with OrthographicCamera

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

the class KTXTest method create.

@Override
public void create() {
    // Cubemap test
    String cubemapVS = //
    "" + //
    "attribute vec3 a_position;\n" + //
    "uniform mat4 u_projViewTrans;\n" + //
    "uniform mat4 u_worldTrans;\n" + //
    "\n" + //
    "varying vec3 v_cubeMapUV;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   vec4 g_position = vec4(a_position, 1.0);\n" + //
    "   g_position = u_worldTrans * g_position;\n" + //
    "   v_cubeMapUV = normalize(g_position.xyz);\n" + //
    "   gl_Position = u_projViewTrans * g_position;\n" + "}";
    String cubemapFS = //
    "" + //
    "#ifdef GL_ES\n" + //
    "precision mediump float;\n" + //
    "#endif\n" + //
    "uniform samplerCube u_environmentCubemap;\n" + //
    "varying vec3 v_cubeMapUV;\n" + //
    "void main() {\n" + //
    "	gl_FragColor = vec4(textureCube(u_environmentCubemap, v_cubeMapUV).rgb, 1.0);\n" + "}\n";
    modelBatch = new ModelBatch(new DefaultShaderProvider(new Config(cubemapVS, cubemapFS)));
    cubemap = new Cubemap(new KTXTextureData(Gdx.files.internal("data/cubemap.zktx"), true));
    cubemap.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.1f, 0.1f, 0.1f, 1.f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
    environment.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap));
    perspectiveCamera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    perspectiveCamera.position.set(10f, 10f, 10f);
    perspectiveCamera.lookAt(0, 0, 0);
    perspectiveCamera.near = 0.1f;
    perspectiveCamera.far = 300f;
    perspectiveCamera.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    instance = new ModelInstance(model);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(perspectiveCamera)));
    // 2D texture test
    String etc1aVS = //
    "" + //
    "uniform mat4 u_projTrans;\n" + //
    "\n" + //
    "attribute vec4 a_position;\n" + //
    "attribute vec2 a_texCoord0;\n" + //
    "attribute vec4 a_color;\n" + //
    "\n" + //
    "varying vec4 v_color;\n" + //
    "varying vec2 v_texCoord;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   gl_Position = u_projTrans * a_position;\n" + //
    "   v_texCoord = a_texCoord0;\n" + //
    "   v_color = a_color;\n" + //
    "}\n";
    String etc1aFS = //
    "" + //
    "#ifdef GL_ES\n" + //
    "precision mediump float;\n" + //
    "#endif\n" + //
    "uniform sampler2D u_texture;\n" + //
    "\n" + //
    "varying vec4 v_color;\n" + //
    "varying vec2 v_texCoord;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   vec3 col = texture2D(u_texture, v_texCoord.st).rgb;\n" + //
    "   float alpha = texture2D(u_texture, v_texCoord.st + vec2(0.0, 0.5)).r;\n" + //
    "   gl_FragColor = vec4(col, alpha) * v_color;\n" + //
    "}\n";
    etc1aShader = new ShaderProgram(etc1aVS, etc1aFS);
    orthoCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    image = new Texture("data/egg.zktx");
    batch = new SpriteBatch(100, etc1aShader);
}
Also used : DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) Config(com.badlogic.gdx.graphics.g3d.shaders.DefaultShader.Config) CubemapAttribute(com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) KTXTextureData(com.badlogic.gdx.graphics.glutils.KTXTextureData) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) Cubemap(com.badlogic.gdx.graphics.Cubemap) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

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