use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.
the class SkeletonTest method create.
@Override
public void create() {
super.create();
showAxes = false;
shapeRenderer = new ShapeRenderer();
shapeRenderer.setColor(Color.WHITE);
onModelClicked("g3d/knight.g3db");
}
use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.
the class PairCacheTest method create.
@Override
public void create() {
super.create();
instructions = "Tap to toggle view\nLong press to toggle debug mode\nSwipe for next test\nCtrl+drag to rotate\nScroll to zoom";
world.addConstructor("collisionBox", new BulletConstructor(world.getConstructor("box").model));
// Create the entities
final float dX = BOX_X_MAX - BOX_X_MIN;
final float dY = BOX_Y_MAX - BOX_Y_MIN;
final float dZ = BOX_Z_MAX - BOX_Z_MIN;
for (int i = 0; i < BOXCOUNT; i++) world.add("collisionBox", BOX_X_MIN + dX * (float) Math.random(), BOX_Y_MIN + dY * (float) Math.random(), BOX_Z_MIN + dZ * (float) Math.random()).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
manifoldArray = new btPersistentManifoldArray();
disposables.add(manifoldArray);
overviewCam = camera;
overviewCam.position.set(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
overviewCam.lookAt(Vector3.Zero);
overviewCam.far = 150f;
overviewCam.update();
frustumCam = new PerspectiveCamera(camera.fieldOfView, camera.viewportWidth, camera.viewportHeight);
frustumCam.far = Vector3.len(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
frustumCam.update();
final Model ghostModel = FrustumCullingTest.createFrustumModel(frustumCam.frustum.planePoints);
disposables.add(ghostModel);
// The ghost object does not need to be shaped as a camera frustum, it can have any collision shape.
ghostObject = FrustumCullingTest.createFrustumObject(frustumCam.frustum.planePoints);
disposables.add(ghostObject);
world.add(ghostEntity = new BulletEntity(ghostModel, ghostObject, 0, 0, 0));
disposables.add(ghostEntity);
shapeRenderer = new ShapeRenderer();
disposables.add(shapeRenderer);
}
use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.
the class SuperKoalio method create.
@Override
public void create() {
// load the koala frames, split them, and assign them to Animations
koalaTexture = new Texture("data/maps/tiled/super-koalio/koalio.png");
TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0];
stand = new Animation(0, regions[0]);
jump = new Animation(0, regions[1]);
walk = new Animation(0.15f, regions[2], regions[3], regions[4]);
walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);
// figure out the width and height of the koala for collision
// detection and rendering by converting a koala frames pixel
// size into world units (1 unit == 16 pixels)
Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth();
Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight();
// load the map, set the unit scale to 1/16 (1 unit == 16 pixels)
map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f);
// create an orthographic camera, shows us 30x20 units of the world
camera = new OrthographicCamera();
camera.setToOrtho(false, 30, 20);
camera.update();
// create the Koala we want to move around the world
koala = new Koala();
koala.position.set(20, 20);
debugRenderer = new ShapeRenderer();
}
use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project bdx by GoranM.
the class Scene method init.
public void init() {
requestedRestart = false;
requestedEnd = false;
paused = false;
visible = true;
if (shapeRenderer == null)
shapeRenderer = new ShapeRenderer();
drawCommands = new ArrayList<ArrayList<Object>>();
lastFrameBuffer = new RenderBuffer(null);
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0, 0, 0, 1));
environment.set(new PointLightsAttribute());
environment.set(new SpotLightsAttribute());
environment.set(new DirectionalLightsAttribute());
screenShaders = new ArrayList<ScreenShader>();
defaultMaterial = new Material("__BDX_DEFAULT");
defaultMaterial.set(new ColorAttribute(ColorAttribute.AmbientLight, 1, 1, 1, 1));
defaultMaterial.set(new ColorAttribute(ColorAttribute.Diffuse, 1, 1, 1, 1));
defaultMaterial.set(new BlendingAttribute());
defaultMaterial.set(new BDXColorAttribute(BDXColorAttribute.Tint, 0, 0, 0));
defaultMesh = new Mesh(new ModelBuilder().createBox(1.0f, 1.0f, 1.0f, defaultMaterial, Usage.Position | Usage.Normal | Usage.TextureCoordinates), this);
meshes = new HashMap<String, Mesh>();
textures = new HashMap<String, Texture>();
materials = new HashMap<String, Material>();
modelToFrame = new HashMap<>();
materials.put(defaultMaterial.id, defaultMaterial);
BroadphaseInterface broadphase = new DbvtBroadphase();
DefaultCollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration();
SequentialImpulseConstraintSolver solver = new SequentialImpulseConstraintSolver();
CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConfiguration);
toBeAdded = new ArrayList<GameObject>();
toBeRemoved = new ArrayList<GameObject>();
objects = new LinkedListNamed<GameObject>();
lights = new LinkedListNamed<Light>();
templates = new HashMap<String, GameObject>();
json = new JsonReader().parse(scene);
name = json.get("name").asString();
world = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
world.setDebugDrawer(new Bullet.DebugDrawer(json.get("physviz").asBoolean()));
gravity(new Vector3f(0, 0, -json.get("gravity").asFloat()));
float[] ac = json.get("ambientColor").asFloatArray();
ambientLight(new Color(ac[0], ac[1], ac[2], 1));
if (!clearColorDefaultSet) {
float[] cc = json.get("clearColor").asFloatArray();
Bdx.display.clearColor.set(cc[0], cc[1], cc[2], 0);
clearColorDefaultSet = true;
}
if (json.get("framerateProfile").asBoolean()) {
Bdx.profiler.init();
}
float[] fc = json.get("clearColor").asFloatArray();
fogColor = new Color(fc[0], fc[1], fc[2], 1);
fog(json.get("mistOn").asBoolean());
fogRange(json.get("mistStart").asFloat(), json.get("mistDepth").asFloat());
for (JsonValue mat : json.get("materials")) {
String texName = mat.get("texture").asString();
boolean hasAlpha = mat.get("alpha_blend").asString().equals("ALPHA");
float opacity = hasAlpha ? mat.get("opacity").asFloat() : 1;
Material material = new Material(mat.name);
float[] c = mat.get("color").asFloatArray();
material.set(ColorAttribute.createDiffuse(c[0], c[1], c[2], opacity));
float[] s = mat.get("spec_color").asFloatArray();
material.set(ColorAttribute.createSpecular(s[0], s[1], s[2], 1));
material.set(FloatAttribute.createShininess(mat.get("shininess").asFloat()));
material.set(new BDXColorAttribute(BDXColorAttribute.Tint, 0, 0, 0));
IntAttribute shadeless = (IntAttribute) new BDXIntAttribute();
if (mat.get("shadeless").asBoolean())
shadeless.value = 1;
material.set(shadeless);
float emitStrength = mat.get("emit").asFloat();
material.set(new BDXColorAttribute(BDXColorAttribute.Emit, emitStrength, emitStrength, emitStrength));
if (mat.get("backface_culling").asBoolean())
material.set(new IntAttribute(IntAttribute.CullFace, GL20.GL_BACK));
else
material.set(new IntAttribute(IntAttribute.CullFace, GL20.GL_NONE));
if (texName != null) {
Texture texture = textures.get(texName);
if (texture == null) {
texture = new Texture(Gdx.files.internal("bdx/textures/" + texName));
textures.put(texName, texture);
}
texture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
material.texture(texture);
}
material.set(new DepthTestAttribute());
if (hasAlpha) {
BlendingAttribute ba = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
ba.opacity = opacity;
material.set(ba);
// Discard pixels that fail this alpha test (sub-1% alpha)
material.set(FloatAttribute.createAlphaTest(0.01f));
// Turn on back-to-front sorting for alpha-enabled objects by default
material.backToFrontSorting(true);
} else {
BlendingAttribute ba = new BlendingAttribute();
ba.blended = false;
material.set(ba);
}
materials.put(mat.name, material);
}
for (JsonValue model : json.get("models")) {
meshes.put(model.name, new Mesh(createModel(model), this, model.name));
}
HashMap<String, JsonValue> fonts = new HashMap<>();
for (JsonValue fontj : json.get("fonts")) {
String font = fontj.asString();
fonts.put(font, new JsonReader().parse(Gdx.files.internal("bdx/fonts/" + font + ".fntx")));
}
FAnim.loadActions(json.get("actions"));
for (JsonValue gobj : json.get("objects")) {
GameObject g = instantiator.newObject(gobj);
g.json = gobj;
g.name = gobj.name;
g.scene = this;
g.props = new HashMap<String, JsonValue>();
for (JsonValue prop : gobj.get("properties")) {
g.props.put(prop.name, prop);
}
String meshName = gobj.get("mesh_name").asString();
if (meshName != null) {
g.visibleNoChildren(gobj.get("visible").asBoolean());
g.mesh(meshName);
} else {
g.visibleNoChildren(false);
g.mesh(defaultMesh);
}
com.badlogic.gdx.graphics.Mesh mesh = g.modelInstance.model.meshes.first();
float[] trans = gobj.get("transform").asFloatArray();
JsonValue origin = json.get("origins").get(meshName);
JsonValue dimensions = json.get("dimensions").get(meshName);
g.origin = origin == null ? new Vector3f() : new Vector3f(origin.asFloatArray());
g.dimensionsNoScale = dimensions == null ? new Vector3f(1, 1, 1) : new Vector3f(dimensions.asFloatArray());
JsonValue physics = gobj.get("physics");
g.currBodyType = GameObject.BodyType.valueOf(physics.get("body_type").asString());
g.currBoundsType = GameObject.BoundsType.valueOf(physics.get("bounds_type").asString());
g.body = Bullet.makeBody(mesh, trans, g.origin, g.currBodyType, g.currBoundsType, physics);
g.body.setUserPointer(g);
g.scale(getGLMatrixScale(trans));
String type = gobj.get("type").asString();
if (type.equals("FONT")) {
Text t = (Text) g;
t.font = fonts.get(gobj.get("font").asString());
t.text(gobj.get("text").asString());
t.capacity = t.text().length();
String align = gobj.get("alignment").asString();
if (align.equals("RIGHT"))
t.alignment(Text.Alignment.RIGHT);
else if (align.equals("CENTER"))
t.alignment(Text.Alignment.CENTER);
else
t.alignment(Text.Alignment.LEFT);
} else if (type.equals("LAMP")) {
JsonValue settings = gobj.get("lamp");
Light l = (Light) g;
if (settings.getString("type").equals("SUN"))
l.type = Light.Type.SUN;
else if (settings.getString("type").equals("SPOT"))
l.type = Light.Type.SPOT;
else
// POINT lamps; HEMI and AREA aren't supported, so they're turned into POINTs
l.type = Light.Type.POINT;
l.energy(settings.getFloat("energy"));
float[] c = settings.get("color").asFloatArray();
l.color(new Color(c[0], c[1], c[2], c[3]));
if (l.type.equals(Light.Type.SPOT)) {
l.spotSize(settings.getFloat("spot_size"));
}
} else if (type.equals("CAMERA")) {
Camera c = (Camera) g;
float[] projection = gobj.get("camera").get("projection").asFloatArray();
Vector2f resolution = new Vector2f(json.get("resolution").asFloatArray());
if (gobj.get("camera").get("type").asString().equals("PERSP")) {
c.initData(Camera.Type.PERSPECTIVE);
c.size(resolution);
c.resolution(resolution);
c.projection(new Matrix4f(projection));
c.fov(c.fov());
} else {
c.initData(Camera.Type.ORTHOGRAPHIC);
c.size(resolution);
c.resolution(resolution);
c.zoom(2 / projection[0]);
}
Matrix4 pm = new Matrix4(projection);
pm.inv();
Vector3 vec = new Vector3(0, 0, -1);
vec.prj(pm);
c.near(-vec.z);
vec.set(0, 0, 1);
vec.prj(pm);
c.far(-vec.z);
}
templates.put(g.name, g);
}
hookParentChild();
cameras = new ArrayListNamed<Camera>();
addInstances();
camera = (Camera) objects.get(json.get("cameras").asStringArray()[0]);
String frameType = json.get("frame_type").asString();
Viewport.Type viewportType;
if (frameType.equals("LETTERBOX")) {
viewportType = Viewport.Type.LETTERBOX;
} else if (frameType.equals("EXTEND")) {
viewportType = Viewport.Type.EXTEND;
} else {
// "SCALE"
viewportType = Viewport.Type.SCALE;
}
viewport = new Viewport(this, viewportType);
for (GameObject g : sortByPriority(new ArrayList<GameObject>(objects))) {
initGameObject(g);
}
valid = true;
}
use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.
the class FreeTypeMetricsTest method create.
@Override
public void create() {
spriteBatch = new SpriteBatch();
atlas = new TextureAtlas("data/pack");
smallFont = new BitmapFont();
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = 60;
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf"));
font = generator.generateFont(parameter);
generator.dispose();
renderer = new ShapeRenderer();
renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix());
}
Aggregations