protected override void OnRender(RenderContext context) { context.Scene = Scene; context.CameraNode = CameraNode; var graphicsDevice = GraphicsService.GraphicsDevice; // Clear background. graphicsDevice.Clear(new Color(60, 60, 60)); // Frustum Culling: Get all scene nodes that intersect the camera frustum. var query = Scene.Query<CameraFrustumQuery>(context.CameraNode, context); // Set render state. graphicsDevice.DepthStencilState = DepthStencilState.Default; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; graphicsDevice.BlendState = BlendState.Opaque; graphicsDevice.SamplerStates[0] = SamplerState.AnisotropicWrap; // Use a MeshRenderer to render all MeshNodes that are in the camera frustum. // We use the shader effects and effect parameters for the render pass named // "Default" (see the material (.drmat) files of the assets). context.RenderPass = "******"; _meshRenderer.Render(query.SceneNodes, context); context.RenderPass = null; // Render debug info. _debugRenderer.Render(context); context.CameraNode = null; context.Scene = null; }
protected override void OnProcess(RenderContext context) { // Render Scene into DistortionTexture. bool doDistortion = RenderDistortionTexture(context); // Execute post-processing effect. var graphicsDevice = GraphicsService.GraphicsDevice; graphicsDevice.SetRenderTarget(context.RenderTarget); graphicsDevice.Viewport = context.Viewport; _viewportSizeParameter.SetValue(new Vector2(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height)); _sourceTextureParameter.SetValue(context.SourceTexture); if (doDistortion) { _strengthParameter.SetValue(Strength); _distortionTextureParameter.SetValue(DistortionTexture); } else { _strengthParameter.SetValue(0.0f); _distortionTextureParameter.SetValue((Texture2D)null); } _effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.DrawFullScreenQuad(); }
protected override void OnRender(RenderContext context) { var graphicsDevice = GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.White); if (_animatableString.Value != null) { // Draw the animated string value. SpriteBatch.Begin(); const float scale = 5; Vector2 size = SpriteFont.MeasureString(_animatableString.Value); Rectangle bounds = graphicsDevice.Viewport.TitleSafeArea; Vector2 position = new Vector2(bounds.Center.X, bounds.Center.Y) - size * scale / 2; SpriteBatch.DrawString( SpriteFont, _animatableString.Value, position, Color.Black, 0, new Vector2(0), new Vector2(scale), SpriteEffects.None, 0); SpriteBatch.End(); } }
protected override void OnRender(RenderContext context) { // Draw text _spriteBatch.Begin(); _spriteBatch.DrawString(_spriteFont, _text, new Vector2(10, 10), Color.LightGreen, 0, new Vector2(), 1.0f, SpriteEffects.None, 0.5f); _spriteBatch.End(); }
// Render() draws a list of scene nodes. public override void Render(IList<SceneNode> nodes, RenderContext context, RenderOrder order) { // For simplicity we ignore the 'order' parameter and do not sort the TextNodes // by distance. var graphicsDevice = context.GraphicsService.GraphicsDevice; var cameraNode = context.CameraNode; if (cameraNode == null) return; // No camera set. Matrix view = (Matrix)cameraNode.View; Matrix projection = cameraNode.Camera.Projection; var viewport = graphicsDevice.Viewport; // Use the SpriteBatch for rendering text. _spriteBatch.Begin(); for (int i = 0; i < nodes.Count; i++) { var node = nodes[i] as TextNode; if (node != null) { // Draw text centered at position of TextNode. Vector3 positionWorld = (Vector3)node.PoseWorld.Position; Vector3 positionScreen = viewport.Project(positionWorld, projection, view, Matrix.Identity); Vector2 position2D = new Vector2(positionScreen.X, positionScreen.Y); Vector2 size = _spriteFont.MeasureString(node.Text); _spriteBatch.DrawString(_spriteFont, node.Text, position2D - size / 2, node.Color); } } _spriteBatch.End(); }
// Renders the content of the first screen. private void RenderScreen1(RenderContext context) { var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.DarkBlue); _spriteBatch.Begin(); _spriteBatch.DrawString(_spriteFont, "This is the first screen.", new Vector2(50, 80), Color.White); _spriteBatch.End(); }
protected override void OnRender(RenderContext context) { GraphicsService.GraphicsDevice.Clear(Color.White); // Draw the sprite centered at the animated position. Vector2 position = _animatablePosition.Value - new Vector2(Logo.Width, Logo.Height) / 2.0f; SpriteBatch.Begin(); SpriteBatch.Draw(Logo, position, Color.Gold); SpriteBatch.End(); }
protected override EffectTechnique OnGetTechnique(Effect effect, RenderContext context) { _passIndex = 0; _actualPassCount = 0; // Get the repetition number for the first pass. _desiredPassCount = GetPassRepetitionCount(context, 0); // We only use the first technique of an effect. Other techniques are ignored. return effect.Techniques[0]; }
protected override void OnRender(RenderContext context) { var graphicsDevice = GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.White); // Draw the sprite using the animated value for the x position. Rectangle bounds = graphicsDevice.Viewport.TitleSafeArea; Vector2 position = new Vector2((float)_animatableDouble.Value, bounds.Center.Y) - new Vector2(Logo.Width, Logo.Height) / 2.0f; SpriteBatch.Begin(); SpriteBatch.Draw(Logo, position, Color.Red); SpriteBatch.End(); }
// Renders the content of the second screen. private void RenderScreen2(RenderContext context) { var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.CornflowerBlue); _spriteBatch.Begin(); // Render the content of the first screen, which is provided in the render context. _spriteBatch.Draw(context.SourceTexture, new Rectangle(200, 200, 600, 400), Color.White); _spriteBatch.DrawString(_spriteFont, "This is the second screen.", new Vector2(50, 80), Color.White); _spriteBatch.End(); }
/// <inheritdoc/> public void Set(SceneNode referenceNode, IList<SceneNode> nodes, RenderContext context) { Reset(); ReferenceNode = referenceNode; int numberOfNodes = nodes.Count; for (int i = 0; i < numberOfNodes; i++) { var node = nodes[i]; Debug.Assert(node.ActualIsEnabled, "Scene query contains disabled nodes."); AddNode(node); } }
public void Set(SceneNode referenceNode, IList<SceneNode> nodes, RenderContext context) { Reset(); ReferenceNode = referenceNode; int numberOfNodes = nodes.Count; for (int i = 0; i < numberOfNodes; i++) { var node = nodes[i]; if ((WboitFlags)node.UserFlags == WboitFlags.Transparent) TransparentNodes.Add(node); else SceneNodes.Add(node); } }
protected override bool OnNextPass(EffectTechnique technique, RenderContext context, ref int index, out EffectPass pass) { int numberOfPasses = technique.Passes.Count; // Progress to next pass when the desired number of repetitions were performed. // (Note: We use a while statement and not an if statement, because the desired // number of repetitions returned by GetPassRepetitionCount() could theoretically // be 0.) while (_actualPassCount >= _desiredPassCount) { // Finished with current pass. Progress to next pass. _passIndex++; if (_passIndex >= numberOfPasses) { // Finished: All effect passes have been applied. context.PassIndex = -1; pass = null; return false; } _actualPassCount = 0; _desiredPassCount = GetPassRepetitionCount(context, _passIndex); } pass = technique.Passes[_passIndex]; // In the parameter index and context.PassIndex, we store the total number // of executed passes. context.PassIndex = index; index++; _actualPassCount++; if (index == numberOfPasses - 1 && string.Equals(pass.Name, "Restore", StringComparison.OrdinalIgnoreCase)) { // A last effect pass may be used to restore the default render states without // drawing anything. The effect pass needs to be called "Restore". pass.Apply(); // Finished: All effect passes have been applied. context.PassIndex = -1; pass = null; return false; } return true; }
private void Render(RenderContext context) { // Here we can render the content of the graphics screen. This method is only // called if the screen is visible. Unlike the Update callback method, this // callback method might be called several times per frame in complex // applications, like game editors with multiple views. - But in most // applications this method is called once per frame. var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.CornflowerBlue); // Draw text. _spriteBatch.Begin(); _spriteBatch.DrawString(_spriteFont, "Hello World!", new Vector2(200, 200), Color.White); _spriteBatch.End(); }
private void Render(RenderContext context) { var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.CornflowerBlue); graphicsDevice.DepthStencilState = DepthStencilState.Default; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; graphicsDevice.BlendState = BlendState.Opaque; // Use the view and projection info from the camera node controlled by the // Player game component. _effect.View = (Matrix)_cameraObject.CameraNode.View; _effect.Projection = _cameraObject.CameraNode.Camera.Projection; _effect.World = Matrix.CreateTranslation(-1, 1, 0); _effect.DiffuseColor = new Vector3(1, 0, 0); _effect.LightingEnabled = true; _effect.CurrentTechnique.Passes[0].Apply(); // Render the submesh using the currently active shader. _torus.Draw(); _effect.World = Matrix.CreateTranslation(1, 1, 0); _effect.DiffuseColor = new Vector3(0, 1, 0); _effect.CurrentTechnique.Passes[0].Apply(); _teapot.Draw(); _effect.World = Matrix.CreateScale(0.5f, 1, 0.5f) * Matrix.CreateTranslation(-2, 1, -2); _effect.DiffuseColor = new Vector3(0, 0, 1); _effect.CurrentTechnique.Passes[0].Apply(); _sphere.Draw(); _effect.World = Matrix.CreateTranslation(0, 1, -2); _effect.DiffuseColor = new Vector3(1, 1, 0); _effect.CurrentTechnique.Passes[0].Apply(); _box.Draw(); _effect.World = Matrix.CreateTranslation(2, 1, -2); _effect.DiffuseColor = new Vector3(1, 0, 1); _effect.LightingEnabled = false; _effect.CurrentTechnique.Passes[0].Apply(); _cone.Draw(); }
protected override void OnRender(RenderContext context) { _frameCount++; // At regular intervals reset the debug output and write the current FPS. if (_stopwatch.Elapsed.TotalSeconds > 1) { _debugRenderer.Clear(); _debugRenderer.DrawText("FPS: " + _frameCount / (float)_stopwatch.Elapsed.TotalSeconds); _stopwatch.Restart(); _frameCount = 0; } context.Scene = Scene; context.CameraNode = CameraNode; var graphicsDevice = GraphicsService.GraphicsDevice; // Clear background. graphicsDevice.Clear(Color.Transparent); // Frustum culling: Get all scene nodes that intersect the camera frustum. var query = Scene.Query<CameraFrustumQuery>(context.CameraNode, context); // Set render state. graphicsDevice.DepthStencilState = DepthStencilState.Default; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; graphicsDevice.BlendState = BlendState.Opaque; graphicsDevice.SamplerStates[0] = SamplerState.AnisotropicWrap; // Use a MeshRenderer to render all MeshNodes that are in the camera frustum. // We use the shader effects and effect parameters for the render pass named // "Default" (see the material (.drmat files) of the assets). context.RenderPass = "******"; _meshRenderer.Render(query.SceneNodes, context); context.RenderPass = null; // Render debug info. _debugRenderer.Render(context); context.CameraNode = null; context.Scene = null; }
protected override void OnRender(RenderContext context) { // Update the projection matrix. (The user can resize the windows and the // aspect ratio can change.) _basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), GraphicsService.GraphicsDevice.Viewport.AspectRatio, 1.0f, 100.0f); // No backface culling. GraphicsService.GraphicsDevice.RasterizerState = RasterizerState.CullNone; foreach (EffectPass pass in _basicEffect.CurrentTechnique.Passes) { pass.Apply(); GraphicsService.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, _vertexList, 0, 1); } }
private void Render(RenderContext context) { var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.CornflowerBlue); graphicsDevice.DepthStencilState = DepthStencilState.Default; graphicsDevice.BlendState = BlendState.Opaque; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; graphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; // Draw XNA model (as usual in XNA) with the view and projection matrix of // the DigitalRune CameraNode. var world = Matrix.CreateFromYawPitchRoll(0.5f, 0.3f, 0) * Matrix.CreateTranslation(0, 1.5f, 0); CameraNode cameraNode = _cameraObject.CameraNode; Matrix view = (Matrix)cameraNode.View; Matrix projection = cameraNode.Camera.Projection; _model.Draw(world, view, projection); }
private void Render(RenderContext renderContext) { // Visualize the state of the input commands by drawing a simple progress bar. _spriteBatch.Begin(); // "Hold (A)" DrawRightAlignedText(new Vector2(400, 100), _textFont, "Hold ", 1.0f, _buttonFont, "'", 0.5f); DrawProgressBar(new Rectangle(405, 100 - 16, 120, 32), _buttonHoldProgress); // "Rapidly tap (A)" DrawRightAlignedText(new Vector2(400, 140), _textFont, "Rapidly tap ", 1.0f, _buttonFont, "'", 0.5f); DrawProgressBar(new Rectangle(405, 140 - 16, 120, 32), _buttonTapProgress); // "Press sequence (A)(B)(A)(B) DrawRightAlignedText(new Vector2(400, 180), _textFont, "Press sequence ", 1.0f, _buttonFont, "')')", 0.5f); DrawProgressBar(new Rectangle(405, 180 - 16, 120, 32), _buttonSequenceProgress); _spriteBatch.End(); }
public void Set(SceneNode referenceNode, IList<SceneNode> nodes, RenderContext context) { Reset(); ReferenceNode = referenceNode; for (int i = 0; i < nodes.Count; i++) { #if !XBOX360 if (nodes[i] is TerrainNode) TerrainNodes.Add(nodes[i]); #endif if (nodes[i] is CloudLayerNode) CloudLayerNodes.Add(nodes[i]); else if (nodes[i] is WaterNode) WaterNodes.Add(nodes[i]); else if (nodes[i] is SceneCaptureNode) SceneCaptureNodes.Add(nodes[i]); else if (nodes[i] is PlanarReflectionNode) PlanarReflectionNodes.Add(nodes[i]); } }
protected override void OnProcess(RenderContext context) { var graphicsDevice = GraphicsService.GraphicsDevice; // Set the render target and also apply the current viewport. graphicsDevice.SetRenderTarget(context.RenderTarget); graphicsDevice.Viewport = context.Viewport; // Choose the effect technique. // (Since the current NegativeFilter has only 1 technique we don't need to do anything.) // _effect.CurrentTechnique = _effect.Techniques[0]; // Update the required effect parameters. _strengthParameter.SetValue(Strength); _textureParameter.SetValue(context.SourceTexture); _viewportSizeParameter.SetValue(new Vector2(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height)); // Apply the effect and do the post-processing. _effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.DrawFullScreenQuad(); }
private void Render(RenderContext context) { // Set render context info. context.CameraNode = _cameraObject.CameraNode; context.Scene = _scene; var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.CornflowerBlue); // Frustum culling: Get all scene nodes which overlap the view frustum. var query = _scene.Query<CameraFrustumQuery>(context.CameraNode, context); // Render all TextNodes that are in the camera frustum. _textRenderer.Render(query.SceneNodes, context); // Draw debug info. _debugRenderer.Render(context); // Clean up. context.Scene = null; context.CameraNode = null; }
protected override void OnRender(RenderContext context) { context.CameraNode = ActiveCamera; var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.CornflowerBlue); graphicsDevice.DepthStencilState = DepthStencilState.Default; graphicsDevice.BlendState = BlendState.Opaque; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; context.RenderPass = "******"; context.Scene = Scene; SceneQuery SceneQuery = Scene.Query<SceneQuery>(ActiveCamera); _opaqueSceneRenderer.Render(SceneQuery.RenderableNodes, context); //DebugRenderer.Render(context); context.RenderPass = null; context.CameraNode = null; }
private void Render(RenderContext context) { context.CameraNode = _cameraObject.CameraNode; var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.White); // Find all objects within camera frustum. var query = Scene.Query<CameraFrustumQuery>(_cameraObject.CameraNode, context); // Draw figure nodes. graphicsDevice.DepthStencilState = DepthStencilState.DepthRead; graphicsDevice.BlendState = BlendState.AlphaBlend; FigureRenderer.Render(query.SceneNodes, context, RenderOrder.BackToFront); UIScreen.Draw(context.DeltaTime); // Draw debug information. DebugRenderer.Render(context); context.CameraNode = null; }
private void Render(RenderContext context) { // Set render context info. context.CameraNode = _cameraObject.CameraNode; context.Scene = _scene; var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.CornflowerBlue); graphicsDevice.DepthStencilState = DepthStencilState.Default; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; graphicsDevice.BlendState = BlendState.Opaque; // Frustum culling: Get all scene nodes which overlap the view frustum. var query = _scene.Query<CameraFrustumQuery>(context.CameraNode, context); // Render all meshes that are in the camera frustum. context.RenderPass = "******"; _meshRenderer.Render(query.SceneNodes, context); _debugRenderer.Render(context); // Clean up. context.RenderPass = null; context.Scene = null; context.CameraNode = null; }
private void Render(RenderContext context) { // Set render context info. context.CameraNode = _cameraObject.CameraNode; context.Scene = _scene; // Frustum culling: Get all scene nodes which overlap the view frustum. var query = _scene.Query<CameraFrustumQuery>(context.CameraNode, context); // Render meshes. var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.CornflowerBlue); graphicsDevice.DepthStencilState = DepthStencilState.Default; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; graphicsDevice.BlendState = BlendState.Opaque; context.RenderPass = "******"; _meshRenderer.Render(query.SceneNodes, context); context.RenderPass = null; // Render billboards using alpha blending. graphicsDevice.DepthStencilState = DepthStencilState.DepthRead; graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; _billboardRenderer.Render(query.SceneNodes, context, RenderOrder.BackToFront); _debugRenderer.Render(context); // Clean up. context.Scene = null; context.CameraNode = null; }
// CanRender() checks whether a given scene node can be rendered with this // scene node renderer. public override bool CanRender(SceneNode node, RenderContext context) { return node is TextNode; }
protected override void OnRender(RenderContext context) { // Set render context info. context.CameraNode = _cameraObject.CameraNode; // Clear screen. var graphicsDevice = context.GraphicsService.GraphicsDevice; graphicsDevice.Clear(Color.CornflowerBlue); // Draw avatar. if (_avatarPose != null) { _avatarRenderer.World = _pose; _avatarRenderer.View = (Matrix)_cameraObject.CameraNode.View; _avatarRenderer.Projection = _cameraObject.CameraNode.Camera.Projection; _avatarRenderer.Draw(_avatarPose); } // Draw reticle. var viewport = context.Viewport; SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); SpriteBatch.Draw( Reticle, new Vector2(viewport.Width / 2 - Reticle.Width / 2, viewport.Height / 2 - Reticle.Height / 2), Color.Black); SpriteBatch.End(); _debugRenderer.Render(context); // Clean up. context.CameraNode = null; }
// Render callback of the the graphics screen which renders the GUI. private void Render(RenderContext context) { var cameraNode = _cameraObject.CameraNode; Matrix44F viewProjection = cameraNode.Camera.Projection * cameraNode.View; var viewport = GraphicsService.GraphicsDevice.Viewport; // Update x/y screen position of progress bars. foreach (var pair in _objects) { var dynamicObject = pair.First; var rigidBody = dynamicObject.RigidBody; // Get a value which is proportional to the object radius. float radius = rigidBody.Shape.GetAabb().Extent.Length * 0.35f; // Position the progress bar above the object. Vector3F positionWorld = rigidBody.Pose.Position + new Vector3F(0, radius, 0); // Convert world space position to screen space. Vector3F positionScreen = viewport.Project(positionWorld, viewProjection); var progressBar = pair.Second; progressBar.X = positionScreen.X; progressBar.Y = positionScreen.Y; progressBar.SetValue(_zPropertyId, positionScreen.Z); // Hide progress bars that are too close or too far away. progressBar.IsVisible = positionScreen.Z >= 0 && positionScreen.Z <= 1; } // The default UI renderer renders UIScreen children from first to last. To get a correct // z order, we need to sort the UIScreen children by their z value. // Z values don't change often. Therefore, we can use a primitive sort algorithm. bool continueSorting = true; while (continueSorting) { continueSorting = false; for (int i = 0; i < _uiScreen.Children.Count - 1; i++) { if (_uiScreen.Children[i].GetValue<float>(_zPropertyId) < _uiScreen.Children[i + 1].GetValue<float>(_zPropertyId)) { _uiScreen.Children.Move(i, i + 1); continueSorting = true; } } } _uiScreen.Draw(context.DeltaTime); }
private void Render(RenderContext context) { // Draw the UI screen. This method does nothing if _uiScreen.IsVisible is false. _uiScreen.Draw(context.DeltaTime); }