/** * Renderer for all visible 3D components. * * @param camera * @param boardController * handles interactions between the behind the scenes logic and * what is drawn * @param piecePlacement * array of 64 shorts defining the contents of all 64 board * locations */ public PerspectiveRenderer(Camera camera, BoardController boardController, short[] piecePlacement) { mCamera = camera; mBoardController = boardController; mShadowBatch = new ModelBatch(new DepthShaderProvider()); mCubeMapBatch = new ModelBatch(Gdx.files.internal("shaders/cubevertex.glsl"), Gdx.files.internal("shaders/cubefragment.glsl")); mBackgroundBatch = new ModelBatch(); mEnvironment = new Environment(); mBackgroundEnvironment = new Environment(); mDrawables = new Array<ABaseObject>(); mGraveyard = new ChessPieceGraveyard(); mLightDirection = new Vector3(11.0f, -9.0f, 11.0f); configureEnvironments(); createGameObjects(piecePlacement); }
public GameRenderer(Viewport viewport, Camera camera, GameEngine engine) { this.viewport = viewport; this.camera = camera; this.engine = engine; shapeRenderer = new MyShapeRenderer(); shapeRenderer.setAutoShapeType(true); spriteBatch = new SpriteBatch(); font = new BitmapFont(); font.setColor(Color.WHITE); font.setUseIntegerPositions(false); font.getData().setScale(0.01f); shadowBatch = new ModelBatch(new DepthShaderProvider()); ShaderProgram.pedantic = false; final String vertUber = Gdx.files.internal("shaders/uber.vert").readString(); final String fragUber = Gdx.files.internal("shaders/uber.frag").readString(); modelBatch = new ModelBatch(new DefaultShaderProvider(vertUber, fragUber) { @Override protected Shader createShader(final Renderable renderable) { return new UberShader(renderable, config); } }); }
@Override public void create () { modelBatch = new ModelBatch(); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f)); environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -1f, -.8f, -.2f)); environment.shadowMap = shadowLight; cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0f, 7f, 10f); cam.lookAt(0, 0, 0); cam.near = 1f; cam.far = 50f; cam.update(); ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.Color, new Material(ColorAttribute.createDiffuse(Color.WHITE))); mpb.setColor(1f, 1f, 1f, 1f); mpb.box(0, -1.5f, 0, 10, 1, 10); mpb.setColor(1f, 0f, 1f, 1f); mpb.sphere(2f, 2f, 2f, 10, 10); model = modelBuilder.end(); instance = new ModelInstance(model); shadowBatch = new ModelBatch(new DepthShaderProvider()); Gdx.input.setInputProcessor(camController = new CameraInputController(cam)); }
public static void createBatchs() { Config modelConfigShader = new Config(Gdx.files.classpath(VERTEX_SHADER).readString(), Gdx.files.classpath(FRAGMENT_SHADER).readString()); modelConfigShader.numBones = MAX_BONES; modelConfigShader.numDirectionalLights = 0; modelConfigShader.numPointLights = 0; modelConfigShader.numSpotLights = 0; modelBatch = new ModelBatch(new DefaultShaderProvider(modelConfigShader)); shadowBatch = new ModelBatch(new DepthShaderProvider()); floorBatch = new ModelBatch(new DefaultShaderProvider(Gdx.files.classpath(VERTEX_SHADER), Gdx.files.classpath(FLOOR_FRAGMENT_SHADER))); }
@Override public void create () { super.create(); lights = new Environment(); lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f)); lights.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)) .set(0.8f, 0.8f, 0.8f, -.4f, -.4f, -.4f)); lights.shadowMap = shadowLight; inputController.rotateLeftKey = inputController.rotateRightKey = inputController.forwardKey = inputController.backwardKey = 0; cam.position.set(25, 25, 25); cam.lookAt(0, 0, 0); cam.update(); modelsWindow.setVisible(false); assets.load("data/g3d/skydome.g3db", Model.class); assets.load("data/g3d/concrete.png", Texture.class); assets.load("data/tree.png", Texture.class); loading = true; trForward.translation.set(0, 0, 8f); trBackward.translation.set(0, 0, -8f); trLeft.rotation.setFromAxis(Vector3.Y, 90); trRight.rotation.setFromAxis(Vector3.Y, -90); ModelBuilder builder = new ModelBuilder(); builder.begin(); builder.node().id = "floor"; MeshPartBuilder part = builder.part("floor", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material("concrete")); ((MeshBuilder)part).ensureRectangles(1600); for (float x = -200f; x < 200f; x += 10f) { for (float z = -200f; z < 200f; z += 10f) { part.rect(x, 0, z + 10f, x + 10f, 0, z + 10f, x + 10f, 0, z, x, 0, z, 0, 1, 0); } } builder.node().id = "tree"; part = builder.part("tree", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material("tree")); part.rect( 0f, 0f, -10f, 10f, 0f, -10f, 10f, 10f, -10f, 0f, 10f, -10f, 0, 0, 1f); part.setUVRange(1, 0, 0, 1); part.rect(10f, 0f, -10f, 0f, 0f, -10f, 0f, 10f, -10f, 10f, 10f, -10f, 0, 0, -1f); floorModel = builder.end(); shadowBatch = new ModelBatch(new DepthShaderProvider()); }
public GameLevelScreen(LevelFile levelDef) { this.gameObjectsTweenManager = new TweenManager(); this.uiTweenManager = new TweenManager(); this.renderContext = new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1)); this.entities = new ArrayList<Entity>(); this.perspectiveCamera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); levelDefinition = levelDef; this.map = new Map(levelDefinition.geometryFile()); perspectiveCamera.position.set(0, 0, 0); perspectiveCamera.near = 0.1f; perspectiveCamera.far = 50f; perspectiveCamera.update(true); this.cameraController = new RTSCameraController(); cameraController.setCamera(perspectiveCamera); cameraController.setCenter(0, 0); cameraController.setEnabled(true); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1f)); this.cellShadingCompositor = new LevelCompositor(renderContext); this.robot = BotLogic.entities.robot(); this.robot.led = BotLogic.entities.led(); addEntity(this.robot); addEntity(this.robot.led); colorModelBatch = new ModelBatch(renderContext); decalBatch = new DecalBatch(); decalBatch.setGroupStrategy(new CameraGroupStrategy(perspectiveCamera)); DepthShader.Config depthConfig = new DepthShader.Config(Gdx.files.internal("shaders/depth.vertex").readString(), Gdx.files.internal("shaders/depth.frag").readString()); depthConfig.defaultCullFace = GL20.GL_BACK; depthConfig.depthBufferOnly = false; depthModelBatch = new ModelBatch(renderContext, new DepthShaderProvider(depthConfig)); map.environment = environment; this.controller = new GameController(this); reset(); environment.set(new ColorAttribute(ColorAttribute.Fog, 0f, 0f, 0f, 1f)); environment.add(new DirectionalLight().set(new Color(.4f,.4f, .4f, 0.1f), new Vector3(1,-1,0))); BotLogic.audio.mainMenuMusic.play(); }