/// <summary> /// Initializes a new instance of the <see cref="DebugGraphicsScreen" /> class. /// </summary> /// <param name="services">The services.</param> public DebugGraphicsScreen(IServiceLocator services) : base(services?.GetInstance <IGraphicsService>()) { if (services == null) { throw new ArgumentNullException(nameof(services)); } Coverage = GraphicsScreenCoverage.Partial; _spriteBatch = GraphicsService.GetSpriteBatch(); _whiteTexture = GraphicsService.GetDefaultTexture2DWhite(); var contentManager = services.GetInstance <ContentManager>(); var spriteFont = contentManager.Load <SpriteFont>("DigitalRune.Editor.Game/Fonts/DejaVuSans"); DebugRenderer = new DebugRenderer(GraphicsService, spriteFont); _internalDebugRenderer = new DebugRenderer(GraphicsService, spriteFont); // To count the update frame rate, we handle the GameLogicUpdating event. // (We cannot use GraphicsScreen.OnUpdate because it is only called at the same rate if // the graphics screen is registered in the graphics service. If it is not registered, // then OnUpdate and OnRender are always called together.) var editor = services.GetInstance <IEditorService>(); _gameExtension = editor.Extensions.OfType <GameExtension>().FirstOrDefault(); if (_gameExtension != null) { _gameExtension.GameLogicUpdating += OnGameLogicUpdating; } }
private void DrawProgressBar(Rectangle bounds, float progress) { var whiteTexture = GraphicsService.GetDefaultTexture2DWhite(); // Draw border. _spriteBatch.Draw(whiteTexture, bounds, null, Color.White); // Draw inner rectangle. bounds.X += 2; bounds.Y += 2; bounds.Width -= 4; bounds.Height -= 4; _spriteBatch.Draw(whiteTexture, bounds, null, Color.Black); // Draw progress indicator. if (progress > 0) { bounds.Width = (int)(bounds.Width * MathHelper.Clamp(progress, 0, 1)); var color = (progress < 1) ? Color.Lime : Color.Yellow; _spriteBatch.Draw(whiteTexture, bounds, null, color); } }
public TerrainDecalSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; _graphicsScreen = new DeferredGraphicsScreen(Services); _graphicsScreen.DrawReticle = true; GraphicsService.Screens.Insert(0, _graphicsScreen); GameObjectService.Objects.Add(new DeferredGraphicsOptionsObject(Services)); Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer); var scene = _graphicsScreen.Scene; Services.Register(typeof(IScene), null, scene); // Add gravity and damping to the physics simulation. Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); // Add a custom game object which controls the camera. var cameraObject = new CameraObject(Services, 5000); cameraObject.ResetPose(new Vector3F(0, 2, 5), 0, 0); GameObjectService.Objects.Add(cameraObject); _graphicsScreen.ActiveCameraNode = cameraObject.CameraNode; // Add standard game objects. GameObjectService.Objects.Add(new GrabObject(Services)); GameObjectService.Objects.Add(new ObjectCreatorObject(Services)); GameObjectService.Objects.Add(new LavaBallsObject(Services)); GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true) { EnableCloudShadows = false, }); GameObjectService.Objects.Add(new FogObject(Services)); // Create terrain. _terrainObject = new TerrainObject(Services); GameObjectService.Objects.Add(_terrainObject); // Add a blood decal to the terrain. var decal0 = new TerrainDecalLayer(GraphicsService) { Pose = GetRandomPose(), Width = 2, Height = 2, DiffuseColor = new Vector3F(0.08f), SpecularColor = new Vector3F(0.2f), SpecularPower = 100, DiffuseTexture = ContentManager.Load <Texture2D>("Decals/Decal_diffuse_mask"), // Original: "Decals/Blood_diffuse_mask", NormalTexture = GraphicsService.GetDefaultNormalTexture(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_normal"), SpecularTexture = GraphicsService.GetDefaultTexture2DWhite(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_specular"), FadeOutStart = 3, FadeOutEnd = 5, Alpha = 0.9f, }; AddDecal(decal0); // Add a black blood decal (oil spill?) var decal1 = new TerrainDecalLayer(GraphicsService) { Pose = GetRandomPose(), Width = 2, Height = 2, DiffuseColor = new Vector3F(0.0f), SpecularColor = new Vector3F(0.5f), SpecularPower = 100, DiffuseTexture = ContentManager.Load <Texture2D>("Decals/Decal_diffuse_mask"), // Original: "Decals/Blood_diffuse_mask", NormalTexture = GraphicsService.GetDefaultNormalTexture(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_normal"), SpecularTexture = GraphicsService.GetDefaultTexture2DWhite(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_specular"), FadeOutStart = 3, FadeOutEnd = 5, }; AddDecal(decal1); // Add more random decals. The decals can share materials! var decal0Material = decal0.Material; for (int i = 0; i < 50; i++) { var decal = new TerrainDecalLayer(decal0Material) { Pose = GetRandomPose(), Width = 2, Height = 2, }; AddDecal(decal); } }