Example #1
0
        /// <summary>
        /// Render the terrain
        /// </summary>
        /// <param name="device"></param>
        /// <param name="world"></param>
        public override void Draw(GraphicsDevice device, WorldState world)
        {
            world._3D.ApplyCamera(Effect, this);
            //device.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
            //device.SamplerStates[0].AddressV = TextureAddressMode.Wrap;

            device.SetVertexBuffer(VertexBuffer);
            device.Indices = IndexBuffer;

            //device.RasterizerState.CullMode = CullMode.None;
            foreach (var pass in Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, GeomLength, 0, NumPrimitives);
            }

            device.SetVertexBuffer(GrassVertexBuffer);
            //device.Indices = GrassIndexBuffer;

            foreach (var pass in Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawPrimitives(PrimitiveType.LineList, 0, GrassPrimitives);
                //device.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, GrassPrimitives*2, 0, GrassPrimitives);
            };
        }
Example #2
0
        public static void Draw(Matrix World, Matrix View, Matrix Projection, GraphicsDevice graphics, Matrix world)
        {
            //World, View, Projection
            efeito.World = world;
            efeito.View = View;
            efeito.Projection = Projection;

            //Iluminação
            efeito.VertexColorEnabled = true;

            //Fog
            efeito.FogEnabled = true;
            efeito.FogColor = Vector3.Zero;
            efeito.FogStart = Camera.nearPlane;
            efeito.FogEnd = Camera.farPlaneShort;

            //Load the buffer
            vertexBuffer.SetData(vertexList);

            // Send the vertex buffer to the device
            graphics.SetVertexBuffer(vertexBuffer);

            foreach (EffectPass pass in efeito.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphics.DrawUserPrimitives(PrimitiveType.LineList, vertexList, 0, 3);
            }
        }
Example #3
0
        public void Draw(GraphicsDevice device, BasicEffect effect)
        {
            if (buf == null)
            {
                buf = new VertexBuffer(device, typeof(VertexPositionTexture), 4, BufferUsage.None);
                var vpt = new VertexPositionTexture[4]{
                    new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(0,0)),
                    new VertexPositionTexture(new Vector3(SIZE, 0, 0), new Vector2(1,0)),
                    new VertexPositionTexture(new Vector3(0, 0, SIZE), new Vector2(0,1)),
                    new VertexPositionTexture(new Vector3(SIZE, 0, SIZE), new Vector2(1,1))
                };

                buf.SetData(vpt);
            }

            device.SetVertexBuffer(buf);

            effect.TextureEnabled = true;
            effect.Texture = texture;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }
        }
Example #4
0
 public static void Initilize(GraphicsDevice gd)
 {
     ConstructCube();
     vBuffer = new VertexBuffer(gd, VertexPositionNormalTexture.VertexDeclaration, 36, BufferUsage.WriteOnly);
     vBuffer.SetData(verts);
     gd.SetVertexBuffer(vBuffer);
     ib = new IndexBuffer(gd, IndexElementSize.SixteenBits, 14, BufferUsage.WriteOnly);
     ib.SetData(new short[14]
     {
         0,
         1,
         2,
         3,
         4,
         5,
         6,
         7,
         8,
         9,
         10,
         11,
         12,
         13
     });
     gd.Indices = ib;
     wireframeRaster = new RasterizerState();
     wireframeRaster.FillMode = FillMode.WireFrame;
     wireframeRaster.CullMode = CullMode.None;
     wireframeEfect = new BasicEffect(gd);
     wireframeEfect.Projection = Matrix.CreatePerspectiveFieldOfView(0.7853982f,
         wireframeEfect.GraphicsDevice.Viewport.AspectRatio, 0.01f, 3000f);
 }
