use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.
the class GestureDetectorTest method create.
@Override
public void create() {
texture = new Texture("data/stones.jpg");
batch = new SpriteBatch();
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
controller = new CameraController();
gestureDetector = new GestureDetector(20, 0.5f, 2, 0.15f, controller);
Gdx.input.setInputProcessor(gestureDetector);
}
use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.
the class DpiTest method create.
@Override
public void create() {
font = new BitmapFont();
batch = new SpriteBatch();
}
use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.
the class CullTest method create.
@Override
public void create() {
ModelBuilder builder = new ModelBuilder();
sphere = builder.createSphere(2f, 2f, 2f, 16, 16, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), Usage.Position | Usage.Normal);
// cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam = new OrthographicCamera(45, 45 * (Gdx.graphics.getWidth() / (float) Gdx.graphics.getHeight()));
cam.near = 1;
cam.far = 200;
Random rand = new Random();
for (int i = 0; i < instances.length; i++) {
pos.set(rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * -100 - 3);
instances[i] = new ModelInstance(sphere, pos);
}
modelBatch = new ModelBatch();
batch = new SpriteBatch();
font = new BitmapFont();
// Gdx.graphics.setVSync(true);
// Gdx.app.log("CullTest", "" + Gdx.graphics.getBufferFormat().toString());
}
use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.
the class MultipleRenderTargetTest method create.
@Override
public void create() {
//use default prepend shader code for batch, some gpu drivers are less forgiving
batch = new SpriteBatch();
//depth texture not currently sampled
ShaderProgram.pedantic = false;
modelCache = new ModelCache();
ShaderProgram.prependVertexCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_ARB_explicit_attrib_location : enable\n" : "#version 300 es\n";
ShaderProgram.prependFragmentCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_ARB_explicit_attrib_location : enable\n" : "#version 300 es\n";
renderContext = new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.ROUNDROBIN));
shaderProvider = new BaseShaderProvider() {
@Override
protected Shader createShader(Renderable renderable) {
return new MRTShader(renderable);
}
};
renderableSorter = new DefaultRenderableSorter() {
@Override
public int compare(Renderable o1, Renderable o2) {
return o1.shader.compareTo(o2.shader);
}
};
mrtSceneShader = new ShaderProgram(Gdx.files.internal("data/g3d/shaders/mrtscene.vert"), Gdx.files.internal("data/g3d/shaders/mrtscene.frag"));
if (!mrtSceneShader.isCompiled()) {
System.out.println(mrtSceneShader.getLog());
}
quad = createFullScreenQuad();
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.near = 1f;
camera.far = 100f;
camera.position.set(3, 5, 10);
camera.lookAt(0, 2, 0);
camera.up.set(0, 1, 0);
camera.update();
cameraController = new FirstPersonCameraController(camera);
cameraController.setVelocity(50);
Gdx.input.setInputProcessor(cameraController);
frameBuffer = new MRTFrameBuffer(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 3);
AssetManager assetManager = new AssetManager();
assetManager.load("data/g3d/materials/cannon.g3db", Model.class);
assetManager.finishLoading();
Model scene = assetManager.get("data/g3d/materials/cannon.g3db");
cannon = new ModelInstance(scene, "Cannon_LP");
cannon.transform.setToTranslationAndScaling(0, 0, 0, 0.001f, 0.001f, 0.001f);
ModelBuilder modelBuilder = new ModelBuilder();
for (int i = 0; i < NUM_LIGHTS; i++) {
modelBuilder.begin();
Light light = new Light();
light.color.set(MathUtils.random(1f), MathUtils.random(1f), MathUtils.random(1f));
light.position.set(MathUtils.random(-10f, 10f), MathUtils.random(10f, 15f), MathUtils.random(-10f, 10f));
light.vy = MathUtils.random(10f, 20f);
light.vx = MathUtils.random(-10f, 10f);
light.vz = MathUtils.random(-10f, 10f);
MeshPartBuilder meshPartBuilder = modelBuilder.part("light", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, new Material());
meshPartBuilder.setColor(light.color.x, light.color.y, light.color.z, 1f);
meshPartBuilder.sphere(0.2f, 0.2f, 0.2f, 10, 10);
light.lightInstance = new ModelInstance(modelBuilder.end());
lights.add(light);
}
modelBuilder.begin();
MeshPartBuilder meshPartBuilder = modelBuilder.part("floor", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, new Material());
meshPartBuilder.setColor(0.2f, 0.2f, 0.2f, 1f);
meshPartBuilder.box(0, -0.1f, 0f, 20f, 0.1f, 20f);
floorInstance = new ModelInstance(modelBuilder.end());
Gdx.input.setInputProcessor(new InputMultiplexer(this, cameraController));
}
use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.
the class VoxelTest method create.
@Override
public void create() {
spriteBatch = new SpriteBatch();
font = new BitmapFont();
modelBatch = new ModelBatch();
DefaultShader.defaultCullFace = GL20.GL_FRONT;
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.near = 0.5f;
camera.far = 1000;
controller = new FirstPersonCameraController(camera);
Gdx.input.setInputProcessor(controller);
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
lights.add(new DirectionalLight().set(1, 1, 1, 0, -1, 0));
Texture texture = new Texture(Gdx.files.internal("data/g3d/tiles.png"));
TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32);
MathUtils.random.setSeed(0);
voxelWorld = new VoxelWorld(tiles[0], 20, 4, 20);
PerlinNoiseGenerator.generateVoxels(voxelWorld, 0, 63, 10);
float camX = voxelWorld.voxelsX / 2f;
float camZ = voxelWorld.voxelsZ / 2f;
float camY = voxelWorld.getHighest(camX, camZ) + 1.5f;
camera.position.set(camX, camY, camZ);
}
Aggregations