Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Tutorial 3 for Windows Phone 7
  Posted by: Anonymous
  When: 19/05/2013 at 11:27:50

 No download link for 2d series: shooter
  Posted by: zaboleq
  When: 07/05/2013 at 15:46:28

 Collision Class?
  Posted by: Anonymous
  When: 05/05/2013 at 19:03:59

 stack overflow
  Posted by: cityguy
  When: 07/04/2013 at 01:58:38

 Meshes looks strange.
  Posted by: ab_saratov
  When: 01/04/2013 at 04:31:08

 Lamppost Not loaded
  Posted by: Anonymous
  When: 22/03/2013 at 06:43:52

 Collision Class?
  Posted by: Da_Boom
  When: 21/03/2013 at 01:23:09

 Math boggles me
  Posted by: cityguy
  When: 17/03/2013 at 03:44:48

 Collision Class?
  Posted by: Da_Boom
  When: 16/03/2013 at 03:44:42

 Tree update
  Posted by: Anonymous
  When: 15/03/2013 at 21:11:22

 XNA 4.0
  Posted by: Anonymous
  When: 15/03/2013 at 19:43:57

 Error when I try to run.
  Posted by: Anonymous
  When: 15/03/2013 at 19:21:06

 Error With the Effect File
  Posted by: Anonymous
  When: 15/03/2013 at 18:21:01

 Can only get shadowmap
  Posted by: Anonymous
  When: 15/03/2013 at 15:48:52

 Vertex and Pixel Shader Versions?
  Posted by: Anonymous
  When: 15/03/2013 at 15:07:16

 Unsupported properties
  Posted by: Anonymous
  When: 15/03/2013 at 14:23:00

 Problem Loading Skybox
  Posted by: Rana
  When: 15/03/2013 at 10:34:45

 Black Screen Of Death - Help!
  Posted by: Anonymous
  When: 15/03/2013 at 03:43:43

 2.0 anyone?
  Posted by: Anonymous
  When: 15/03/2013 at 02:19:48

 Defitinition of tha rotation axis
  Posted by: Anonymous
  When: 15/03/2013 at 00:55:14




Topic: Help with Indices



  
Goto parent category
  
Create a new user account


   Help with Indices
 Poster : shepardwj
 Posts: 5
 Country : USA
 City: Ral

  
Posted by shepardwj on 29/03/2008 at 16:10:26
Im haveing trouble with the commented part.

Error message at the bottom of code!

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace XNAtutorial1
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        private VertexBuffer vb;
        private IndexBuffer ib;


        VertexPositionColor[] vertices;
        Effect effect;
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        private float angle = 0f;

        GraphicsDevice device;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            base.Initialize();

            setUpXNADevice();

            SetUpVertices();

            SetUpCamera();

            SetUpIndices();
        }

        private void setUpXNADevice()
        {
            device = graphics.GraphicsDevice;

            graphics.PreferredBackBufferWidth = 500;
            graphics.PreferredBackBufferHeight = 500;
            graphics.ApplyChanges();
            Window.Title = "Riemer's XNA Tutorials -- Series 1";

            CompiledEffect compiledeffect = Effect.CompileEffectFromFile("@/../../../../effects.fx", null, null,
                CompilerOptions.None, TargetPlatform.Windows);
            effect = new Effect(graphics.GraphicsDevice, compiledeffect.GetEffectCode(), CompilerOptions.None, null);
        }

        private void SetUpVertices()
        {
            vertices = new VertexPositionColor[5];

            vertices[0].Position = new Vector3(0f, 0f, 0f);
            vertices[0].Color = Color.White;
            vertices[1].Position = new Vector3(5f, 10f, 0f);
            vertices[1].Color = Color.White;
            vertices[2].Position = new Vector3(10f, 0f, 0f);
            vertices[2].Color = Color.White;
            vertices[3].Position = new Vector3(5f, 5f, 0f);
            vertices[3].Color = Color.White;
            vertices[4].Position = new Vector3(10f, 5, 0f);
            vertices[4].Color = Color.White;

            ///vb = new VertexBuffer(device, sizeof(float) * 4 * 5, ResourceUsage.WriteOnly, ResourceManagementMode.Automatic);
            ///vb = new VertexBuffer(device, sizeof(float) * 4 * 5, BufferUsage.WriteOnly);
        }

        private void SetUpIndices()
        {
            short[] indices = new short[6];

            indices[0] = 3;
            indices[1] = 1;
            indices[2] = 0;
            indices[3] = 4;
            indices[4] = 2;
            indices[5] = 1;

            ///ib = new IndexBuffer(device, typeof(short), 6, ResourceUsage.WriteOnly, ResourceManagementMode.Automatic);
            ///ib = new IndexBuffer(device, typeof(short), 6, BufferUsage.WriteOnly);
        }

        private void SetUpCamera()
        {
            Matrix viewMatrix = Matrix.CreateLookAt(new Vector3(0, 0, 40), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            Matrix projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                this.Window.ClientBounds.Width / this.Window.ClientBounds.Height, 1.0f, 50.0f);

            effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xProjection"].SetValue(projectionMatrix);
            effect.Parameters["xWorld"].SetValue(Matrix.Identity);
        }

        protected override void LoadContent()
        {

            spriteBatch = new SpriteBatch(GraphicsDevice);
        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            angle += 0.05f;

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {

            device.RenderState.CullMode = CullMode.None;

            device.Clear(Color.DarkSlateBlue);

            effect.CurrentTechnique = effect.Techniques["Colored"];

            Vector3 rotAxis = new Vector3(3 * angle, angle, 2 * angle);
            rotAxis.Normalize();
            Matrix worldMatrix = Matrix.CreateTranslation(-5, -10 * 1 / 3, 0) * Matrix.CreateFromAxisAngle(rotAxis, angle);
            effect.Parameters["xWorld"].SetValue(worldMatrix);

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

                device.Vertices[0].SetSource(vb, 0, VertexPositionColor.SizeInBytes);
                device.Indices = ib;
                device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 5, 0, 2);

                pass.End();
            }
            effect.End();

            base.Draw(gameTime);
        }
    }
}


