use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class EdgeDetectionTest method create.
public void create() {
ShaderProgram.pedantic = false;
/*
* shader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal(
* "data/shaders/depthtocolor.frag").readString()); if (!shader.isCompiled()) { Gdx.app.log("EdgeDetectionTest",
* "couldn't compile scene shader: " + shader.getLog()); }
*/
batchShader = new ShaderProgram(Gdx.files.internal("data/shaders/batch.vert").readString(), Gdx.files.internal("data/shaders/convolution.frag").readString());
if (!batchShader.isCompiled()) {
Gdx.app.log("EdgeDetectionTest", "couldn't compile post-processing shader: " + batchShader.getLog());
}
ObjLoader objLoader = new ObjLoader();
scene = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
sceneInstance = new ModelInstance(scene);
modelBatch = new ModelBatch();
fbo = new FrameBuffer(Format.RGB565, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0, 0, 10);
cam.lookAt(0, 0, 0);
cam.far = 30;
batch = new SpriteBatch();
batch.setShader(batchShader);
fboRegion = new TextureRegion(fbo.getColorBufferTexture());
fboRegion.flip(false, true);
logger = new FPSLogger();
calculateOffsets();
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class Box2DTest method create.
@Override
public void create() {
// setup the camera. In Box2D we operate on a
// meter scale, pixels won't do it. So we use
// an orthographic camera with a viewport of
// 48 meters in width and 32 meters in height.
// We also position the camera so that it
// looks at (0,16) (that's where the middle of the
// screen will be located).
camera = new OrthographicCamera(48, 32);
camera.position.set(0, 16, 0);
// next we setup the immediate mode renderer
renderer = new ShapeRenderer();
// next we create the box2d debug renderer
debugRenderer = new Box2DDebugRenderer();
// next we create a SpriteBatch and a font
batch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
font.setColor(Color.RED);
textureRegion = new TextureRegion(new Texture(Gdx.files.internal("data/badlogicsmall.jpg")));
// next we create out physics world.
createPhysicsWorld();
// register ourselfs as an InputProcessor
Gdx.input.setInputProcessor(this);
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class AnimationTest method create.
@Override
public void create() {
texture = new Texture(Gdx.files.internal("data/walkanim.png"));
TextureRegion[] leftWalkFrames = TextureRegion.split(texture, 64, 64)[0];
TextureRegion[] rightWalkFrames = new TextureRegion[leftWalkFrames.length];
for (int i = 0; i < rightWalkFrames.length; i++) {
TextureRegion frame = new TextureRegion(leftWalkFrames[i]);
frame.flip(true, false);
rightWalkFrames[i] = frame;
}
leftWalk = new Animation<TextureRegion>(0.25f, leftWalkFrames);
rightWalk = new Animation<TextureRegion>(0.25f, rightWalkFrames);
cavemen = new Caveman[100];
for (int i = 0; i < 100; i++) {
cavemen[i] = new Caveman((float) Math.random() * Gdx.graphics.getWidth(), (float) Math.random() * Gdx.graphics.getHeight(), Math.random() > 0.5 ? true : false);
}
batch = new SpriteBatch();
fpsLog = new FPSLogger();
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class TiledMapBench method create.
@Override
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false, (w / h) * 320, 320);
camera.update();
cameraController = new OrthoCamController(camera);
Gdx.input.setInputProcessor(cameraController);
font = new BitmapFont();
batch = new SpriteBatch();
{
tiles = new Texture(Gdx.files.internal("data/maps/tiled/tiles.png"));
TextureRegion[][] splitTiles = TextureRegion.split(tiles, 32, 32);
map = new TiledMap();
MapLayers layers = map.getLayers();
for (int l = 0; l < 20; l++) {
TiledMapTileLayer layer = new TiledMapTileLayer(150, 100, 32, 32);
for (int x = 0; x < 150; x++) {
for (int y = 0; y < 100; y++) {
int ty = (int) (Math.random() * splitTiles.length);
int tx = (int) (Math.random() * splitTiles[ty].length);
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(splitTiles[ty][tx]));
layer.setCell(x, y, cell);
}
}
layers.add(layer);
}
}
renderer = new OrthogonalTiledMapRenderer(map);
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class TiledMapObjectLoadingTest method render.
@Override
public void render() {
Gdx.gl.glClearColor(0.55f, 0.55f, 0.55f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
shapeRenderer.setProjectionMatrix(camera.combined);
batch.setProjectionMatrix(camera.combined);
shapeRenderer.setColor(Color.BLUE);
Gdx.gl20.glLineWidth(2);
MapLayer layer = map.getLayers().get("Objects");
AnimatedTiledMapTile.updateAnimationBaseTime();
for (MapObject mapObject : layer.getObjects()) {
if (mapObject instanceof TiledMapTileMapObject) {
batch.begin();
TiledMapTileMapObject tmtObject = (TiledMapTileMapObject) mapObject;
TextureRegion textureRegion = tmtObject.getTile().getTextureRegion();
// TilEd rotation is clockwise, we need counter-clockwise.
float rotation = -tmtObject.getRotation();
float scaleX = tmtObject.getScaleX();
float scaleY = tmtObject.getScaleY();
float xPos = tmtObject.getX();
float yPos = tmtObject.getY();
textureRegion.flip(tmtObject.isFlipHorizontally(), tmtObject.isFlipVertically());
batch.draw(textureRegion, xPos, yPos, tmtObject.getOriginX() * scaleX, tmtObject.getOriginY() * scaleY, textureRegion.getRegionWidth() * scaleX, textureRegion.getRegionHeight() * scaleY, 1f, 1f, rotation);
// We flip back to the original state.
textureRegion.flip(tmtObject.isFlipHorizontally(), tmtObject.isFlipVertically());
batch.end();
} else if (mapObject instanceof EllipseMapObject) {
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();
shapeRenderer.ellipse(ellipse.x, ellipse.y, ellipse.width, ellipse.height);
shapeRenderer.end();
} else if (mapObject instanceof RectangleMapObject) {
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle();
shapeRenderer.rect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
shapeRenderer.end();
} else if (mapObject instanceof PolygonMapObject) {
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
Polygon polygon = ((PolygonMapObject) mapObject).getPolygon();
shapeRenderer.polygon(polygon.getTransformedVertices());
shapeRenderer.end();
}
}
batch.begin();
font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
batch.end();
}
Aggregations