Example #5
0
        public override void RenderToDevice(GraphicsDevice device, BasicEffect basicEffet)
        {
            if (basicEffet.LightingEnabled)
            {

                // Build the cube, setting up the _vertices array
                if (isConstructed == false)
                    Construct();

                // Create the shape buffer and dispose of it to prevent out of memory
                using (VertexBuffer buffer = new VertexBuffer(
                    device,
                    VertexPositionNormalTexture.VertexDeclaration,
                    NUM_VERTICES,
                    BufferUsage.WriteOnly))
                {
                    // Load the buffer
                    buffer.SetData(_vertices);
                    // Send the vertex buffer to the device
                    device.SetVertexBuffer(buffer);
                    // Draw the primitives from the vertex buffer to the device as triangles
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, NUM_TRIANGLES);
                }
            }
        }
        public static void Render(BoundingSphere sphere,
                                  GraphicsDevice graphicsDevice,
                                  Matrix view,
                                  Matrix projection,
                                  Color color,
                                  Guid id)
        {
            var subscription = Subscriptions[id];

            graphicsDevice.SetVertexBuffer(subscription.VertexBuffer);
            subscription.BasicEffect.World = Matrix.CreateScale(sphere.Radius)*
                                                   Matrix.CreateTranslation(sphere.Center);
            subscription.BasicEffect.View = view;
            subscription.BasicEffect.Projection = projection;
            subscription.BasicEffect.DiffuseColor = color.ToVector3();

            foreach (var pass in subscription.BasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, 0, SphereResolution);
                graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip,
                                              SphereResolution + 1,
                                              SphereResolution);
                graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip,
                                              (SphereResolution + 1)*2,
                                              SphereResolution);
            }
        }
Example #7
0
        public void Render(GraphicsDevice device, Camera cam)
        {
            if (!Transform.renderer.enabled)
            {
                return;
            }

            device.SetVertexBuffer(VertexBuffer);
            device.Indices = IndexBuffer;

            Effect e = Material.shader.effect;
            Material.shader.ApplyPreRenderSettings(Material, UseVertexColor);
            Material.SetBlendState(device);

            IEffectMatrices ems = e as IEffectMatrices;
            if (ems != null)
            {
                ems.World = Transform.world;
                ems.View = cam.view;
                ems.Projection = cam.projectionMatrix;
            }
            foreach (EffectPass pass in e.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawIndexedPrimitives(
                    PrimitiveType.TriangleList,
                    0,
                    0,
                    VertexBuffer.VertexCount,
                    0,
                    IndexBuffer.IndexCount / 3
                );
            }
            RenderStats.AddDrawCall(batches, VertexBuffer.VertexCount, IndexBuffer.IndexCount / 3);
        }
Example #8
0
        public override void RenderToDevice(GraphicsDevice device, BasicEffect basicEffet)
        {
            if (Visible)
            {
                if (!basicEffet.LightingEnabled)
                {
                    if (isConstructed == false)
                        Construct();

                    using
                        (
                        VertexBuffer buffer = new VertexBuffer(
                        device,
                        VertexPositionColor.VertexDeclaration,
                        points,
                        BufferUsage.WriteOnly)
                      )
                    {
                        // Load the buffer
                        buffer.SetData(pointList);

                        // Send the vertex buffer to the device
                        device.SetVertexBuffer(buffer);
                        device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, pointList, 0, 6, lineListIndices, 0, 3);
                    }
                }
            }
        }
Example #9
0
 void IMesh.Render(GraphicsDevice Device)
 {
     Device.SetVertexBuffer(verticies);
     Device.Indices = indicies;
     Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, verticies.VertexCount,
         0, System.Math.Min(primitiveCount, 65535));
 }
Example #10
0
        /// <summary>
        /// Draws the primitive to the screen.
        /// </summary>
        /// <param Name="device">GPU to draw with.</param>
        public virtual void Render(GraphicsDevice device)
        {
            lock (VertexLock)
            {
            #if MONOGAME_BUILD
                device.SamplerStates[0].Filter = TextureFilter.Point;
                device.SamplerStates[1].Filter = TextureFilter.Point;
                device.SamplerStates[2].Filter = TextureFilter.Point;
                device.SamplerStates[3].Filter = TextureFilter.Point;
                device.SamplerStates[4].Filter = TextureFilter.Point;
            #endif
                if (VertexBuffer == null)
                {
                    return;
                }

                if (Vertices == null || VertexBuffer == null || Vertices.Length < 3 ||  VertexBuffer.IsDisposed || VertexBuffer.VertexCount < 3)
                {
                    return;
                }

                device.SetVertexBuffer(VertexBuffer);

                if (IndexBuffer != null)
                {
                    device.Indices = IndexBuffer;
                    device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, VertexBuffer.VertexCount, 0, IndexBuffer.IndexCount / 3);
                }
                else
                {
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, Vertices.Length/3);
                }
            }
        }
        //Set Buffers Onto GPU
        public void ReadyBuffers(GraphicsDevice GraphicsDevice)
        {
            //Set Vertex Buffer
            GraphicsDevice.SetVertexBuffer(vb);

            //Set Index Buffer
            GraphicsDevice.Indices = ib;
        }
