예제 #1
0
        public void Render(Microsoft.Xna.Framework.Graphics.Color XColor)
        {
            //myTexture = Texture2D.FromFile(device, fullPath);
            //textureScreenBuffer.GenerateMipMaps(TextureFilter.Point);

            //device.Clear(Microsoft.Xna.Framework.Graphics.Color.CornflowerBlue);
            device.Clear(XColor);

            // FOR BLOCKY PIXELS, USE THIS CODE
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
            device.SamplerStates[0].MagFilter = TextureFilter.Point;

            // FOR ANTI-ALIASED PIXELS, USE THIS CODE
            //spriteBatch.Begin();

            spriteBatch.Draw(textureScreenBuffer0, new Microsoft.Xna.Framework.Rectangle(0, 0, vdb.pnlNT2000.Width, vdb.pnlNT2000.Height), Microsoft.Xna.Framework.Graphics.Color.White);
            spriteBatch.Draw(textureScreenBuffer1, new Microsoft.Xna.Framework.Rectangle(512, 0, vdb.pnlNT2000.Width, vdb.pnlNT2000.Height), Microsoft.Xna.Framework.Graphics.Color.White);
            spriteBatch.Draw(textureScreenBuffer2, new Microsoft.Xna.Framework.Rectangle(0, 480, vdb.pnlNT2000.Width, vdb.pnlNT2000.Height), Microsoft.Xna.Framework.Graphics.Color.White);
            spriteBatch.Draw(textureScreenBuffer3, new Microsoft.Xna.Framework.Rectangle(512, 480, vdb.pnlNT2000.Width, vdb.pnlNT2000.Height), Microsoft.Xna.Framework.Graphics.Color.White);

            spriteBatch.End();

            //base.Update();
            device.Present();
        }
        private void DrawTriangleBuffer()
        {
            if (polygonCount * 3 > vertices.Length)
            {
                ResizeBuffers();
            }

            int vertexIndex = 0;

            for (int i = 0; i < polygonCount; i++)
            {
                Triangle polygon = triangleBuffer[i];
                var      color   = new Microsoft.Xna.Framework.Color(
                    polygon.Color.R,
                    polygon.Color.G,
                    polygon.Color.B);

                vertices[vertexIndex + 0] = new VertexPositionColor(
                    new Microsoft.Xna.Framework.Vector3(polygon.A.X, polygon.A.Y, polygon.A.Z), color);
                vertices[vertexIndex + 1] = new VertexPositionColor(
                    new Microsoft.Xna.Framework.Vector3(polygon.B.X, polygon.B.Y, polygon.B.Z), color);
                vertices[vertexIndex + 2] = new VertexPositionColor(
                    new Microsoft.Xna.Framework.Vector3(polygon.C.X, polygon.C.Y, polygon.C.Z), color);

                vertexIndex += 3;
            }

            vertexBuffer.SetData(vertices);
            device.SetVertexBuffer(vertexBuffer);

            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                if (polygonCount > 0)
                {
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, polygonCount);
                }
            }

            device.SetVertexBuffer(null);
            device.Present();
        }