Ive looked at the other posts have tried it, but it doesnt work. The other methods dont give me an error, but the 2 white triangles i should have are not there.

Error 1    The name 'ResourceUsage' does not exist in the current context

Error 2    The name 'ResourceManagementMode' does not exist in the current context

Error 3    The name 'ResourceUsage' does not exist in the current context

Error 4    The name 'ResourceManagementMode' does not exist in the current context

Pleas help! Thank you. :)

 Poster : shepardwj
 Posts: 5
 Country : USA
 City: Ral

  
Posted by shepardwj on 29/03/2008 at 16:48:21
New problem. Here is the new code!


using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace XNAtutorial1
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        private VertexBuffer vb;
        private IndexBuffer ib;


        VertexPositionColor[] vertices;
        Effect effect;
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        private float angle = 0f;

        GraphicsDevice device;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            base.Initialize();

            setUpXNADevice();

            SetUpVertices();

            SetUpIndices();

            SetUpCamera();
        }

        private void setUpXNADevice()
        {
            device = graphics.GraphicsDevice;

            graphics.PreferredBackBufferWidth = 500;
            graphics.PreferredBackBufferHeight = 500;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();
            Window.Title = "Riemer's XNA Tutorials -- Series 1";

            CompiledEffect compiledeffect = Effect.CompileEffectFromFile("@/../../../../effects.fx", null, null,
                CompilerOptions.None, TargetPlatform.Windows);
            effect = new Effect(graphics.GraphicsDevice, compiledeffect.GetEffectCode(), CompilerOptions.None, null);
        }

        private void SetUpVertices()
        {
            vertices = new VertexPositionColor[5];

            vertices[0].Position = new Vector3(0f, 0f, 0f);
            vertices[0].Color = Color.White;
            vertices[1].Position = new Vector3(5f, 10f, 0f);
            vertices[1].Color = Color.White;
            vertices[2].Position = new Vector3(10f, 0f, 0f);
            vertices[2].Color = Color.White;
            vertices[3].Position = new Vector3(5f, 5f, 0f);
            vertices[3].Color = Color.White;
            vertices[4].Position = new Vector3(10f, 5, 0f);
            vertices[4].Color = Color.White;

            vb = new VertexBuffer(device, VertexPositionNormalTexture.SizeInBytes * (vertices.Length), BufferUsage.WriteOnly);
        }

        private void SetUpIndices()
        {
            short[] indices = new short[6];

            indices[0] = 3;
            indices[1] = 1;
            indices[2] = 0;
            indices[3] = 4;
            indices[4] = 2;
            indices[5] = 1;

            ib = new IndexBuffer(device, typeof(short), 6, BufferUsage.WriteOnly);
        }

        private void SetUpCamera()
        {
            Matrix viewMatrix = Matrix.CreateLookAt(new Vector3(0, 0, 40), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            Matrix projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                this.Window.ClientBounds.Width / this.Window.ClientBounds.Height, 1.0f, 50.0f);

            effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xProjection"].SetValue(projectionMatrix);
            effect.Parameters["xWorld"].SetValue(Matrix.Identity);
        }

        protected override void LoadContent()
        {

            spriteBatch = new SpriteBatch(GraphicsDevice);
        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            angle += 0.05f;

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {

            device.RenderState.FillMode = FillMode.WireFrame;

            device.RenderState.CullMode = CullMode.None;

            device.Clear(Color.DarkSlateBlue);

            effect.CurrentTechnique = effect.Techniques["Colored"];

            Matrix worldMatrix = Matrix.Identity;

            effect.Parameters["xWorld"].SetValue(worldMatrix);
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();

                device.Vertices[0].SetSource(vb, 0, VertexPositionColor.SizeInBytes);
                device.Indices = ib;
                device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 5, 0, 2);

                pass.End();
            }
            effect.End();

            base.Draw(gameTime);
        }
    }
}
 Poster : shepardwj
 Posts: 5
 Country : USA
 City: Ral

  
Posted by shepardwj on 29/03/2008 at 16:49:12
The problem is that it wont show the wireframe triangles.
 Poster : Anonymous
 Posts:
 Country :
 City:

  
Posted by Anonymous on 01/04/2008 at 13:43:16
looks like you are missing a few things.

at the end of SetUpVertices()

vb.SetData<VertexPositionColor>(vertices);


at the end of SetUpIndices()

ib = new IndexBuffer(device, sizeof(short) * 6, BufferUsage.WriteOnly, IndexElementSize.SixteenBits);
            ib.SetData<short>(indices);


Hope it helps.
 Poster : Anonymous
 Posts:
 Country :
 City:

  
Posted by Anonymous on 02/09/2012 at 14:42:52
HI!!!! YOU! I know you maybe have  10. I know far weep 2 and crysis can't run you DX10 beacsue I reckon your record card is ancient. I guess your record card is 9.0c . Few record games must run on record games.

  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)