Beispiel #1
0
        private bool Render()
        {
            // Clear the buffer to begin the scene.
            D3D.BeginScene(0.1f, 0f, 0f, 1f);

            // Generate the view matrix based on the camera position.
            Camera.Render();

            // Get the world, view, and projection matrices from camera and d3d objects.
            var viewMatrix       = Camera.ViewMatrix;
            var worldMatrix      = D3D.WorldMatrix;
            var projectionMatrix = D3D.ProjectionMatrix;

            // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            Model.Render(D3D.DeviceContext);

            // Render the model using the color shader.
            if (!ColorShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix))
            {
                return(false);
            }

            // Present the rendered scene to the screen.
            D3D.EndScene();

            return(true);
        }
Beispiel #2
0
        public override void Render(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix)
        {
            int stride = Utilities.SizeOf <VertexDefinition.PositionColor>(); //Gets or sets the stride between vertex elements in the buffer (in bytes).

            deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer, stride, 0));
            deviceContext.InputAssembler.SetIndexBuffer(IndexBuffer, Format.R32_UInt, 0);
            deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            _shader.Render(deviceContext, IndexCount, worldMatrix, viewMatrix, projectionMatrix);
        }
        public bool RenderColorShader(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix)
        {
            // Render the ColoreShader.
            if (!ColorShader.Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix))
            {
                return(false);
            }

            return(true);
        }
        private bool Render()
        {
            D3D.BeginScene(0.1f, 0f, 0f, 1f);

            Camera.Render();
            Model.Render(D3D.DeviceContext);
            if (!ColorShader.Render(D3D.DeviceContext, Model.IndexCount, D3D.WorldMatrix, Camera.ViewMatrix, D3D.ProjectionMatrix))
            {
                return(false);
            }

            D3D.EndScene();
            return(true);
        }
Beispiel #5
0
        private bool RenderGraphics()
        {
            // Clear the scene.
            D3D.BeginScene(0, 0, 0, 1);

            // Generate the view matrix based on the camera's position.
            Camera.Render();

            // Get the world, view, and projection matrices from camera and d3d objects.
            var viewMatrix       = Camera.ViewMatrix;
            var worldMatrix      = D3D.WorldMatrix;
            var projectionMatrix = D3D.ProjectionMatrix;
            var orthoMatrix      = D3D.OrthoMatrix;

            // Render the terrain buffers.
            Terrain.Render(D3D.DeviceContext);

            // Render the model using the color shader.
            if (!ColorShader.Render(D3D.DeviceContext, Terrain.IndexCount, worldMatrix, viewMatrix, projectionMatrix))
            {
                return(false);
            }

            // Turn off the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOff();

            // Turn on the alpha blending before rendering the text.
            D3D.TurnOnAlphaBlending();

            // Render the text string.
            if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix))
            {
                return(false);
            }

            // Turn off the alpha blending before rendering the text.
            D3D.TurnOffAlphaBlending();

            // Turn on the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOn();

            // Present the rendered scene to the screen.
            D3D.EndScene();

            return(true);
        }
        private bool RenderGraphics()
        {
            // Clear the scene.
            D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f);

            // Generate the view matrix based on the camera's position.
            Camera.Render();

            // Get the world, view, projection, and ortho matrices from the camera and Direct3D objects.
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix cameraViewMatrix = Camera.ViewMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;
            Matrix orthoD3DMatrix   = D3D.OrthoMatrix;

            // Render the terrain buffers.
            Terrain.Render(D3D.DeviceContext);

            // Render the model using the color shader.
            if (!ColorShader.Render(D3D.DeviceContext, Terrain.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix))
            {
                return(false);
            }

            // Turn off the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOff();

            // Turn on the alpha blending before rendering the text.
            D3D.TurnOnAlphaBlending();

            // Render the text user interface elements.
            if (!Text.Render(D3D.DeviceContext, FontShader, worldMatrix, orthoD3DMatrix))
            {
                return(false);
            }

            // Turn off alpha blending after rendering the text.
            D3D.TurnOffAlphaBlending();

            // Turn the Z buffer back on now that all 2D rendering has completed.
            D3D.TurnZBufferOn();

            // Present the rendered scene to the screen.
            D3D.EndScene();

            return(true);
        }
        public void Render(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix)
        {
            if (_changed)
            {
                float left   = (float)((ScreenSize.X / 2) * -1) + (float)Position.X;
                float right  = left + (float)Size.X;
                float top    = (float)(ScreenSize.Y / 2) - (float)Position.Y;
                float bottom = top - (float)Size.Y;

                _vertices[0] = new VertexDefinition.PositionColor {
                    position = new Vector3(left, top, Depth), color = _color
                };
                _vertices[1] = new VertexDefinition.PositionColor {
                    position = new Vector3(right, bottom, Depth), color = _color
                };
                _vertices[2] = new VertexDefinition.PositionColor {
                    position = new Vector3(left, bottom, Depth), color = _color
                };
                _vertices[3] = new VertexDefinition.PositionColor {
                    position = new Vector3(right, top, Depth), color = _color
                };

                DataStream mappedResource;
                deviceContext.MapSubresource(_vertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
                mappedResource.WriteRange(_vertices);
                deviceContext.UnmapSubresource(_vertexBuffer, 0);
                _changed = false;
            }

            // Set vertex buffer stride and offset.
            int stride = Utilities.SizeOf <VertexDefinition.PositionColor>(); //Gets or sets the stride between vertex elements in the buffer (in bytes).

            deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vertexBuffer, stride, 0));
            deviceContext.InputAssembler.SetIndexBuffer(_indexBuffer, Format.R32_UInt, 0);
            deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            _shader.Render(deviceContext, _indexCount, worldMatrix, viewMatrix, projectionMatrix);
        }