protected override void InitializeCore() { base.InitializeCore(); backgroundEffect = new EffectInstance(new Effect(RenderSystem.GraphicsDevice, BackgroundEffect.Bytecode) { Name = "BackgroundEffect" }); spriteBatch = new SpriteBatch(RenderSystem.GraphicsDevice) { VirtualResolution = new Vector3(1) }; }
protected override void InitializeCore() { base.InitializeCore(); backgroundEffect = new Effect(Context.GraphicsDevice, BackgroundEffect.Bytecode) { Name = "BackgroundEffect" }; spriteBatch = new SpriteBatch(Context.GraphicsDevice) { VirtualResolution = new Vector3(1)}; }
public override void Start() { // create the SpriteBatch used to render them spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = new Vector3(virtualResolution, 1000) }; // initialize parameters textHeight = Font.MeasureString(KeyboardSessionString).Y; screenSize = new Vector2(virtualResolution.X, virtualResolution.Y); roundTextureSize = new Vector2(RoundTexture.Width, RoundTexture.Height); // activate the gesture recognitions if (!IsLiveReloading) // Live Scripting: do it only on first launch { Input.ActivatedGestures.Add(new GestureConfigDrag()); Input.ActivatedGestures.Add(new GestureConfigFlick()); Input.ActivatedGestures.Add(new GestureConfigLongPress()); Input.ActivatedGestures.Add(new GestureConfigComposite()); Input.ActivatedGestures.Add(new GestureConfigTap()); } // Add Graphics Layer var scene = SceneSystem.SceneInstance.Scene; var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor); compositor.Master.Renderers.Add(delegateRenderer = new SceneDelegateRenderer(Render)); }
public override void Start() { base.Start(); customEffect = EffectSystem.LoadEffect("Effect").WaitForResult(); customEffectInstance = new EffectInstance(customEffect); spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = new Vector3(1) }; // set fixed parameters once customEffectInstance.Parameters.Set(TexturingKeys.Sampler, samplerState); customEffectInstance.Parameters.Set(EffectKeys.Center, new Vector2(0.5f, 0.5f)); customEffectInstance.Parameters.Set(EffectKeys.Frequency, 40); customEffectInstance.Parameters.Set(EffectKeys.Spread, 0.5f); customEffectInstance.Parameters.Set(EffectKeys.Amplitude, 0.015f); customEffectInstance.Parameters.Set(EffectKeys.InvAspectRatio, GraphicsDevice.Presenter.BackBuffer.Height / (float)GraphicsDevice.Presenter.BackBuffer.Width); // NOTE: Linear-Wrap sampling is not available for non-square non-power-of-two textures on opengl es 2.0 samplerState = SamplerState.New(GraphicsDevice, new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Clamp)); // Add Effect rendering to the end of the pipeline var scene = SceneSystem.SceneInstance.Scene; var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor); renderer = new SceneDelegateRenderer(RenderQuad); compositor.Master.Renderers.Add(renderer); }
/// <summary> /// Draw a sprite using a sprite batch. /// </summary> /// <param name="sprite">The sprite</param> /// <param name="spriteBatch">The sprite batch used to draw the sprite.</param> /// <param name="position">The position to which draw the sprite</param> /// <param name="color">The color to use to draw the sprite</param> /// <param name="rotation">The rotation to apply on the sprite</param> /// <param name="scales">The scale factors to apply on the sprite</param> /// <param name="depthLayer">The depth layer to which draw the sprite</param> /// <param name="spriteEffects">The sprite effect to apply on the sprite</param> /// <remarks>This function must be called between the <see cref="SpriteBatch.Begin(SiliconStudio.Xenko.Graphics.SpriteSortMode,SiliconStudio.Xenko.Graphics.Effect)"/> /// and <see cref="SpriteBatch.End()"/> calls of the provided <paramref name="spriteBatch"/></remarks> /// <exception cref="ArgumentException">The provided frame index is not valid.</exception> /// <exception cref="ArgumentOutOfRangeException">The provided spriteBatch is null</exception> public static void Draw(this Sprite sprite, SpriteBatch spriteBatch, Vector2 position, Color color, Vector2 scales, float rotation = 0f, float depthLayer = 0, SpriteEffects spriteEffects = SpriteEffects.None) { if (spriteBatch == null) throw new ArgumentNullException("spriteBatch"); if (sprite.Texture == null) return; spriteBatch.Draw(sprite.Texture, position, sprite.Region, color, rotation, sprite.Center, scales, spriteEffects, sprite.Orientation, depthLayer); }
public void DrawSprite(SpriteBatch spriteBatch) { // DrawParallax the first quad spriteBatch.Draw(texture, firstQuadPos + screenCenter, firstQuadRegion, Color.White, 0f, firstQuadOrigin, 1f, SpriteEffects.None, ImageOrientation.AsIs, depth); if (secondQuadRegion.Width > 0) { // DrawParallax the second quad spriteBatch.Draw(texture, secondQuadPos + screenCenter, secondQuadRegion, Color.White, 0f, secondQuadOrigin, 1f, SpriteEffects.None, ImageOrientation.AsIs, depth); } }
/// <summary> /// Initializes a new instance of the <see cref="XenkoRenderer"/> class. /// </summary> /// <param name="graphicsDeviceManager">The graphics device manager.</param> public XenkoRenderer(GraphicsDeviceManager graphicsDeviceManager, EffectSystem effectSystem) : base() { manager = graphicsDeviceManager; this.effectSystem = effectSystem; spriteBatch = new SpriteBatch(manager.GraphicsDevice); clipRectanges = new Stack<Rectangle>(); activeEffects = new Stack<EffectInstance>(); scissorRasterizerStateDescription = RasterizerStates.CullNone; scissorRasterizerStateDescription.ScissorTestEnable = true; // enables the scissor test geometryRasterizerStateDescription = RasterizerStates.CullNone; //geometryRasterizerStateDescription.FillMode = FillMode.Wireframe; geometryPipelineState = new MutablePipelineState(manager.GraphicsDevice); geometryPipelineState.State.DepthStencilState = DepthStencilStates.None; }
protected override async Task LoadContent() { await base.LoadContent(); spriteBatch = new SpriteBatch(GraphicsDevice); font = Asset.Load<SpriteFont>("Font"); wireframeState = RasterizerState.New(GraphicsDevice, new RasterizerStateDescription(CullMode.Back) { FillMode = FillMode.Wireframe }); materials.Add(Asset.Load<Material>("NoTessellation")); materials.Add(Asset.Load<Material>("FlatTessellation")); materials.Add(Asset.Load<Material>("PNTessellation")); materials.Add(Asset.Load<Material>("PNTessellationAE")); materials.Add(Asset.Load<Material>("FlatTessellationDispl")); materials.Add(Asset.Load<Material>("FlatTessellationDisplAE")); materials.Add(Asset.Load<Material>("PNTessellationDisplAE")); var cube = new Entity("Cube") { new ModelComponent(new ProceduralModelDescriptor(new CubeProceduralModel { Size = new Vector3(80), MaterialInstance = { Material = materials[0] } }).GenerateModel(Services)) }; var sphere = new Entity("Sphere") { new ModelComponent(new ProceduralModelDescriptor(new SphereProceduralModel { Radius = 50, Tessellation = 5, MaterialInstance = { Material = materials[0] }} ).GenerateModel(Services)) }; var megalodon = new Entity { new ModelComponent { Model = Asset.Load<Model>("megalodon Model") } }; megalodon.Transform.Position= new Vector3(0, -30f, -10f); var knight = new Entity { new ModelComponent { Model = Asset.Load<Model>("knight Model") } }; knight.Transform.RotationEulerXYZ = new Vector3(-MathUtil.Pi / 2, MathUtil.Pi / 4, 0); knight.Transform.Position = new Vector3(0, -50f, 20f); knight.Transform.Scale= new Vector3(0.6f); entities.Add(sphere); entities.Add(cube); entities.Add(megalodon); entities.Add(knight); camera = new TestCamera(); CameraComponent = camera.Camera; Script.Add(camera); LightingKeys.EnableFixedAmbientLight(GraphicsDevice.Parameters, true); GraphicsDevice.Parameters.Set(EnvironmentLightKeys.GetParameterKey(LightSimpleAmbientKeys.AmbientLight, 0), (Color3)Color.White); ChangeModel(0); SetWireframe(true); camera.Position = new Vector3(25, 45, 80); camera.SetTarget(currentEntity, true); }
protected override async Task LoadContent() { await base.LoadContent(); spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("Font"); wireframeState = new RasterizerStateDescription(CullMode.Back) { FillMode = FillMode.Wireframe }; materials.Add(Content.Load<Material>("NoTessellation")); materials.Add(Content.Load<Material>("FlatTessellation")); materials.Add(Content.Load<Material>("PNTessellation")); materials.Add(Content.Load<Material>("PNTessellationAE")); materials.Add(Content.Load<Material>("FlatTessellationDispl")); materials.Add(Content.Load<Material>("FlatTessellationDisplAE")); materials.Add(Content.Load<Material>("PNTessellationDisplAE")); RenderContext.GetShared(Services).RendererInitialized += RendererInitialized; var cube = new Entity("Cube") { new ModelComponent(new ProceduralModelDescriptor(new CubeProceduralModel { Size = new Vector3(80), MaterialInstance = { Material = materials[0] } }).GenerateModel(Services)) }; var sphere = new Entity("Sphere") { new ModelComponent(new ProceduralModelDescriptor(new SphereProceduralModel { Radius = 50, Tessellation = 5, MaterialInstance = { Material = materials[0] }} ).GenerateModel(Services)) }; var megalodon = new Entity { new ModelComponent { Model = Content.Load<Model>("megalodon Model") } }; megalodon.Transform.Position= new Vector3(0, -30f, -10f); var knight = new Entity { new ModelComponent { Model = Content.Load<Model>("knight Model") } }; knight.Transform.RotationEulerXYZ = new Vector3(-MathUtil.Pi / 2, MathUtil.Pi / 4, 0); knight.Transform.Position = new Vector3(0, -50f, 20f); knight.Transform.Scale= new Vector3(0.6f); entities.Add(sphere); entities.Add(cube); entities.Add(megalodon); entities.Add(knight); camera = new TestCamera(); CameraComponent = camera.Camera; Script.Add(camera); // TODO GRAPHICS REFACTOR ChangeModel(0); camera.Position = new Vector3(25, 45, 80); camera.SetTarget(currentEntity, true); }
public override void Start() { // create the ball sprite. var virtualResolution = new Vector3(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height, 1); spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = virtualResolution }; // Initialize ball's state related variables. resolution = new Vector2(virtualResolution.X, virtualResolution.Y); ballHalfSize = new Vector2(SphereWidth / 2f, SphereHeight / 2f); if (!IsLiveReloading) { ballPosition = resolution / 2; ballSpeed = new Vector2(600, -400); } // Add Graphics Layer var scene = SceneSystem.SceneInstance.Scene; var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor); compositor.Master.Renderers.Add(delegateRenderer = new SceneDelegateRenderer(RenderSpheres)); }
protected override async Task LoadContent() { await base.LoadContent(); font = Content.Load<SpriteFont>("Font"); teapot = Content.Load<Model>("Teapot"); batch = new SpriteBatch(GraphicsDevice); BuildUI(); spriteComponent = new SpriteComponent { SpriteProvider = new SpriteFromSheet { Sheet = Content.Load<SpriteSheet>("SpriteSheet") } }; modelComponent = new ModelComponent { Model = teapot }; modelComponent2 = new ModelComponent { Model = teapot }; modelComponent3 = new ModelComponent { Model = teapot }; entity = new Entity { spriteComponent, modelComponent }; entity2 = new Entity { modelComponent2 }; entity3 = new Entity { modelComponent3 }; SceneSystem.SceneInstance.Scene.Entities.Add(entity); SceneSystem.SceneInstance.Scene.Entities.Add(entity2); SceneSystem.SceneInstance.Scene.Entities.Add(entity3); if (Input.Accelerometer.IsSupported) Input.Accelerometer.IsEnabled = true; if (Input.Compass.IsSupported) Input.Compass.IsEnabled = true; if (Input.Gyroscope.IsSupported) Input.Gyroscope.IsEnabled = true; if (Input.UserAcceleration.IsSupported) Input.UserAcceleration.IsEnabled = true; if (Input.Gravity.IsSupported) Input.Gravity.IsEnabled = true; if (Input.Orientation.IsSupported) Input.Orientation.IsEnabled = true; ChangeScene(0); }
// Complete the graphic pipeline, initialize texture data public override void Start() { // create the sprite batch used in our custom rendering function spriteBatch = new SpriteBatch(GraphicsDevice); // insert the custom renderer in between the 2 camera renderer. var scene = SceneSystem.SceneInstance.Scene; var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor); compositor.Master.Renderers.Insert(2, new SceneDelegateRenderer(RenderTexture)); // Create and initialize the dynamic texture renderTexture = Texture.New2D(GraphicsDevice, RenderTextureSize, RenderTextureSize, 1, PixelFormat.R8G8B8A8_UNorm_SRgb, usage: GraphicsResourceUsage.Dynamic); // Setup initial data in "SymmetricDefaultShape" to the texture for (var i = 0; i < SymmetricDefaultShape.Length; i += 2) { TogglePixel(SymmetricDefaultShape[i], SymmetricDefaultShape[i + 1]); if (SymmetricDefaultShape[i] != (RenderTextureSize - 1) - SymmetricDefaultShape[i]) TogglePixel((RenderTextureSize - 1) - SymmetricDefaultShape[i], SymmetricDefaultShape[i + 1]); } renderTexture.SetData(Game.GraphicsContext.CommandList, textureData); }
/// <summary> /// Draw a sprite using a sprite batch and with white color and scale of 1. /// </summary> /// <param name="sprite">The sprite</param> /// <param name="spriteBatch">The sprite batch used to draw the sprite.</param> /// <param name="position">The position to which draw the sprite</param> /// <param name="rotation">The rotation to apply on the sprite</param> /// <param name="depthLayer">The depth layer to which draw the sprite</param> /// <param name="spriteEffects">The sprite effect to apply on the sprite</param> /// <remarks>This function must be called between the <see cref="SpriteBatch.Begin(SiliconStudio.Xenko.Graphics.SpriteSortMode,SiliconStudio.Xenko.Graphics.Effect)"/> /// and <see cref="SpriteBatch.End()"/> calls of the provided <paramref name="spriteBatch"/></remarks> /// <exception cref="ArgumentException">The provided frame index is not valid.</exception> /// <exception cref="ArgumentOutOfRangeException">The provided spriteBatch is null</exception> public static void Draw(this Sprite sprite, SpriteBatch spriteBatch, Vector2 position, float rotation = 0, float depthLayer = 0, SpriteEffects spriteEffects = SpriteEffects.None) { sprite.Draw(spriteBatch, position, Color.White, Vector2.One, rotation, depthLayer, spriteEffects); }
protected override Task LoadContent() { // Load the fonts spriteFont11 = Content.Load<SpriteFont>("Arial"); // load the round texture roundTexture = Content.Load<Texture>("round"); // create the SpriteBatch used to render them spriteBatch = new SpriteBatch(GraphicsDevice); // initialize parameters textHeight = spriteFont11.MeasureString(KeyboardSessionString).Y; screenSize = new Vector2(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height); roundTextureSize = new Vector2(roundTexture.Width, roundTexture.Height); // activate the gesture recognitions Input.ActivatedGestures.Add(new GestureConfigDrag()); Input.ActivatedGestures.Add(new GestureConfigFlick()); Input.ActivatedGestures.Add(new GestureConfigLongPress()); Input.ActivatedGestures.Add(new GestureConfigComposite()); Input.ActivatedGestures.Add(new GestureConfigTap()); // add a task to the task scheduler that will be executed asynchronously Script.AddTask(UpdateInputStates); return Task.FromResult(0); }
public override void Draw(GameTime gameTime) { if (overlayMessages.Count == 0) { return; } //TODO, this is not so nice if (spriteBatch == null) { spriteBatch = new SpriteBatch(Game.GraphicsDevice); } //TODO, this is not so nice if (Font == null) { try { Font = Content.Load<SpriteFont>("XenkoDefaultFont"); } catch (Exception) { Visible = false; return; } } // TODO GRAPHICS REFACTOR where to get command list from? Game.GraphicsContext.CommandList.SetRenderTargetAndViewport(null, Game.GraphicsDevice.Presenter.BackBuffer); spriteBatch.Begin(Game.GraphicsContext, depthStencilState: DepthStencilStates.None); foreach (var msg in overlayMessages) { spriteBatch.DrawString(msg.TextFont ?? Font, msg.Message, msg.Position, msg.TextColor); } spriteBatch.End(); }
/// <summary> /// Draw all text groups with SpriteBatch /// </summary> public override void Start() { // Create the SpriteBatch used to render them spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = new Vector3(virtualResolution, 1000) }; centerVirtualPosition = new Vector2(virtualResolution.X * 0.5f, virtualResolution.Y * 0.5f); screenSize = new Vector2(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height); screenRenderers.Add(DrawIntroductionCategory); screenRenderers.Add(DrawStaticCategory); screenRenderers.Add(DrawDynamicCategory); screenRenderers.Add(DrawStyleCategory); screenRenderers.Add(DrawAliasCategory); screenRenderers.Add(DrawLanguageCategory); screenRenderers.Add(DrawAlignmentCategory); screenRenderers.Add(DrawAnimationCategory); // Add Graphics Layer var scene = SceneSystem.SceneInstance.Scene; var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor); compositor.Master.Renderers.Add(delegateRenderer = new SceneDelegateRenderer(DrawFont)); }