Example #12
0
        /// <summary>
        /// Draws the specified game time.
        /// </summary>
        /// <param name="viewMatrix">The view matrix.</param>
        /// <param name="projectionMatrix">The projection matrix.</param>
        /// <param name="shaderEffect">The shader effect.</param>
        /// <param name="graphicsDevice">The graphics device.</param>
        public void Draw(Matrix viewMatrix, Matrix projectionMatrix, Effect shaderEffect, GraphicsDevice graphicsDevice)
        {
            // Kopie der Sichtmatrix erstellen und die Translation
              // unberücksichtigt lassen, da der Himmel unendlich erscheinen soll
              // unabhängig davon, wo wir uns im Level befinden
              Matrix view = viewMatrix;
              ////oView.Translation = Vector3.Zero;

              // Graphics Device zum Rendern der Primitive vorbereiten
              ////Game1.Instance.GraphicsDevice.VertexDeclaration = this.vertexDeclaration;
              graphicsDevice.SetVertexBuffer(vertexBuffer);

              // Tiefentest deaktivieren und Schreibschutz des Z-Buffers aktivieren
              // Beim Rendern der Sky Box sollen keine Tiefenwerte in den Z-Buffer geschrieben
              // werden, denn der Himmel liegt immer hinter allen anderen Objekten
              ////Game1.Instance.GraphicsDevice.DepthStencilState.DepthBufferEnable = true;
              ////Game1.Instance.GraphicsDevice.DepthStencilState.DepthBufferWriteEnable = true;

              graphicsDevice.DepthStencilState = DepthStencilState.Default;

              ////shaderEffect.CurrentTechnique = shaderEffect.Techniques["Simplest"];
              shaderEffect.Parameters["xWorldViewProjection"].SetValue(Matrix.Identity * viewMatrix * projectionMatrix);
              shaderEffect.Parameters["xWorld"].SetValue(Matrix.Identity);
              shaderEffect.Parameters["xTexture"].SetValue(this.texture);

              // Render States setzen
              graphicsDevice.RasterizerState = RasterizerState.CullNone;
              ////Game1.Instance.GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Mirror;
              ////Game1.Instance.GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Mirror;
              ////effect.Begin();

              SamplerState samplerState = graphicsDevice.SamplerStates[0];
              graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;

              foreach (var pass in shaderEffect.CurrentTechnique.Passes)
              {
            pass.Apply();
            graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
              }

              ////effect.End();

              ////m_oEffect.Texture = m_oLeftTexture;
              ////this.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 24, 2);

              ////m_oEffect.Texture = m_oRightTexture;
              ////this.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 36, 2);

              ////m_oEffect.Texture = m_oTopTexture;
              ////this.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 48, 2);

              ////m_oEffect.CurrentTechnique.Passes[0].End();

              // Tiefentest wieder aktivieren und Schreibschutz entfernen
              ////Game1.Instance.GraphicsDevice.DepthStencilState.DepthBufferEnable = true;
              ////Game1.Instance.GraphicsDevice.DepthStencilState.DepthBufferWriteEnable = true;
        }
Example #13
0
 public static void draw(GraphicsDevice device)
 {
     if (vBuffer == null)
     {
         vBuffer = CreateVertexBuffer(device);
     }
     device.SetVertexBuffer(vBuffer);
     device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
 }