예제 #3
0
        public void Run()
        {
            using (var form = CreateForm())
            {
                PresentationParameters presentationParameters = CreatePresentationParameters();

                var device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware,
                    form.Handle, presentationParameters);

                Application.Idle +=
                    delegate
                    {
                        device.Clear(Color.Blue);

                        device.Present();

                        Application.DoEvents();
                    };

                Application.Run(form);
            }
        }
        public void Run()
        {
            using (var form = EmptyWindow.CreateForm())
            {
                PresentationParameters presentationParameters = EmptyWindow.CreatePresentationParameters();

                var device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware,
                    form.Handle, presentationParameters);

                Vertex[] vertices = CreateVertices();

                var vertexBuffer = new VertexBuffer(device,
                    typeof(Vertex), vertices.Length, BufferUsage.None);

                vertexBuffer.SetData(vertices, 0, vertices.Length);

                var indices = CreateIndices();
                var indexBuffer = new IndexBuffer(device,
                    sizeof (int) * indices.Length, BufferUsage.None,
                    IndexElementSize.ThirtyTwoBits);
                indexBuffer.SetData(indices);

                VertexDeclaration vertexDeclaration = TriangleWithVertexBuffer.CreateVertexDeclaration(device);

                var basicEffect = new BasicEffect(device, new EffectPool())
                {
                    LightingEnabled = false,
                    TextureEnabled = false,
                    VertexColorEnabled = true
                };

                Application.Idle +=
                    delegate
                    {
                        device.Clear(Color.Blue);

                        device.VertexDeclaration = vertexDeclaration;
                        device.Vertices[0].SetSource(vertexBuffer, 0, 24);
                        device.Indices = indexBuffer;
                        device.RenderState.CullMode = CullMode.None;

                        basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView(
                            (float)(System.Math.PI / 3), 800f / 600.0f, 0.01f, 100f);
                        basicEffect.View = Matrix.CreateLookAt(
                            new Vector3(0, 0, -3), new Vector3(), new Vector3(0, 1, 0));
                        basicEffect.World = Matrix.Identity;

                        basicEffect.Begin();
                        foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
                        {
                            pass.Begin();

                            device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                0, 0, vertices.Length, 0, 2);

                            pass.End();
                        }

                        basicEffect.End();

                        device.Present();

                        Application.DoEvents();
                    };

                Application.Run(form);
            }
        }
        private void DrawRightEye(GameTime time, Vector3 eyePosition, RenderModes mode, GraphicsDevice device,
                                  SpriteBatch sb)
        {
            switch (mode)
            {
                case RenderModes.StereoCrossConverged:
                    device.SetRenderTarget(0, (_takeScreenshot ? _screenshotTargetRight : _rightEyeRender));
                    break;
                case RenderModes.Stereo:
                    // Draw on the extra created window
                    device.Present(_stereoRightHandle);
                    break;
            }

            device.Clear(ClearColor);

            // Setup camera for right eye
            // Translate look at direction to new eye position
            const float focusDistance = 10.0f;
            Vector3 lookAtVector = Vector3.Normalize(Camera.LookAt - Camera.Position);
            Camera.LookAt = Camera.Position + focusDistance*lookAtVector;
            Camera.Position = eyePosition;
            Camera.UpdateMatrices();

            _basicEffect.View = Camera.View; 
            base.Draw(time);

            // Print FPS
            if (ShowFPS)
            {
                string fpsText = "FPS: " + _fpsUtil.Value;
                PrintInfo(sb, new Vector2(0.9f*_screenWidth, 0), fpsText);
            }
        }
 public override void Present()
 {
     //TODO: Need to add checks to use the largest backbuffer, and only draw a portion of it to the window handle (refer to XNA Winforms tutorial)
     //for when we have multiple XNA swap chains.
     _graphicsDevice.Present(null, null, _windowHandle);
 }
예제 #7
0
        public void Create(bool fullscreen, int width, int height, bool audio)
        {
            GraphicsDevice Device;
            Window = new Form();
            Window.ClientSize = new System.Drawing.Size(width, height);

            Window.Show();

            //GraphicsAdapter.DefaultAdapter.
            PresentationParameters param=new PresentationParameters();
            param.BackBufferCount=1;
            //param.BackBufferFormat=SurfaceFormat.Rgba32;
            param.BackBufferHeight=height;
            param.BackBufferWidth=width;
            //param.FullScreenRefreshRateInHz=60;
            param.IsFullScreen=fullscreen;
            param.PresentFlag=PresentFlag.None;
            param.SwapEffect=fullscreen?SwapEffect.Flip:SwapEffect.Discard;
            param.PresentationInterval=PresentInterval.One;
            param.AutoDepthStencilFormat = DepthFormat.Depth16;
            param.BackBufferFormat = SurfaceFormat.Bgr32;
            param.EnableAutoDepthStencil = true;
            param.PresentationInterval = PresentInterval.Immediate;

            try
            {
                Device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, Window.Handle, CreateOptions.HardwareVertexProcessing, param);
            }
            catch (InvalidCallException e)
            {
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine(e.ErrorCode);
                throw e;
            }

            Device.Clear(new Color(0, 0, 0, 1));
            Device.Present();

            renderer = new XnaRenderer(Device);
        }