|
 | 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. | |
|
|
 | | |  |
|
|
|
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
|
|