Example #14
0
        public void Draw(GraphicsDevice graphics, Matrix world, Matrix view, Matrix projection)
        {
            graphics.SetVertexBuffer(vertices);
            graphics.Indices = indices;

            skyEffect.Parameters["WVP"].SetValue(world * view * projection);
            skyEffect.CurrentTechnique.Passes[0].Apply();

            graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, number_of_vertices, 0, number_of_indices / 3);
        }
        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();
        }
        internal void Draw(Texture2D[] textures, GraphicsDevice device, BasicEffect effect, EffectPass pass)
        {
            effect.World = displayObject.WorldTransform;
            effect.Texture = textures[displayObject.TextureIndex];
            device.SetVertexBuffer(vertexBuffer);
            device.Indices = indexBuffer;
            pass.Apply();

            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
        }
 /// <summary>
 /// Draws the primitive to the screen.
 /// </summary>
 /// <param name="device">GPU to draw with.</param>
 public virtual void RenderWireframe(GraphicsDevice device)
 {
     RasterizerState state = new RasterizerState();
     RasterizerState oldState = device.RasterizerState;
     state.FillMode = FillMode.WireFrame;
     device.RasterizerState = state;
     device.SetVertexBuffer(m_vertexBuffer);
     device.DrawPrimitives(PrimitiveType.TriangleList, 0, m_vertices.Length / 3);
     device.RasterizerState = oldState;
 }
        /// <summary>
        /// Draws the primitive to the screen.
        /// </summary>
        /// <param name="device">GPU to draw with.</param>
        public virtual void Render(GraphicsDevice device)
        {
            if (m_vertices == null || m_vertexBuffer == null || m_vertexBuffer.IsDisposed)
            {
                return;
            }

            device.SetVertexBuffer(m_vertexBuffer);
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, m_vertices.Length / 3);
        }
        //Draw and Set Buffers
        public void Draw(GraphicsDevice GraphicsDevice)
        {
            //Set Vertex Buffer
            GraphicsDevice.SetVertexBuffer(vb);

            //Set Index Buffer
            GraphicsDevice.Indices = ib;

            //Draw Quad
            GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);
        }
Example #20
0
        //-----------------------------------------------------------------------
        public void Draw(GraphicsDevice device)
        {
            if (indices.Length == 0)
                return;

            if (isDirty)
                Warm(device);

            device.SetVertexBuffer(vertexbuffer);
            device.Indices = indexbuffer;
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
        }
Example #21
0
		/// <summary>
		/// Draws the vertice list on the given surface.
		/// </summary>
		/// <param name="device"></param>
		/// <param name="effect"></param>
		/// <param name="matrixView"></param>
		/// <param name="matrixProjection"></param>
		/// <param name="matrixWorld"></param>
		public void Draw(GraphicsDevice device, BasicEffect effect, Matrix matrixView, Matrix matrixProjection, Matrix matrixWorld) {
			effect.CurrentTechnique.Passes[0].Apply();

			effect.Projection = matrixProjection;
			effect.World = matrixWorld;
			effect.View = matrixView;

			//Device.VertexDeclaration = mVertexDeclaration;
			//Device.Vertices[0].SetSource(mVertexBuffer, 0, VertexPositionColorTexture.SizeInBytes);
			device.SetVertexBuffer(mVertexBuffer);
			device.DrawPrimitives(PrimitiveType.TriangleList, 0, mVerticesList.Count);
		}
Example #22
0
 //描画パスごとに呼び出す
 public void drawPass(GraphicsDevice inDevice)
 {
     inDevice.SetVertexBuffer(m_VertexBuffer);
     inDevice.Indices=m_IndexBuffer;
     inDevice.DrawIndexedPrimitives(
         PrimitiveType.TriangleList,
         0,
         0,
         m_Vertices.Length,
         0,
         m_Indices.Length / 3
     );
 }
        public void DrawSkybox(Matrix viewMatrix, Matrix projectionMatrix, 
            Matrix camWorld, GraphicsDevice device)
        {
            device.SetVertexBuffer(vertices);
            device.Indices = indices;

            skyEffect.Parameters["WVP"].SetValue(camWorld * projectionMatrix * viewMatrix
                *Matrix.CreateScale(100));
            skyEffect.CurrentTechnique.Passes[0].Apply();

            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,
                number_of_vertices, 0, number_of_indices / 3);
        }
Example #24
0
        public void Draw(GraphicsDevice device,CameraAula camera)
        {
            //effect.View = CameraAula.view;
            //effect.Projection = Camera.Projection;
            effect.View = camera.view;
            effect.World = worldMatrix;

            vBuffer.SetData(vertices);

            device.SetVertexBuffer(vBuffer);

            effect.CurrentTechnique.Passes[0].Apply();
            device.DrawUserPrimitives(PrimitiveType.TriangleStrip, vertices, 0, 2);
        }
