use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class VehicleTest method create.
@Override
public void create() {
super.create();
instructions = "Tap to shoot\nArrow keys to drive\nR to reset\nLong press to toggle debug mode\nSwipe for next test";
final Model chassisModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
disposables.add(chassisModel);
chassisModel.materials.get(0).clear();
chassisModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE));
final Model wheelModel = objLoader.loadModel(Gdx.files.internal("data/wheel.obj"));
disposables.add(wheelModel);
wheelModel.materials.get(0).clear();
wheelModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.BLACK), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(128));
Texture checkboard = new Texture(Gdx.files.internal("data/g3d/checkboard.png"));
final Model largeGroundModel = modelBuilder.createBox(200f, 2f, 200f, new Material(TextureAttribute.createDiffuse(checkboard), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
largeGroundModel.manageDisposable(checkboard);
disposables.add(largeGroundModel);
world.addConstructor("largeground", new BulletConstructor(largeGroundModel, 0f));
BoundingBox bounds = new BoundingBox();
Vector3 chassisHalfExtents = chassisModel.calculateBoundingBox(bounds).getDimensions(new Vector3()).scl(0.5f);
Vector3 wheelHalfExtents = wheelModel.calculateBoundingBox(bounds).getDimensions(new Vector3()).scl(0.5f);
world.addConstructor("chassis", new BulletConstructor(chassisModel, 5f, new btBoxShape(chassisHalfExtents)));
world.addConstructor("wheel", new BulletConstructor(wheelModel, 0, null));
for (int i = 0; i < 1000; i += 200) world.add("largeground", 0f, -1f, i);
chassis = world.add("chassis", 0, 3f, 0);
wheels[0] = world.add("wheel", 0, 0, 0);
wheels[1] = world.add("wheel", 0, 0, 0);
wheels[2] = world.add("wheel", 0, 0, 0);
wheels[3] = world.add("wheel", 0, 0, 0);
// Create the vehicle
raycaster = getRaycaster();
tuning = new btVehicleTuning();
vehicle = new btRaycastVehicle(tuning, (btRigidBody) chassis.body, raycaster);
chassis.body.setActivationState(Collision.DISABLE_DEACTIVATION);
((btDynamicsWorld) world.collisionWorld).addVehicle(vehicle);
vehicle.setCoordinateSystem(0, 1, 2);
btWheelInfo wheelInfo;
Vector3 point = new Vector3();
Vector3 direction = new Vector3(0, -1, 0);
Vector3 axis = new Vector3(-1, 0, 0);
wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, 0.7f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, 0.7f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, -0.5f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, -0.5f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
}
use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class MoveSpriteExample method create.
public void create() {
// create a SpriteBatch with which to render the sprite
batch = new SpriteBatch();
// load the sprite's texture. note: usually you have more than
// one sprite in a texture, see {@see TextureAtlas} and {@see TextureRegion}.
texture = new Texture(Gdx.files.internal("data/bobargb8888-32x32.png"));
// create an {@link OrthographicCamera} which is used to transform
// touch coordinates to world coordinates.
camera = new OrthographicCamera();
// we want the camera to setup a viewport with pixels as units, with the
// y-axis pointing upwards. The origin will be in the lower left corner
// of the screen.
camera.setToOrtho(false);
}
use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class HeightMapTest method create.
@Override
public void create() {
super.create();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
int w = 20, h = 20;
Pixmap data = new Pixmap(Gdx.files.internal("data/g3d/heightmap.png"));
field = new HeightField(true, data, true, Usage.Position | Usage.Normal | Usage.ColorUnpacked | Usage.TextureCoordinates);
data.dispose();
field.corner00.set(-10f, 0, -10f);
field.corner10.set(10f, 0, -10f);
field.corner01.set(-10f, 0, 10f);
field.corner11.set(10f, 0, 10f);
field.color00.set(0, 0, 1, 1);
field.color01.set(0, 1, 1, 1);
field.color10.set(1, 0, 1, 1);
field.color11.set(1, 1, 1, 1);
field.magnitude.set(0f, 5f, 0f);
field.update();
ground = new Renderable();
ground.environment = environment;
ground.meshPart.mesh = field.mesh;
ground.meshPart.primitiveType = GL20.GL_TRIANGLES;
ground.meshPart.offset = 0;
ground.meshPart.size = field.mesh.getNumIndices();
ground.meshPart.update();
ground.material = new Material(TextureAttribute.createDiffuse(texture));
}
use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class MeshBuilderTest method create.
@Override
public void create() {
super.create();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
modelsWindow.setVisible(false);
Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
Material material = new Material(TextureAttribute.createDiffuse(texture));
MeshBuilder meshBuilder = new MeshBuilder();
meshBuilder.begin(Usage.Position | Usage.Normal | Usage.ColorPacked | Usage.TextureCoordinates, GL20.GL_TRIANGLES);
meshBuilder.box(1f, 1f, 1f);
Mesh mesh = new Mesh(true, meshBuilder.getNumVertices(), meshBuilder.getNumIndices(), meshBuilder.getAttributes());
mesh = meshBuilder.end(mesh);
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
modelBuilder.manage(texture);
modelBuilder.node().id = "box";
MeshPartBuilder mpb = modelBuilder.part("box", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.setColor(Color.RED);
mpb.box(1f, 1f, 1f);
modelBuilder.node().id = "sphere";
mpb = modelBuilder.part("sphere", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.sphere(2f, 2f, 2f, 10, 5);
modelBuilder.node().id = "cone";
mpb = modelBuilder.part("cone", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.setVertexTransform(new Matrix4().rotate(Vector3.X, -45f));
mpb.cone(2f, 3f, 1f, 8);
modelBuilder.node().id = "cylinder";
mpb = modelBuilder.part("cylinder", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.setUVRange(1f, 1f, 0f, 0f);
mpb.cylinder(2f, 4f, 3f, 15);
modelBuilder.node().id = "mesh";
mpb = modelBuilder.part("mesh", GL20.GL_TRIANGLES, mesh.getVertexAttributes(), material);
Matrix4 transform = new Matrix4();
mpb.setVertexTransform(transform.setToTranslation(0, 2, 0));
mpb.addMesh(mesh);
mpb.setColor(Color.BLUE);
mpb.setVertexTransform(transform.setToTranslation(1, 1, 0));
mpb.addMesh(mesh);
mpb.setColor(null);
mpb.setVertexTransform(transform.setToTranslation(-1, 1, 0).rotate(Vector3.X, 45));
mpb.addMesh(mesh);
mpb.setVertexTransform(transform.setToTranslation(0, 1, 1));
mpb.setUVRange(0.75f, 0.75f, 0.25f, 0.25f);
mpb.addMesh(mesh);
model = modelBuilder.end();
instances.add(new ModelInstance(model, new Matrix4().trn(0f, 0f, 0f), "mesh", true));
instances.add(new ModelInstance(model, new Matrix4().trn(-5f, 0f, -5f), "box", true));
instances.add(new ModelInstance(model, new Matrix4().trn(5f, 0f, -5f), "sphere", true));
instances.add(new ModelInstance(model, new Matrix4().trn(-5f, 0f, 5f), "cone", true));
instances.add(new ModelInstance(model, new Matrix4().trn(5f, 0f, 5f), "cylinder", true));
}
use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class GwtTest method create.
@Override
public void create() {
Preferences pref = Gdx.app.getPreferences("test");
boolean resultb = pref.getBoolean("test");
int resulti = pref.getInteger("test");
shader = new ShaderProgram(Gdx.files.internal("data/shaders/shader-vs.glsl"), Gdx.files.internal("data/shaders/shader-fs.glsl"));
if (!shader.isCompiled())
throw new GdxRuntimeException(shader.getLog());
mesh = new Mesh(VertexDataType.VertexBufferObject, true, 6, 0, VertexAttribute.Position(), VertexAttribute.TexCoords(0));
mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 0, 1, 0.5f, -0.5f, 0, 1, 1, 0.5f, 0.5f, 0, 1, 0, 0.5f, 0.5f, 0, 1, 0, -0.5f, 0.5f, 0, 0, 0, -0.5f, -0.5f, 0, 0, 1 });
texture = new Texture(new Pixmap(Gdx.files.internal("data/badlogic.jpg")), true);
texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
String params = Gdx.files.internal("data/gwttestparams.txt").readString();
numSprites = Integer.parseInt(params);
batch = new SpriteBatch();
positions = new ArrayList<Vector2>();
for (int i = 0; i < numSprites; i++) {
positions.add(new Vector2(MathUtils.random() * Gdx.graphics.getWidth(), MathUtils.random() * Gdx.graphics.getHeight()));
}
sprite = new Sprite(texture);
sprite.setSize(64, 64);
sprite.setOrigin(32, 32);
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
cache = font.newFontCache();
cache.setColor(Color.RED);
cache.setText("This is a Test", 0, 0);
atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
}
Aggregations