package de.eightbitboy.ecorealms;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.VertexAttributes;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;

import de.eightbitboy.ecorealms.world.World;

public class EcoRealms extends ApplicationAdapter {
	private EcoRealmsConfig config;
	private World world;

	private PerspectiveCamera cam;
	public ModelBatch modelBatch;
	public Model model;
	public ModelInstance instance;

	public EcoRealms() {
		this.config = new EcoRealmsConfig();
	}

	public EcoRealms(EcoRealmsConfig config) {
		this.config = config;
	}

	@Override
	public void create() {
		modelBatch = new ModelBatch();
		createWorld();
		createCamera();
		createModel();
	}

	@Override
	public void render() {
		Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

		modelBatch.begin(cam);
		modelBatch.render(instance);
		modelBatch.end();
	}

	@Override
	public void dispose() {
		modelBatch.dispose();
		model.dispose();
	}

	private void createWorld() {
		world = new World(config.WORLD_SIZE_X, config.WORLD_SIZE_Y);
	}

	private void createCamera() {
		cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		cam.position.set(10f, 10f, 10f);
		cam.lookAt(0, 0, 0);
		cam.near = 1f;
		cam.far = 300f;
		cam.update();
	}

	private void createModel() {
		ModelBuilder modelBuilder = new ModelBuilder();
		model = modelBuilder.createBox(5f, 5f, 5f,
				new Material(ColorAttribute.createDiffuse(Color.GREEN)),
				VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
		instance = new ModelInstance(model);
	}
}

@@ -371,24 +371,74 @@
 priteBatch;%0A
+import com.badlogic.gdx.graphics.g3d.Environment;%0A
 import com.b
@@ -681,16 +681,83 @@
 ribute;%0A
+import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;%0A
 import c
@@ -960,16 +960,50 @@
 world;%0A%0A
+%09private Environment environment;%0A
 %09private
@@ -1024,29 +1024,30 @@
 mera cam;%0A%09p
-ublic
+rivate
  ModelBatch 
@@ -1056,29 +1056,30 @@
 delBatch;%0A%09p
-ublic
+rivate
  Model model
@@ -1082,21 +1082,22 @@
 odel;%0A%09p
-ublic
+rivate
  ModelIn
@@ -1332,24 +1332,47 @@
 ateWorld();%0A
+%09%09createEnvironment();%0A
 %09%09createCame
@@ -1636,16 +1636,29 @@
 instance
+, environment
 );%0A%09%09mod
@@ -1852,24 +1852,272 @@
 IZE_Y);%0A%09%7D%0A%0A
+%09private void createEnvironment()%7B%0A%09%09environment = new Environment();%0A%09%09environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));%0A%09%09environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));%0A%09%7D%0A%0A
 %09private voi

Add lighting