Example #25
0
        public void Draw()
        {
            IGraphicsDeviceService igs = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService));
            device = igs.GraphicsDevice;

            //XNA 3.1
               // device.VertexDeclaration = vertexDecl;
               // device.Vertices[0].SetSource(vb, 0, VertexPositionNormalTexture.SizeInBytes);
            // XNA 4.0
            // set vertex buffer and declaration
            device.SetVertexBuffer(vb);

            device.Indices = ib;
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, (dimension + 1) * (dimension + 1), 0, 2 * dimension * dimension);
        }
Example #26
0
        public override void ReconstructShading(GameTime deltaTime, Camera3D camera, Matrix view, Matrix projection, GraphicsDevice graphicsDevice)
        {
            // this pass uses the light accumulation texture and reconstruct the mesh's shading
            // our parameters were already filled in the first pass
            RenderEffect.SetCurrentTechnique(1);
            RenderEffect.SetMatrices(GlobalTransform, view, projection);

            // Apply the Render Effect
            RenderEffect.Apply();

            graphicsDevice.SetVertexBuffer(m_MeshPart.VertexBuffer, m_MeshPart.VertexOffset);
            graphicsDevice.Indices = m_MeshPart.IndexBuffer;

            graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, m_MeshPart.NumVertices, m_MeshPart.StartIndex, m_MeshPart.PrimitiveCount);
        }
        public void Draw(GraphicsDevice graphicsDevice, Effect effect,
            string colorMapParamName, string normalMapParamName,
            Texture2D ColorMap, Texture2D NormalMap)
        {
            graphicsDevice.SetVertexBuffer(vertexBuffer);

            effect.Parameters[colorMapParamName].SetValue(ColorMap);
            effect.Parameters[normalMapParamName].SetValue(NormalMap);

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
            }
        }
Example #28
0
        public override int Draw(GraphicsDevice device, Camera cam)
        {
            if (filter == null)
            {
                return 0;
            }

            BoundingSphere sphere = new BoundingSphere((Microsoft.Xna.Framework.Vector3)transform.position + filter.boundingSphere.Center, filter.boundingSphere.Radius * transform.lossyScale.sqrMagnitude);
            if (cam.DoFrustumCulling(ref sphere))
            {
            #if DEBUG
                if (Camera.logRenderCalls)
                {
                    Debug.LogFormat("VP cull {0} with radius {1} pos {2} cam {3} at {4}", gameObject, filter.boundingSphere.Radius, transform.position, cam.gameObject, cam.transform.position);
                }
            #endif
                return 0;
            }

            // NOTE: I don't want to look at this now... Use the old rendering method.
            if (false /*vBuffer != null */)
            {
                device.SetVertexBuffer(vBuffer);
                IndexBuffer iBuffer = filter.mesh.GetIndexBuffer();
                device.Indices = iBuffer;
                if (material != null)
                {
                    Render(device, cam, material, vBuffer.VertexCount, iBuffer.IndexCount / 3);
                    //for (int i = 1; i < sharedMaterials.Length; i++)
                    //{
                    //    sharedMaterials[i].Render(vBuffer, iBuffer);
                    //}
                }
                else
                {
                    Debug.LogFormat("We have no material for {0}, so it is not rendered", this);
                }
            }
            else
            {
                if (filter.CanBatch())
                {
                    return cam.BatchRender(filter.meshToRender, sharedMaterials, transform);
                }
            }

            return 0;
        }
Example #29
0
        public virtual void Draw(GraphicsDevice device)
        {
            _effect.World = RotationMatrix * Matrix.CreateTranslation(Position);
            _effect.View = Camera.View;
            _effect.Projection = Camera.Projection;
            _effect.VertexColorEnabled = true;
            _effect.EnableDefaultLighting();
            device.SetVertexBuffer(_vertexBuffer);
            device.Indices = _indexBuffer;

            foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives(_primType, _vertices, 0, _vertices.Length, _indices, 0, _primCount, VertexPositionColorNormal.VertexDeclaration);
            }
        }
