use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class FrameBufferTest method create.
@Override
public void create() {
mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
float c1 = Color.toFloatBits(255, 0, 0, 255);
float c2 = Color.toFloatBits(255, 0, 0, 255);
float c3 = Color.toFloatBits(0, 0, 255, 255);
mesh.setVertices(new float[] { -0.5f, -0.5f, 0, c1, 0, 0, 0.5f, -0.5f, 0, c2, 1, 0, 0, 0.5f, 0, c3, 0.5f, 1 });
stencilMesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
stencilMesh.setVertices(new float[] { -0.5f, 0.5f, 0, c1, 0, 0, 0.5f, 0.5f, 0, c2, 1, 0, 0, -0.5f, 0, c3, 0.5f, 1 });
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
spriteBatch = new SpriteBatch();
frameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false);
stencilFrameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false, true);
createShader(Gdx.graphics);
}
use of com.badlogic.gdx.graphics.Texture 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.Texture in project libgdx by libgdx.
the class CharacterTest method create.
@Override
public void create() {
super.create();
instructions = "Tap to shoot\nArrow keys to move\nR to reset\nLong press to toggle debug mode\nSwipe for next test";
// Create a visual representation of the character (note that we don't use the physics part of BulletEntity, we'll do that manually)
final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
disposables.add(texture);
final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1), FloatAttribute.createShininess(8f));
final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes);
disposables.add(capsule);
world.addConstructor("capsule", new BulletConstructor(capsule, null));
character = world.add("capsule", 5f, 3f, 5f);
// Set by reference
characterTransform = character.transform;
characterTransform.rotate(Vector3.X, 90);
// Create the physics representation of the character
ghostObject = new btPairCachingGhostObject();
ghostObject.setWorldTransform(characterTransform);
ghostShape = new btCapsuleShape(2f, 2f);
ghostObject.setCollisionShape(ghostShape);
ghostObject.setCollisionFlags(btCollisionObject.CollisionFlags.CF_CHARACTER_OBJECT);
characterController = new btKinematicCharacterController(ghostObject, ghostShape, .35f, Vector3.Y);
// And add it to the physics world
world.collisionWorld.addCollisionObject(ghostObject, (short) btBroadphaseProxy.CollisionFilterGroups.CharacterFilter, (short) (btBroadphaseProxy.CollisionFilterGroups.StaticFilter | btBroadphaseProxy.CollisionFilterGroups.DefaultFilter));
((btDiscreteDynamicsWorld) (world.collisionWorld)).addAction(characterController);
// Add the ground
(ground = world.add("ground", 0f, 0f, 0f)).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
// Create some boxes to play with
for (int x = 0; x < BOXCOUNT_X; x++) {
for (int y = 0; y < BOXCOUNT_Y; y++) {
for (int z = 0; z < BOXCOUNT_Z; z++) {
world.add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
}
}
}
}
use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class TileTest method create.
@Override
public void create() {
cam = new OrthographicCamera(480, 320);
cam.position.set(WIDTH * 32 / 2, HEIGHT * 32 / 2, 0);
camController = new OrthoCamController(cam);
Gdx.input.setInputProcessor(camController);
texture = new Texture(Gdx.files.internal("data/tiles.png"));
Random rand = new Random();
for (int i = 0; i < LAYERS; i++) {
caches[i] = new SpriteCache();
SpriteCache cache = caches[i];
cache.beginCache();
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
int tileX = rand.nextInt(5);
int tileY = rand.nextInt(5);
cache.add(texture, x << 5, y << 5, 1 + tileX * 33, 1 + tileY * 33, 32, 32);
}
}
layers[i] = cache.endCache();
}
}
use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class OcclusionBuffer method drawDebugTexture.
/** Draw the depth buffer to a texture. Slow, should only be used for debugging purposes.
*
* @return Region of debug texture */
public TextureRegion drawDebugTexture() {
if (debugPixmap == null) {
debugPixmap = new Pixmap(bufferWidth, bufferHeight, Pixmap.Format.RGBA8888);
debugTexture = new Texture(debugPixmap);
debugTextureRegion = new TextureRegion(debugTexture);
debugTextureRegion.flip(false, true);
}
debugPixmap.setColor(Color.BLACK);
debugPixmap.fill();
// Find min/max depth values in buffer
float minDepth = Float.POSITIVE_INFINITY;
float maxDepth = Float.NEGATIVE_INFINITY;
buffer.clear();
while (buffer.position() < buffer.capacity()) {
float depth = MathUtils.clamp(buffer.get(), 0, Float.POSITIVE_INFINITY);
minDepth = Math.min(depth, minDepth);
maxDepth = Math.max(depth, maxDepth);
}
float extent = 1 / (maxDepth - minDepth);
buffer.clear();
// Draw to pixmap
for (int x = 0; x < bufferWidth; x++) {
for (int y = 0; y < bufferHeight; y++) {
float depth = MathUtils.clamp(buffer.get(x + y * bufferWidth), 0, Float.POSITIVE_INFINITY);
float c = depth * extent;
debugPixmap.drawPixel(x, y, Color.rgba8888(c, c, c, 1));
}
}
debugTexture.draw(debugPixmap, 0, 0);
return debugTextureRegion;
}
Aggregations