Example #30
0
File: Cube.cs Project: rd3k/Cubrick
        public void RenderToDevice(GraphicsDevice device, Camera camera)
        {
            for (int i = 0; i < 6; i++)
                blockAreas[i].RenderToDevice();

            cubeEffect.World = Matrix.CreateRotationX(MathHelper.ToRadians(rotationX)) *
                               Matrix.CreateRotationY(MathHelper.ToRadians(rotationY)) *
                               Matrix.CreateRotationZ(MathHelper.ToRadians(rotationZ)) *
                               Matrix.CreateTranslation(Position);

            cubeEffect.View = camera;

            cubeEffect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 1.0f, 1000.0f);

            cubeEffect.TextureEnabled = true;

            VertexBuffer buffer = new VertexBuffer(device, VertexPositionNormalTexture.VertexDeclaration, 36, BufferUsage.WriteOnly);
            buffer.SetData(vertices);
            device.SetVertexBuffer(buffer);

            cubeEffect.Texture = faceTextures[0];
            cubeEffect.CurrentTechnique.Passes[0].Apply();
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, 6);

            cubeEffect.Texture = faceTextures[1];
            cubeEffect.CurrentTechnique.Passes[0].Apply();
            device.DrawPrimitives(PrimitiveType.TriangleList, 6, 6);

            cubeEffect.Texture = faceTextures[2];
            cubeEffect.CurrentTechnique.Passes[0].Apply();
            device.DrawPrimitives(PrimitiveType.TriangleList, 12, 6);

            cubeEffect.Texture = faceTextures[3];
            cubeEffect.CurrentTechnique.Passes[0].Apply();
            device.DrawPrimitives(PrimitiveType.TriangleList, 18, 6);

            cubeEffect.Texture = faceTextures[4];
            cubeEffect.CurrentTechnique.Passes[0].Apply();
            device.DrawPrimitives(PrimitiveType.TriangleList, 24, 6);

            cubeEffect.Texture = faceTextures[5];
            cubeEffect.CurrentTechnique.Passes[0].Apply();
            device.DrawPrimitives(PrimitiveType.TriangleList, 30, 6);
        }
        public void Draw(GraphicsDevice gd)
        {
            gd.RasterizerState = RasterizerState.CullNone;
            gd.SetVertexBuffer(vertexBuffer);
            gd.SamplerStates[0] = SamplerState.LinearClamp;

            effect.World = world;
            effect.View = camera.View ;
            effect.Projection = camera.Projection;

            effect.TextureEnabled = true;
            effect.Texture = this.texture;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                gd.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3);
            }
        }
Example #32
0
        private void PrepRenderState()
        {
            GraphicsDevice.BlendState        = blendState;
            GraphicsDevice.SamplerStates[0]  = samplerState;
            GraphicsDevice.DepthStencilState = depthStencilState;
            GraphicsDevice.RasterizerState   = rasterizerState;

            GraphicsDevice.SetVertexBuffer(vertexBuffer);
            GraphicsDevice.Indices = indexBuffer;

            Viewport viewport = GraphicsDevice.Viewport;

            // Inlined CreateOrthographicOffCenter * transformMatrix
            float tfWidth  = (float)(2.0 / (double)viewport.Width);
            float tfHeight = (float)(-2.0 / (double)viewport.Height);

            unsafe
            {
                float *dstPtr = (float *)spriteMatrixTransform;
                dstPtr[0]  = (tfWidth * transformMatrix.M11) - transformMatrix.M14;
                dstPtr[1]  = (tfWidth * transformMatrix.M21) - transformMatrix.M24;
                dstPtr[2]  = (tfWidth * transformMatrix.M31) - transformMatrix.M34;
                dstPtr[3]  = (tfWidth * transformMatrix.M41) - transformMatrix.M44;
                dstPtr[4]  = (tfHeight * transformMatrix.M12) + transformMatrix.M14;
                dstPtr[5]  = (tfHeight * transformMatrix.M22) + transformMatrix.M24;
                dstPtr[6]  = (tfHeight * transformMatrix.M32) + transformMatrix.M34;
                dstPtr[7]  = (tfHeight * transformMatrix.M42) + transformMatrix.M44;
                dstPtr[8]  = transformMatrix.M13;
                dstPtr[9]  = transformMatrix.M23;
                dstPtr[10] = transformMatrix.M33;
                dstPtr[11] = transformMatrix.M43;
                dstPtr[12] = transformMatrix.M14;
                dstPtr[13] = transformMatrix.M24;
                dstPtr[14] = transformMatrix.M34;
                dstPtr[15] = transformMatrix.M44;
            }

            // FIXME: When is this actually applied? -flibit
            spriteEffectPass.Apply();
        }
Example #33
0
        private void PrepRenderState()
        {
            GraphicsDevice.BlendState        = blendState;
            GraphicsDevice.SamplerStates[0]  = samplerState;
            GraphicsDevice.DepthStencilState = depthStencilState;
            GraphicsDevice.RasterizerState   = rasterizerState;

            GraphicsDevice.SetVertexBuffer(vertexBuffer);
            GraphicsDevice.Indices = indexBuffer;

            Viewport viewport = GraphicsDevice.Viewport;
            Matrix   projection;

            Matrix.CreateOrthographicOffCenter(
                0,
                viewport.Width,
                viewport.Height,
                0,
                0,
                1,
                out projection
                );

            /* FIXME: Half-pixel offset for GL!
             * Abstract out, or remove altogether.
             * -flibit
             */
            projection.M41 += -0.5f * projection.M11;
            projection.M42 += -0.5f * projection.M22;
            Matrix.Multiply(
                ref transformMatrix,
                ref projection,
                out projection
                );
            spriteMatrixTransform.SetValue(projection);

            // FIXME: When is this actually applied? -flibit
            spriteEffectPass.Apply();
        }
Example #34
0
        public void DrawGeometry(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, Effect effect)
        {
            //Effect.CurrentTechnique = Effect.Techniques[0];
            if (SkelBones == null)
            {
                ReloadSkeleton();
            }
            effect.Parameters["SkelBindings"].SetValue(SkelBones);

            lock (Bindings)
            {
                foreach (var pass in effect.CurrentTechnique.Passes)
                {
                    foreach (var binding in Bindings)
                    {
                        if (binding.Texture != null)
                        {
                            var tex = binding.Texture.Get(device);
                            effect.Parameters["MeshTex"].SetValue(tex);
                        }
                        else
                        {
                            effect.Parameters["MeshTex"].SetValue((Texture2D)null);
                        }
                        pass.Apply();
                        binding.Mesh.Draw(device);
                    }
                }
            }

            //skip drawing shadows if we're drawing id
            if (LightPositions == null || effect.CurrentTechnique == effect.Techniques[1])
            {
                return;
            }

            if (ShadBuf == null)
            {
                var shadVerts = new ShadowVertex[]
                {
                    new ShadowVertex(new Vector3(-1, 0, -1), 25),
                    new ShadowVertex(new Vector3(-1, 0, 1), 25),
                    new ShadowVertex(new Vector3(1, 0, 1), 25),
                    new ShadowVertex(new Vector3(1, 0, -1), 25),

                    new ShadowVertex(new Vector3(-1, 0, -1), 19),
                    new ShadowVertex(new Vector3(-1, 0, 1), 19),
                    new ShadowVertex(new Vector3(1, 0, 1), 19),
                    new ShadowVertex(new Vector3(1, 0, -1), 19)
                };
                for (int i = 0; i < shadVerts.Length; i++)
                {
                    shadVerts[i].Position *= 1f;
                }
                int[] shadInd = new int[] { 2, 1, 0, 2, 0, 3, 6, 5, 4, 6, 4, 7 };

                ShadBuf = new VertexBuffer(device, typeof(ShadowVertex), shadVerts.Length, BufferUsage.None);
                ShadBuf.SetData(shadVerts);
                ShadIBuf = new IndexBuffer(device, IndexElementSize.ThirtyTwoBits, shadInd.Length, BufferUsage.None);
                ShadIBuf.SetData(shadInd);
            }

            foreach (var light in LightPositions)
            {
                //effect.Parameters["FloorHeight"].SetValue((float)(Math.Floor(Position.Y/2.95)*2.95 + 0.05));
                effect.Parameters["LightPosition"].SetValue(light);
                var oldTech = effect.CurrentTechnique;
                effect.CurrentTechnique = effect.Techniques[4];
                effect.CurrentTechnique.Passes[0].Apply();
                device.DepthStencilState = DepthStencilState.DepthRead;
                device.SetVertexBuffer(ShadBuf);
                device.Indices = ShadIBuf;
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4);
                effect.CurrentTechnique  = oldTech;
                device.DepthStencilState = DepthStencilState.Default;
            }

            DrawHeadObject(device, effect);
        }
Example #35
0
 public override void SetVertexBuffer(VertexBuffer vb)
 {
     _device.SetVertexBuffer(((XNAVertexBufferImplementation)vb.Implementation).XNAVertexBuffer);
 }